Quick revision
The short answer
There are four main options. Scatter-gather queries every shard and merges, which is simple but slow and loads every shard. A secondary index or read model keyed by buyer_id, fed by change data capture or events, answers the query from one place. Duplicating order summaries into a buyer-sharded store is a variant of that with eventual consistency and reconciliation. Resharding by buyer is the last resort, only if buyer queries dominate. We decide from query volume, freshness needs and operational cost, and we tell product exactly what consistency they get.
What to remember
In this answer, we looked at a marketplace sharded by seller that needs fast buyer queries. Scatter-gather is simple and always current, but slow and expensive at scale. A read model keyed by buyer, fed by CDC or an outbox, answers the query from one place with eventual consistency, and a buyer-sharded duplicate scales that further with reconciliation. Resharding by buyer is a last resort. We decide from query volume, freshness and operational cost, and we document the consistency guarantee for product.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
There are four main options. Scatter-gather queries every shard and merges, which is simple but slow and loads every shard. A secondary index or read model keyed by buyer_id, fed by change data capture or events, answers the query from one place. Duplicating order summaries into a buyer-sharded store is a variant of that with eventual consistency and reconciliation. Resharding by buyer is the last resort, only if buyer queries dominate. We decide from query volume, freshness needs and operational cost, and we tell product exactly what consistency they get.
Why this question is asked
Every sharded system eventually meets a query that cuts across its shard key. A marketplace sharded by seller makes seller dashboards and order fulfilment fast, and then product asks for 'my orders' for buyers, whose orders are spread over every seller and therefore every shard. Interviewers ask this scenario to see whether we know the standard patterns for a second access path and can weigh them with numbers. In this answer, we will see why the query is hard, go through each option with its cost, and then walk through how to decide and what to promise product.
1Why the Buyer Query Is Hard
Orders are stored on the shard of their seller. A buyer who bought from 40 different sellers has orders on up to 40 shards, and if we have 64 shards, we cannot know which ones without asking. With only seller_id as the shard key, 'all orders of buyer 123' has no shard to go to, so the router must ask every shard. That is the starting point, and every option below is a way to avoid or reduce that fan-out.
2Option 1: Scatter-Gather
Scatter-gather sends the query to every shard in parallel, each shard returns its matching rows using a local index on buyer_id, and the application merges and sorts them. It needs no new infrastructure and the result is always current, which makes it a reasonable start for a low-volume feature.
The costs grow with the shard count. Latency is set by the slowest of 64 shards, so p99 latency rises because some shard is always having a slow moment. Load multiplies: one buyer page view becomes 64 queries, so 1,000 page views per second become 64,000 queries per second across the cluster. And one unavailable shard either fails the request or forces us to show a partial list. For a buyer-facing feature with real traffic, this rarely stays acceptable.
3Option 2: A Read Model Keyed by Buyer
The pattern that usually wins is a separate read model: a table or store keyed by buyer_id that contains what the buyer page needs, built from the order data on every shard. Each shard publishes its changes, either with change data capture such as Debezium reading the database log, or with events written through an outbox table in the same transaction as the order. A consumer applies them to the buyer read model. The buyer page then reads one partition of one store.
5 messages in order. Play them, or step through them one at a time.
The seller shards stay the source of truth; the read model is a copy shaped for buyers.
Notice what we have accepted: the read model is eventually consistent. An order placed now appears in 'my orders' after the event is processed, typically within a second or two, and longer during a consumer backlog. We also need the consumer to be idempotent, since events can be delivered more than once, and a way to rebuild the read model from scratch if it is corrupted or its schema changes.
4Option 3: Duplicate Order Summaries Into a Buyer-Sharded Store
A variant is to duplicate order summaries into a second sharded store, sharded by buyer_id. It might be the same database technology with a different shard key, or a store such as Cassandra or DynamoDB with buyer_id as the partition key. The write path is the same as option 2, events or CDC, and the difference is mainly scale: a buyer-sharded copy scales horizontally just like the main store.
Because there are now two copies of each order, they can drift: a missed event, a bug in the consumer, or a manual fix applied to only one side. So we run a reconciliation job, for example nightly, that compares order counts and checksums per buyer or per day between the seller shards and the buyer store and repairs differences. That job is part of the design, not an afterthought.
5Option 4: Reconsider the Shard Key
If buyer queries became the dominant access pattern, we could reshard by buyer_id. But then the seller dashboards and fulfilment, which are the core of a marketplace, would become the cross-shard queries, and we would be back to the same problem from the other side. Resharding a live marketplace means moving every order with no downtime, which is a long and risky project. It is the right answer only when the numbers clearly show the main workload has changed, which is rare.
6How to Decide, and What to Tell Product
The decision comes from three numbers and one question. Query volume: at 5 buyer page views per second, scatter-gather over 64 shards may be fine; at 2,000 per second it is not. Freshness: does the buyer need to see the order instantly, or is two seconds acceptable? Usually the confirmation page after checkout can show the order from the response itself, so the list only needs to be fresh within seconds. Operational cost: a CDC pipeline and a read model are more infrastructure to run, monitor and rebuild. And the question: what consistency can product live with?
Whatever we choose, we write the guarantee down and share it with product, for example: 'my orders reflects new orders within 5 seconds in normal operation; during incidents it can lag, and the order detail page always shows the latest state from the source'. That prevents a stream of bug reports about orders that are temporarily missing.
| Option | Latency and load | Freshness | Operational cost |
|---|---|---|---|
| Scatter-gather | Slowest shard; 64 queries per page | Always current | Low |
| Read model keyed by buyer | One fast query | Seconds behind | CDC or outbox pipeline, rebuilds |
| Buyer-sharded duplicate | One fast query, scales out | Seconds behind | Pipeline plus reconciliation |
| Reshard by buyer | Fast for buyers, slow for sellers | Current | Very high migration cost |
7Follow-up questions
Why use an outbox rather than publishing to Kafka directly from the service?
Because writing the order and publishing the event are two separate systems, and the service could crash between them, leaving an order with no event or an event with no order. The outbox row is written in the same database transaction as the order, so both commit or neither does, and a relay or CDC process publishes it afterwards.
How do you paginate a scatter-gather query?
Each shard returns its top N by created_at after the cursor, the application merges and takes the top N overall, and the cursor is the last created_at and order id. It works, but every page still touches every shard.
What if a buyer must see an order immediately after checkout?
The checkout response already has the order, so the client shows it directly, or the service reads that one order from the seller shard by its id. The list view can stay eventually consistent.
8Conclusion
In this answer, we looked at a marketplace sharded by seller that needs fast buyer queries. Scatter-gather is simple and always current, but slow and expensive at scale. A read model keyed by buyer, fed by CDC or an outbox, answers the query from one place with eventual consistency, and a buyer-sharded duplicate scales that further with reconciliation. Resharding by buyer is a last resort. We decide from query volume, freshness and operational cost, and we document the consistency guarantee for product.
Open with
Since orders live on the seller's shard, a buyer's orders are spread across all shards, so there is no single shard to ask. The simplest option is scatter-gather: query every shard in parallel using a local index on buyer_id and merge.
Then, if they want more
It is always current and needs nothing new, but latency follows the slowest shard, one page view becomes 64 queries, and one bad shard degrades the result. It is fine for low volume. The usual answer is a read model keyed by buyer_id.
Each shard publishes order changes, either through an outbox written in the same transaction or through CDC like Debezium, and a consumer upserts order summaries into a store partitioned by buyer. The buyer page then reads one partition. The cost is eventual consistency, typically a second or two, idempotent consumers and the ability to rebuild it.
A bigger variant duplicates summaries into a buyer-sharded store, which needs a reconciliation job comparing counts and checksums against the source. Resharding everything by buyer is my last resort, because seller dashboards and fulfilment are the core of a marketplace and resharding is expensive.
I would decide from query volume, how fresh the list must be, and what the team can operate, and I would write down the guarantee for product, for example new orders appear within five seconds, while the order detail page always reads the source.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your marketplace is sharded by seller_id. A new product feature needs 'all orders of a...": https://scrivio-interview-library.netlify.app/databases/partitioning-and-sharding/653e483e1c/