API Maker

The backend engine for the AI era

Case study 02 · Automatic indexing

Ready for sale day: the indexes that created themselves

KartWise runs a marketplace for 6,000 home and kitchen sellers. Its orders collection had grown to 48 million documents, and every big sale slowed the seller dashboard to a crawl. Nobody had the time to find which queries needed an index. With the automatic mode of Index Maker, API Maker found them, created them and shipped them to every environment by itself.

  • 76×faster order search840 ms → 11 ms, median
  • 31indexes created by themselvesin the first 3 weeks
  • 31%database CPU at sale peakwas 78%
  • 0hours spent hunting slow querieswas 2 days before every sale

The challenge

Where KartWise was stuck

KartWise moved its seller APIs to API Maker in 2024, for the generated APIs and the caching. The backend held up well. The database did not. Each new feature of the seller dashboard brought a new filter: by status and date, by pincode, by return reason, by payout batch. Each filter was a new query shape, on a collection that grew by 90,000 orders a day.

Before the Diwali sale of 2025 the team spent two days reading slow query logs and added six indexes by hand. On the first night of the sale the dashboard still froze. The query that hurt most filtered returns by seller and reason. Nobody had looked at it: an intern had written it three weeks before, for a report.

The lesson was clear. The question was not which index to add. It was who keeps watching the queries, every week, forever.

  • Nobody knew which queries were slowThe slow log had thousands of lines. Linking one line to the API that sent it took hours.
  • Indexes made by hand driftedAn index created on production was missing on staging, so tests and production behaved differently.
  • The database hit its ceilingAt sale peak the replica set ran at 78% CPU, and the team had already doubled its size once.

The solution

What they built with API Maker

KartWise was already on API Maker, so Index Maker was one setting away. It records the queries of the APIs, grouped by the shape of their condition, and asks MongoDB with explain whether each one uses an index. The team switched on the automatic mode in November 2025, two weeks before the year-end sale.

  1. Recording, every six hours

    A scanning period starts every six hours and records for thirty minutes. Nothing is added to the requests: the recording runs beside them.

    Index Maker
  2. explain decides, nobody guesses

    When a period ends, each query shape runs through explain with a recorded sample: full index, part of one, or none.

  3. Thresholds set by the team

    An index is made only for slow or frequent shapes on tables over 100,000 rows, and never past 12 indexes on one collection. Every decision is kept with its reason.

  4. Shipped as a migration script

    Each index goes into the migration script am_index_maker. Staging and production run it on their next deploy, so every environment has the same indexes.

    Database Migrations
  5. Watching the next feature

    When a developer adds a new filter, the next period sees its shape. The index often exists before the feature reaches production.

    Git Deployment

The numbers

Before and after

Median time of the five slowest queries (ms)

  • Before
  • With Index Maker
Returns by seller and reasonReturns by seller and reason, Before: 1,240 ms1,240 msReturns by seller and reason, With Index Maker: 9 ms9 msOrders by status and dateOrders by status and date, Before: 840 ms840 msOrders by status and date, With Index Maker: 11 ms11 msPayouts by batchPayouts by batch, Before: 610 ms610 msPayouts by batch, With Index Maker: 6 ms6 msPincode delivery checkPincode delivery check, Before: 380 ms380 msPincode delivery check, With Index Maker: 4 ms4 msReviews by productReviews by product, Before: 290 ms290 msReviews by product, With Index Maker: 7 ms7 ms
Returns by seller and reasonReturns by seller and reason, Before: 1,240 ms1,240Returns by seller and reason, With Index Maker: 9 ms9Orders by status and dateOrders by status and date, Before: 840 ms840Orders by status and date, With Index Maker: 11 ms11Payouts by batchPayouts by batch, Before: 610 ms610Payouts by batch, With Index Maker: 6 ms6Pincode delivery checkPincode delivery check, Before: 380 ms380Pincode delivery check, With Index Maker: 4 ms4Reviews by productReviews by product, Before: 290 ms290Reviews by product, With Index Maker: 7 ms7

Measured by the API logs of API Maker, one week before and one week after.

Database CPU at the peak hour of each sale day (%)

  • Diwali sale 2025, before
  • Year-end sale 2025, with Index Maker
020406080Day 1Day 2Day 3Day 4Day 5Day 1, Diwali sale 2025, before: 78%Day 2, Diwali sale 2025, before: 74%Day 3, Diwali sale 2025, before: 76%Day 4, Diwali sale 2025, before: 71%Day 5, Diwali sale 2025, before: 69%Day 1, Year-end sale 2025, with Index Maker: 34%Day 2, Year-end sale 2025, with Index Maker: 31%Day 3, Year-end sale 2025, with Index Maker: 29%Day 4, Year-end sale 2025, with Index Maker: 30%Day 5, Year-end sale 2025, with Index Maker: 27%78%69%34%27%
020406080Day 1Day 2Day 3Day 4Day 5Day 1, Diwali sale 2025, before: 78%Day 2, Diwali sale 2025, before: 74%Day 3, Diwali sale 2025, before: 76%Day 4, Diwali sale 2025, before: 71%Day 5, Diwali sale 2025, before: 69%Day 1, Year-end sale 2025, with Index Maker: 34%Day 2, Year-end sale 2025, with Index Maker: 31%Day 3, Year-end sale 2025, with Index Maker: 29%Day 4, Year-end sale 2025, with Index Maker: 30%Day 5, Year-end sale 2025, with Index Maker: 27%78%69%34%27%

The year-end sale had 18% more orders than Diwali.

The results

What changed for KartWise

  • Fast on sale dayThrough the year-end sale the P95 of the seller APIs stayed under 120 ms, at 3,200 requests a second.
  • A smaller database, not a bigger oneWith the CPU at 31%, the team moved the replica set down one size and saves $2,900 a month.
  • Every decision explainedOf 112 query shapes, 31 got an index. The rest were skipped with a reason: small table, covered by an existing index, or not worth it.
  • The same indexes everywhereStaging, the load test setup and production run the same script, so a test tells the truth about production again.
We used to spend two days before every sale hunting slow queries. Now I open Index Maker, read what it decided and why, and go back to building features.
Head of EngineeringKartWise

What comes next. KartWise is turning on Index Maker for its PostgreSQL database of seller payouts, where the automatic mode builds indexes concurrently, without locking the table.

Have a problem like KartWise?

Try API Maker on your own computer for free, or tell us about your project.