GOAT EngineerPreparing your learning space…

System Design · Practice problem · Hard

Survive Your Own Retries

A retry storm is when callers retrying a struggling service send it more work than it can finish, so it stays down after the original failure ends. Preventing one takes more than backoff. Build it here and watch it happen.

Hard means correctness and scale at the same time. You solve it on a canvas that runs your design. The canvas needs JavaScript; everything on this page works without it.

What is the situation?

You run the tracking page for a parcel delivery company. A customer opens the page, their phone sends GET /parcels/:id, and if no answer comes within 2 seconds the page shows an error. Your servers get the answer from the Parcel Service, which another team runs: 3 servers, each taking about 168 calls a second, so about 505 a second in all. The Parcel Service reads from the Parcel Store, a database that takes about 1,262 reads a second and fails over now and then, which means it is away for a few seconds and then comes back. Your busy hour is 300 reads a second. Last month the store failed over for 5 seconds, and the tracking page was still down long after the store came back. Design the path from GET /parcels/:id to the Parcel Store so that a failure stays the size it really was. Here is what is yours to choose. On any connection, you choose how long a caller waits before it gives up (a timeout) and how many times, and how far apart, it tries again. On the Parcel Service, you choose how many calls may wait at each of its servers before new ones are turned away. It starts at 10,000, and the other team will set it to whatever you ask. You cannot make the Parcel Service or the Parcel Store bigger. Three facts about this world. Almost no parcel is looked up twice in the same minute, so a Cache would hardly ever hold the one being asked for. Couriers' scans arrive as POST /scans and are saved in the Parcel Store, so an answer that did not come from there leaves them out and does not count as served; there are only a few scans in each test, so they are not where the load is. And there is no circuit breaker on this canvas: your tools are timeouts, retries, lines and limits.

What must your design do?

  • On a busy hour with nothing wrong, at 300 reads a second, at least 99.9% of reads are served, and 99% of them within 200 ms.
  • Reads really go through the Parcel Service and on to the Parcel Store: at least 240 a second reach each of them on that busy hour.
  • A 1 second failover at a quiet hour, 100 reads a second, costs almost nothing: at least 99.5% of reads are served.
  • If one Parcel Service server turns slow, at least 95% of reads are still served.
  • Across about a minute that holds a longer failover at the busy hour, at least 85% of reads are served.
  • After a longer failover or a surge, you are back to normal within 10 seconds of it ending. Back to normal means at least 99% of reads served for three seconds running.
  • When more reads arrive than the Parcel Service can take, at least 55% are served across the run, and 99% of those within 500 ms. Turning the rest away quickly is fine.
  • On a big day the Parcel Service can still handle, 380 reads a second, at least 98% of reads are served.
  • The system costs $470 a month or less. The Parcel Service and the Parcel Store are $255 of that, whatever you build.

What does Run test?

Run works without an account. It checks your design against 2 tests you can read before you start:

  • A busy hour with nothing wrong. 300 reads a second for 30 seconds, and nothing failed.
  • A one second failover at a quiet hour. 100 reads a second. At second 15, the Parcel Store went away for 1 second and came back.

What does Submit add?

Submit needs an account. It runs 4 more tests you cannot read in advance, and stops at the first one your design fails, showing what happened and why. Passing every test, or giving up, unlocks the written solution.

Which parts can you use?

Already on your canvas: Parcel Service, Parcel Store.

  • Load Balancer: about 50,003 a second, $18 a month each
  • API Gateway: about 20,000 a second, $35 a month each
  • App Server: about 2,000 a second, $45 a month each

Every connection takes 1 ms, and the budget is $470 a month.

What does this problem leave out?

  • A waiting call holding a thread. Here a call waiting on another holds nothing, so slow calls cannot use up your own App Servers, and a design with a short line and no timeout can pass. On a real server, set a timeout anyway.
  • Circuit breakers and retry budgets. Nothing here stops calling a service because recent calls failed, or caps retries as a share of traffic. The nearest you can build is a limit in front of the service that counts every try.
  • A server finding out its caller has gone. Here a server works on every call it accepted, and your servers keep retrying after a phone has given up. Real systems can pass a deadline along and drop that work.
  • What a refusal costs. Here turning a call away takes no time at all. A real server spends a little on each one, so a real flood of refusals can still hurt.
  • People pressing refresh. Only your servers retry here. A real customer who sees an error often tries again, which adds to a storm.
  • What a copy of the data costs. A store you add takes every write you send it, at once, so keeping your own copy to fall back on is cheaper and fresher here than it would really be.
  • Reads that do harm when repeated. A read here is safe to send twice. Repeating a write is a different problem, and other problems on this site cover it.
  • Failures of your own servers. Nothing here crashes your App Servers or your API Gateway, so running one of each is not punished.

Where does this problem fit?

Its category is Design the building block: Build the primitive itself. It practises queues & async, rate limiting & protection and reliability & ops.

See every practice problem.

By GOAT Engineer. Explore System Design · Privacy Policy · Contact.