Skip to content
Engineering Bible
System Design

System Design on reliability

Every remote call needs a timeout

  • Without one, a slow dependency ties up your threads and connections until you fail too.
  • Amazon's rule: accept a rate of false timeouts, say 0.1%, then use the p99.9 latency.
  • Pass the deadline down the call chain, so no one works on a request already given up.

Retry with backoff and jitter

  • Retry only what may pass next time: timeouts and server errors, not bad requests.
  • Back off: wait longer after each failure, for example 1, 2, then 4 seconds.
  • Add jitter, a random extra wait, so clients do not all retry at the same moment.
  • Cap the attempts. Google's clients stop at 3 tries per request.

Retries multiply down the stack

  • If 5 layers each try a call 3 times, the database can see 243 times the load.
  • Retry at one layer only, and answer “overloaded, do not retry” when full.
  • Use a retry budget: Google's clients retry at most 10% of their requests.

An idempotency key makes a retry safe

  • After a timeout the client cannot know if the request ran. A retry may charge twice.
  • The client sends a unique key with the request and reuses it on every retry.
  • The server stores the key with the result, and returns that result for a repeat.
POST /v1/charges
Idempotency-Key: order-1042-payment-1

amount=2000&currency=usd
Stripe's API takes the key as a header on POST requests. Same key, same result, one charge.

Limit and shed load before it sinks you

  • A rate limiter caps each client, say 100 requests a second, then answers HTTP 429.
  • Token bucket: each request spends a token and tokens refill steadily. Bursts are fine.
  • Load shedding drops low-priority work when the whole system nears its limit.
  • Rejecting some requests fast beats serving every request slowly.

A circuit breaker stops calls to a failing dependency

  • Closed: calls pass and failures are counted. Too many failures open the breaker.
  • Open: calls fail at once with no waiting. The dependency gets room to recover.
  • Half-open: after a pause, a few test calls pass. If they succeed, it closes again.
  1. Closedcalls pass, failures counted
  2. Openfail fast, no calls made
  3. Half-opena few test calls

then back to “Closed”

If a test call fails in half-open, the breaker goes back to open.

Watch four signals, and page on symptoms

  • Google's four golden signals: latency, traffic, errors and saturation.
  • A trace follows one request through every service, showing where the time went.
  • Page a person for what users feel, like error rate, not for every cause, like CPU.
System Design in seven pages7 / 7