Quick revision
The short answer
I would stop the admin tool from querying the shards for anything it can get elsewhere: reporting moves to a warehouse or lakehouse fed by change data capture from every shard, with a stated freshness, and admin lookups by non-shard keys go through a global search index or lookup table that returns the shard key first. The scatter-gather queries that remain run against replicas with per-shard concurrency caps, timeouts and clearly marked partial results, and the tool gets its own rate limits and a circuit breaker so it can never harm customer traffic. We also log who runs which queries and review the heavy ones.
What to remember
In this answer, we redesigned an admin tool that overloaded 64 shards during incidents. Reporting moved to a warehouse fed by CDC with stated freshness, and lookups by non-shard keys go through a global index that returns the shard key first, so a search touches one shard. Remaining fan-out queries run on replicas with per-shard caps, timeouts and marked partial results, the tool has its own pools, rate limits and a circuit breaker, and query logs drive a regular review of heavy usage.
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.
I would stop the admin tool from querying the shards for anything it can get elsewhere: reporting moves to a warehouse or lakehouse fed by change data capture from every shard, with a stated freshness, and admin lookups by non-shard keys go through a global search index or lookup table that returns the shard key first. The scatter-gather queries that remain run against replicas with per-shard concurrency caps, timeouts and clearly marked partial results, and the tool gets its own rate limits and a circuit breaker so it can never harm customer traffic. We also log who runs which queries and review the heavy ones.
Why this question is asked
Internal tools are often built quickly against the production databases, and they work fine until the day they are needed most. During an incident, many engineers open the admin tool at once, each search fans out to 64 shards, and the tool that should help diagnose the problem becomes a second outage. Interviewers ask this scenario because it combines sharding, isolation of workloads and operational discipline. In this answer, we will see why the current design amplifies load, then redesign reporting, lookups and the remaining fan-out queries, and add protections and visibility.
1Why the Admin Tool Overloads Every Shard
An admin search such as 'find orders for email anna@example.com' does not include the shard key, so the tool asks all 64 shards. If the email column is not indexed on the shards, each shard scans its orders table. One search therefore costs 64 queries, possibly 64 scans. During an incident, 30 engineers searching repeatedly produce thousands of heavy queries per minute, hitting every shard at the same moment, exactly when the shards are already under stress. And because every query waits for the slowest shard, the tool feels slow, so people click again, adding more load.
2Move Reporting to an Analytics Store
Reports, exports and aggregate views do not belong on the shards at all. We stream every change from every shard with change data capture, for example Debezium reading each shard's log into Kafka, and load it into a warehouse or lakehouse such as BigQuery, Snowflake, Redshift, or Iceberg tables queried by Trino. Analytical engines are built to scan and aggregate across all the data, and running a heavy report there has no effect on customer traffic.
The trade-off is freshness, and we state it explicitly, for example 'reports reflect changes within 5 minutes'. For most reporting that is fine. During an incident, a five-minute-old view of error counts by status is usually exactly what people need, and it is available without touching the shards.
3Find the Shard Key First for Admin Lookups
Admin lookups are different from reports: support engineers need the current state of one customer or one order, found by email, phone, order number or payment reference. The fix is a global lookup that answers 'which shard key does this belong to?' before touching any shard. That can be a search index such as OpenSearch or Elasticsearch, fed by the same CDC stream, holding the searchable attributes and the shard key, or a small lookup table mapping email to customer_id. The tool queries the index, gets customer_id 4711, and then reads that customer's current data from exactly one shard.
5 messages in order. Play them, or step through them one at a time.
One shard is touched instead of 64.
Notice the change in cost: one index query plus one single-shard query, instead of 64 shard queries. The index can be a few seconds behind, so a customer created a moment ago may not appear yet; the tool says so and offers a direct lookup by id.
4Limit the Scatter-Gather Queries That Remain
Some fan-out queries will remain, for rare investigations. We make them safe. They run against read replicas, never primaries, so customer writes are not affected. The tool limits concurrency per shard, for example at most two admin queries per shard at a time, with a queue in front, so 30 engineers cannot send 30 parallel scans to each shard. Every query has a timeout, such as a statement_timeout of 5 seconds set on the admin connection, so a runaway scan is cancelled. And the tool accepts partial results: if 3 of 64 shards time out, it shows the results from 61 with a clear marker, 'results from 61 of 64 shards', rather than failing or, worse, silently pretending the answer is complete.
5Isolate the Tool From Customer Traffic
The admin tool should be built so that it cannot harm customers, whatever its users do. It gets its own connection pools to the replicas, small ones, so it cannot take connections customer services need. It has its own rate limits per user and in total. A circuit breaker, for example with Resilience4j, opens when shards start timing out, and the tool then stops sending fan-out queries for a while and shows a message pointing to the analytics view. In an incident, that turns a load amplifier into a tool that steps back when the system is struggling.
- Admin UIsearch, customer view, reports
- Guard layerrate limits per user, circuit breaker, query audit log
- Search index + warehousefed by CDC; answers most questions
- Replicas (capped fan-out)timeouts, 2 queries per shard, partial results
- Primary shardscustomer traffic only; admin never queries them
5 layers, from the top down. Step through them one at a time.
Each layer answers what it can, so fewer requests reach the shards.
6Track and Review Heavy Queries
Finally, visibility. The tool logs every query with the user, the query shape, the number of shards touched, rows returned and duration. A weekly review of the heaviest queries shows what people actually need: if the same fan-out search runs 500 times a week, it deserves a field in the search index or a prepared report. Logging also matters for privacy and audit, since admin tools often expose customer data, and knowing who looked at what is a compliance requirement in many companies.
7Follow-up questions
Why not just add indexes on the shards for the admin searches?
Indexes would make each shard's part cheaper, but every search would still touch all 64 shards, and each extra index slows writes for customer traffic. A global index fed by CDC moves the work off the shards entirely.
What freshness should the search index have?
Usually seconds, since CDC into an index is fast; the tool should show the index's lag and allow a direct lookup by shard key when someone needs data created moments ago.
How do you stop people bypassing the tool with direct SQL?
By giving them a tool good enough that they do not need to, and by limiting direct production access to break-glass accounts that are logged and reviewed. Read-only replica access with strict timeouts can be a middle ground.
8Conclusion
In this answer, we redesigned an admin tool that overloaded 64 shards during incidents. Reporting moved to a warehouse fed by CDC with stated freshness, and lookups by non-shard keys go through a global index that returns the shard key first, so a search touches one shard. Remaining fan-out queries run on replicas with per-shard caps, timeouts and marked partial results, the tool has its own pools, rate limits and a circuit breaker, and query logs drive a regular review of heavy usage.
Open with
The core problem is that every admin search lacks the shard key, so it fans out to 64 shards, and during an incident many people do that at once, on shards that are already struggling.
Then, if they want more
I would redesign it in layers. First, reporting leaves the shards: change data capture from every shard, for example Debezium into Kafka, feeds a warehouse or lakehouse, and reports run there with a stated freshness of a few minutes.
Second, admin lookups by email, phone or order number go to a global search index or lookup table, also fed by CDC, which returns the shard key first, so the tool then reads the current data from exactly one shard instead of 64.
Third, for the fan-out queries that remain, I run them on replicas only, cap concurrency per shard, maybe two admin queries per shard, set statement timeouts, and return partial results with a clear marker like 61 of 64 shards rather than failing or pretending to be complete.
Fourth, the tool is isolated: its own small connection pools, rate limits per user and in total, and a circuit breaker that stops fan-out queries when shards start timing out and points people to the analytics view.
Finally, I log every query with the user, shards touched and duration, and review the heaviest ones regularly, which tells us what to add to the index or turn into a report, and also gives the audit trail compliance needs for access to customer data.
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 "An internal admin tool runs scatter-gather queries across 64 shards, and during...": https://scrivio-interview-library.netlify.app/databases/partitioning-and-sharding/1e50267537/