{}DSA Atlas

Handling Load — Backpressure, Shedding & Resilience Patterns

How systems survive overload and partial failure — queueing theory basics (Little's law, utilisation vs latency), timeouts, retries with backoff and jitter, retry budgets, circuit breakers, bulkheads, backpressure, load shedding and prioritisation, queue-based load levelling, autoscaling, thundering herds, graceful degradation, and cell-based architecture.

Advanced6 interview questions

Queueing theory you need

utilisation ρ latency 050%80%95% aim to stay left of here
Average time in an M/M/1 queue = service time / (1 − ρ).
UtilisationLatency multiplier (M/M/1)
50%2×
80%5×
90%10×
99%100×

Little's law: in-flight requests = arrival rate × latency. Use it to size thread pools and connection pools: 2,000 req/s × 50 ms DB time = 100 concurrent DB connections needed.

The resilience toolbox

Edgerate limitingload sheddingWAF / DDoSpriority routing Callertimeouts / deadlinesretries + jittercircuit breakerfallbackshedged requests Servicebulkheadsbounded queuesadaptive concurrencygraceful degradation Systemqueue-based levellingautoscalingcells / shuffle shardingmulti-AZ / region
Overload protection is layered: reject early, fail fast, isolate, and scale.

Timeouts and deadlines

Every network call needs a timeout. Set it from the dependency's latency distribution (e.g., a bit above p99.9), and propagate deadlines: if the user request has 800 ms left, downstream calls get less than that (gRPC does this natively). Without timeouts, a slow dependency exhausts every thread in the caller.

Retries with backoff and jitter

import random, time

def call_with_retry(fn, attempts=3, base=0.1, cap=2.0, deadline=None):
    for attempt in range(attempts):
        try:
            return fn()
        except TransientError:
            if attempt == attempts - 1:
                raise
            sleep = random.uniform(0, min(cap, base * 2 ** attempt))   # "full jitter"
            if deadline and time.monotonic() + sleep > deadline:
                raise
            time.sleep(sleep)
async function callWithRetry<T>(fn: () => Promise<T>, attempts = 3, base = 100, cap = 2000): Promise<T> {
  for (let i = 0; ; i++) {
    try {
      return await fn();
    } catch (e) {
      if (i === attempts - 1 || !isTransient(e)) throw e;
      const sleep = Math.random() * Math.min(cap, base * 2 ** i);   // full jitter
      await new Promise((r) => setTimeout(r, sleep));
    }
  }
}

Circuit breaker

CLOSED OPEN HALF-OPEN failures > threshold cool-down elapsed trial fails trial calls succeed
Open = fail fast and give the dependency time to recover.

Bulkheads

Isolate resources per dependency or per tenant (separate thread pools, connection pools, queues, even clusters) so one slow dependency or noisy tenant can't sink everything — like watertight compartments on a ship.

Hedged requests

For tail latency: if a request hasn't returned by the p95 time, send a duplicate to another replica and take the first response (idempotent reads only). Cuts p99 dramatically for ~5% extra load (Google's "The Tail at Scale").

Backpressure

When consumers are slower than producers, something must give: buffer (bounded!), slow the producer, or drop.

MechanismWhere
TCP flow controltransport
HTTP/2, gRPC flow control windowsRPC
Bounded queues that block or rejectin-process
Pull-based consumers (Kafka) + lag monitoringmessaging
429 / 503 + Retry-AfterAPIs
Reactive streams request(n)libraries (Reactor, RxJava, Akka)

Load shedding and prioritisation

P0 checkout, login P1 browse, search P2 recs, prefetch P3 batch, retries admission controlload = 130% of capacity serve P0 + P1 reject P2/P3 fast (503)
When over capacity, drop the cheapest-to-lose work first — and drop it early.

Graceful degradation examples: serve the homepage from cache with stale data, hide recommendations, disable expensive search filters, switch to lower video bitrates, make writes async ("we'll email your receipt").

Queue-based load levelling

Put a durable queue between the bursty front and the capacity-limited back end (e.g., order processing, video encoding, third-party API with quotas). The API acknowledges with 202 Accepted; workers drain at a sustainable rate; autoscale workers on queue depth/age.

Autoscaling

TypeSignalNotes
Reactive (HPA, ASG target tracking)CPU, RPS, queue depth, laglag of 1–5 min — not enough for spikes alone
Scheduledtime of dayknown peaks (9 a.m., sales)
PredictiveML on historyAWS predictive scaling
Pre-warmingmanual before eventsSuper Bowl ads, ticket drops; also warm caches and pre-scale DBs

Scaling is limited by the slowest-scaling dependency: you can add 100 app servers in minutes but not 10 more database primaries.

Cell-based architecture and shuffle sharding

cell router (tenant → cell) cell 1LB · app · cache · DBtenants A–F cell 2 (bad deploy)LB · app · cache · DBtenants G–M affected only cell 3LB · app · cache · DBtenants N–Z
Each cell is a complete, size-bounded copy of the stack; failure blast radius = one cell.

Interview questions

0 / 6 marked confident

Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.