Code RoomComposite index design
MediumPrep Room Coding #3427

Composite index design

System designDatabases & SQLMid–Senior~40 min

Design the index for a hot query on a 2B-row orders table that's slow despite 'having an index'. The query is: WHERE merchant_id = ? AND status = 'open' ORDER BY created_at DESC LIMIT 50, run ~30k times/sec for merchant dashboards. There's a single-column index on merchant_id but the database still sorts thousands of rows and does thousands of row fetches per query. Design the right index (column order, what it covers), explain why the current one is slow, and the write-side cost you're accepting.

What a strong answer looks like

Clarify scale and constraints first. Propose a clean component breakdown, then go deep on the hard parts (data model, bottlenecks, consistency, failure modes) and name the trade-offs you are making.

Clarify4:30 left
Estimate4:30 planned
Design13:30 planned
Deep dive10:30 planned
Failure7:00 planned
0:00
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.