Quick revision
The short answer
During the incident we halt the rollout and withdraw the release, then rate-limit full listings per device and per shard so they queue with retry-after and jitter instead of starving normal sync. Afterwards we give full listings a cheap path, namespace snapshots in object storage plus recent journal entries, separate incremental sync from resyncs with per-shard concurrency budgets, and release clients in stages with per-version server metrics, automatic halts and kill switches, knowing exactly how many concurrent resyncs the system can take.
What to remember
In this answer, we saw how a cursor-reset bug turned two million devices into billions of row reads and stalled sync for everyone. During the incident we halted the rollout, withdrew the release and rate-limited full listings per device and per shard with retry-after and jitter so normal sync recovered. Afterwards we gave full listings a cheap path through namespace snapshots plus recent journal entries, separated incremental sync and resyncs into lanes with per-shard budgets, released clients in stages with per-version metrics, automatic halts and kill switches, and made the cost of recovery a known, tested number.
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.
During the incident we halt the rollout and withdraw the release, then rate-limit full listings per device and per shard so they queue with retry-after and jitter instead of starving normal sync. Afterwards we give full listings a cheap path, namespace snapshots in object storage plus recent journal entries, separate incremental sync from resyncs with per-shard concurrency budgets, and release clients in stages with per-version server metrics, automatic halts and kill switches, knowing exactly how many concurrent resyncs the system can take.
Why this question is asked
This incident is a good example of how a client bug becomes a server outage. Nothing in the metadata tier was broken; it was simply asked to do its most expensive operation two million times in an hour. Interviewers use it to test incident command, capacity thinking and release engineering at once. In this answer, we will estimate the load the bug created, contain it while it runs, give full listings a cheaper path, separate traffic into priority lanes, change how clients are released, and make the cost of recovery a known number.
1Why Two Million Resets Stopped Everyone
In normal operation a device calls list_changes with its cursor and receives a handful of journal entries, a cheap indexed read. A device whose cursor is reset must instead ask for a full listing of every namespace it syncs, which means scanning every file entry in those namespaces.
Suppose the average device syncs 20,000 entries. Two million devices asking for full listings in an hour means 40 billion rows read, around 11 million rows per second on top of normal traffic, concentrated on the shards that hold large namespaces. The database CPU went to 100 percent, so every query slowed down, including the cheap incremental syncs of the 78 million unaffected devices. Clients then timed out and retried, adding more load. That is why sync stalled for everyone and not just for the updated devices.
2Containing the Incident While It Runs
The first move is to stop the source. We halt the staged rollout so no more devices update, and withdraw the release from the update channel. If the client has a server-controlled flag, we use it to tell updated clients to pause full resyncs.
The second move is to protect normal sync. We put a rate limit on full listings, both per device and per shard, so that a shard serves, say, 50 concurrent full listings and rejects the rest with HTTP 429 and a Retry-After header. Clients then wait the given time plus random jitter, so the rejected devices come back spread out over the next hours instead of all at once. Incremental sync and uploads are not limited, so they recover as soon as the database CPU comes down. Over the following hours the 2 million resets drain at a pace the shards can absorb.
- Device asks for a full listingcursor was reset
- Shard under its resync budget?about 50 concurrent per shardYesServe the listingNo429 with Retry-After
- Client waits Retry-After plus jitterspreads retries over hours
- Incremental sync and uploadsnever limited, recover first
4 steps in order. Play them, or step through them one at a time.
3A Cheaper Path for Full Listings
Even with limits, a full listing that scans the database is expensive, and it will be needed again: new devices, reinstalls and recoveries all start from nothing. So we build a path that does not touch the database for the bulk of the work.
A background job periodically writes a snapshot of each namespace, the list of entries with their versions and block lists, to object storage as a compressed file, tagged with the journal cursor at which it was taken. A device that needs a full listing downloads the snapshot, often straight from a CDN-style object store, and then calls list_changes from the snapshot's cursor to catch up on the few changes since. The database now serves only the tail of the journal, a cheap indexed read, and the expensive bytes come from storage built for that.
7 messages in order. Play them, or step through them one at a time.
4Priority Lanes for Sync Traffic
The deeper lesson is that cheap, latency-sensitive requests and expensive, deferrable ones shared the same capacity. We separate them into lanes. Incremental sync and uploads go first, in a lane with most of each shard's capacity. Full resyncs run in a background lane with a concurrency budget per shard, enforced by the API layer or by a separate pool of database replicas used only for resync reads.
With lanes in place, a flood of resyncs makes resyncs slow, which is acceptable, but never makes everyone's normal sync slow. The same thinking applies to any expensive operation a client can trigger, such as listing deleted files or restoring a folder.
5Releasing Clients in Stages
Client releases need the same care as server releases, because a client bug hits servers through millions of devices. We roll out in stages, 1 percent, then 10 percent, then wider, with a soak time between stages. The server tags every request with the client version, so dashboards show behaviour per version, and the rollout halts automatically if a version looks abnormal.
We also give the server kill switches for client features: configuration that the client fetches at start and on a schedule, able to turn off a new sync path or force the old behaviour without shipping a new release. Had this release run at 1 percent first, 800,000 devices, not 2 million, would have reset, and the full-listing rate per version would have tripped the halt within minutes.
| Metric per client version | Normal | Halt the rollout when |
|---|---|---|
| Requests per device per hour | about 60 | more than twice the previous version |
| Full-listing rate | under 0.01 percent of devices a day | any sudden jump |
| Error and retry rate | under 1 percent | above 3 percent |
| Upload bytes per device | steady | large unexplained change |
6Knowing the Cost of Recovery
Finally, the team should know two numbers in advance: the cost of one full resync, in database rows and seconds of CPU for a typical and a very large namespace, and the number of concurrent resyncs the system can serve safely. Those numbers set the per-shard budget and tell us how long a mass reset would take to drain, for example two million resets at 5,000 per minute across the fleet is about seven hours.
Client recovery paths, such as a reset cursor, a corrupted local database or a reinstall, should be tested against production-sized folders with hundreds of thousands of entries, not test accounts with ten files. Recovery code runs rarely, so it is exactly the code that surprises us at the worst time.
7Follow-up questions
Why not simply add more database capacity?
Scaling a sharded database takes hours or days and would have been sized for a once-a-year spike. Rate limits and lanes protect the system immediately and for every future cause of mass resync, while snapshots remove most of the expensive work for good.
How do you stop clients from making it worse with retries?
The server tells them how long to wait with Retry-After, and clients add random jitter and exponential backoff on any error. A client must never retry an expensive call in a tight loop, and that behaviour belongs in a shared, well-tested library.
Should the client have been able to reset its cursor at all?
Resetting is a valid recovery path, but it should be rare and visible. A client that resets should report why, and the server should treat a sudden rise in resets as a signal, not as normal traffic.
8Conclusion
In this answer, we saw how a cursor-reset bug turned two million devices into billions of row reads and stalled sync for everyone. During the incident we halted the rollout, withdrew the release and rate-limited full listings per device and per shard with retry-after and jitter so normal sync recovered. Afterwards we gave full listings a cheap path through namespace snapshots plus recent journal entries, separated incremental sync and resyncs into lanes with per-shard budgets, released clients in stages with per-version metrics, automatic halts and kill switches, and made the cost of recovery a known, tested number.
Open with
First I would contain it: halt the rollout and pull the release so no more devices reset. Then I would protect normal sync by rate-limiting full listings per device and per shard, so a shard serves a fixed number concurrently and rejects the rest with 429 and Retry-After, and clients come back with jitter.
Then, if they want more
Incremental sync and uploads stay unlimited, so the 78 million healthy devices recover as soon as CPU drops, and the two million resets drain over hours. For the server changes, a full listing should not scan the database.
I would periodically write namespace snapshots to object storage tagged with a journal cursor, so a reset device downloads the snapshot and then calls list_changes from that cursor for the recent tail. I would also split traffic into lanes: incremental sync and uploads first, full resyncs in a background lane with a concurrency budget per shard.
On the client side, rollouts go in stages, 1 percent, 10 percent, then wider, with server metrics per client version such as requests per device and full-listing rate, an automatic halt, and server-side kill switches for client features.
And the team should know the cost of one full resync and the safe number of concurrent resyncs, and test recovery paths against production-sized folders.
About this answer
- Last updated
- 13 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 official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
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 "How do you contain this sync incident while it runs, and what changes in the server and...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/c2a18d6080/