Skip to content
BIASED

Resilience and capacity

How a service survives slow and failing dependencies and heavy load: timeouts and deadlines, retries with backoff and jitter, retry amplification, circuit breakers and bulkheads, rate limiting and load shedding, idempotency, Little's law and queueing delay versus utilization.

Timeouts and deadlines

Availability of a service that hard-depends on others is at most the product of their availabilities; soft dependencies and graceful degradation push back against that math. This topic is about keeping failures small when they happen. Clients that wait forever on a slow payment path hold workers, sockets and memory until upstream retries amplify load and turn a dependency blip into your outage.

Set timeouts from the dependency's latency tail, not from hope. If the dependency's p99 is 200 ms, a 10 s client timeout is not "safe" — it is permission for each stuck call to occupy a worker for 10 s. At 500 RPS with 2% of calls stuck that deep, you need on the order of 0.02×500×10=1000.02\times500\times10=100 extra concurrent workers just to hold the dead weight. Propagate deadlines (absolute deadlines or remaining time budgets) so cancelled clients stop work downstream instead of finishing useless queries after the user is gone.

Distinguish connect timeout, request timeout and total deadline. A generous connect timeout with a tight total deadline still fails fast when the network is blackholed.

Retries, backoff, jitter

Retry only transient, safe failures — 503, connection resets, idempotent GETs. Do not blindly retry 400s or non-idempotent POSTs. Exponential backoff with full jitter desynchronizes thundering herds when a dependency recovers: every client choosing Uniform(0,min⁡(cap,base⋅2attempt))\mathrm{Uniform}(0, \min(cap, base\cdot 2^{attempt})) spreads load instead of aligning on the same sleep.

Retries at every layer multiply. With aa attempts per layer and LL layers, the bottom can see up to aLa^{L} attempts for one client call — 27 for a=3a=3, L=3L=3. A single user click becomes 27 payment authorisations if each layer retries a POST. Use retry budgets (e.g. at most 10% of traffic may be retries) and prefer retrying at one layer. State-changing calls need idempotency keys — a timeout after "charge card" is ambiguous; without a key, a retry double-charges.

Record retry count on metrics. A quiet rise in retries with stable success rate is a leading indicator that a dependency is degrading — cheaper to see than waiting for the error budget burn alert.

Bulkheads and load shedding

Circuit breakers stop calling a dark dependency for a cool-down after error rates cross a threshold — fail fast locally instead of queueing. Half-open probes let a trickle through to test recovery. Bulkheads cap concurrency or pool size per dependency so a slow recommendations service cannot exhaust the worker pool the checkout path needs. Rate limits, load shedding and backpressure turn overload into quick 503s (or "try again") instead of unbounded queues that make every request slow.

Bound everything that can grow: time, attempts, concurrency, queue length, offered load. Make repetition safe. An infinite queue feels kind and is how shared services die: Little's law says L=λWL=\lambda W — if WW grows under overload, LL grows until memory or thread pools snap.

Worked shed. A service handles 800 RPS comfortably at W≈50W\approx50 ms (L≈40L\approx40 in flight). At 2 000 RPS offered with capacity still ~800 RPS, an unbounded queue grows without bound; shedding at 1 000 RPS admitted keeps WW finite for the requests you accept. Users prefer a fast failure and retry to a 30 s hang.

Queueing and capacity

Little's law L=λWL=\lambda W relates arrivals, in-flight work and latency in stable systems. Simple queueing models: mean delay grows like 1/(1−ρ)1/(1-\rho) as utilization ρ→1\rho\to 1. Running hot at ρ=0.95\rho=0.95 looks efficient on a CPU dashboard until tails explode and every deploy tip the system over. Capacity plans include peak and failure: lose a zone holding one third of replicas and the remaining capacity must absorb the peak without crossing the latency cliff.

Worked Little. λ=50\lambda=50 req/s, average L=100L=100 requests in the system → W=L/λ=2W=L/\lambda=\mathbf{2} s. If λ\lambda holds and LL climbs to 200, latency doubled — an early capacity signal before hard errors.

Keep headroom: many teams size for ρ≤0.7\rho\le 0.7 at expected peak on the surviving failure domain. Autoscale helps but reacts late; combine with load shedding for the minutes HPA needs to add Pods.

Load tests that only ramp happy-path RPS miss the failure modes that burn budgets: dependency timeouts, cache stampedes after eviction, reconnect storms after a blip. Inject latency and errors in staging (aligned with chaos practice) while you watch retry metrics, pool utilisation and shed rates. Capacity is a hypothesis until tested under the same deadlines production uses.

Cache stampedes deserve an explicit pattern: singleflight / request coalescing so one miss does not become 5 000 origin calls. Combined with bulkheads, coalescing keeps a cold cache from becoming an outage. Document the degraded mode each dependency enters when its breaker opens — empty recommendations is fine; empty auth is not.

Next: Incidents and operational security — when defences fail, how to mitigate, learn and harden so the same failure is harder to repeat.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.