Building a Fault-Tolerant HTTP Traffic Distribution Layer
System DesignModel answerLast updated
Design a resilient, horizontally scalable HTTP/HTTPS traffic distribution tier that routes by path or header, tracks backend health, and survives node and control-plane failures without dropping connections.
Scenario
Your platform runs a large fleet of microservices behind a single public entry point. You are asked to design the application-layer (L7) traffic distribution tier that accepts HTTP/HTTPS requests and forwards them to the right backend instance. The tier must sustain millions of requests per second and must keep serving through hardware, zone, and software failures.
What the system must do
Functional
- Route requests by URL path, host, or header values (for example, sending requests with a version header to a specific service version).
- Offer standard selection strategies such as round robin and least connections.
Non-functional
- High availability with no single point of failure.
- Horizontal scalability.
- Very small added latency per request.
Constraint
- Backend instances start and stop frequently. Doing so must not cut off connections that are already active.
What to cover in your answer
- Architecture. How clients find and reach the system (DNS, Anycast, or similar) and how traffic flows to the backends.
- Health tracking. How backend health is detected and how each node keeps a current view of the available pool.
- Failure behavior. What happens when one of your traffic nodes dies, and how the configuration/control side stays operational.
- Scaling. How you grow the tier itself as load increases.
Also address
- How you would support session persistence (sticky sessions).
- How you avoid a thundering herd when a failed backend comes back.
- When you would terminate TLS at the tier versus pass encrypted traffic through untouched.
State your assumptions about scale and do a rough capacity estimate.
Hints
Hint 1
Separate the per-request data path from the configuration path. Ask what should keep working if the configuration system goes completely offline.
Hint 2
Consider splitting the tier in two: a cheap, near-stateless packet-steering layer in front of a feature-rich HTTP layer. Think about what hashing scheme lets the front layer lose a node without breaking existing connections.
Hint 3
For safe scale-down, think in terms of endpoint states (warming, healthy, draining, unhealthy) and a drain sequence. For recovery storms, think about gradually ramping weight rather than flipping a backend instantly to full share.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Approach
Treat this as a layered system with a clean data-plane / control-plane split. One large proxy cannot give millions of RPS plus zero downtime, so I would put a lightweight L4 steering tier in front of a fleet of L7 proxies, and keep configuration distribution off the request path.
1. Assumptions and sizing
- Peak 5M RPS globally, about 1.5M per region, average response 10 KB, so roughly 15 GB/s (about 120 Gbps) per region at the busiest site.
- 10M+ concurrent connections, including HTTP/2, gRPC, and WebSocket.
- Added latency under 1 ms p50 and under 5 ms p99.
- Availability target 99.99%+. Losing a node, an AZ, or a control-plane component must not drop traffic.
- Tens of thousands of backend instances, with hundreds of membership changes per minute.
Rough capacity: a 32-core Envoy-class proxy with TLS handles about 50k RPS, so about 30 proxies per region at peak. With N+2 per AZ and 30% headroom, plan for about 45. An XDP/DPDK L4 node can handle roughly 10M packets per second, so 4-8 L4 nodes per region suffice.
2. Architecture
Client -> GeoDNS -> regional Anycast VIP (BGP)
-> Router (ECMP)
-> L4 tier (consistent hashing on 5-tuple, DSR)
-> L7 proxy fleet (TLS, routing, balancing)
-> Backends
Control plane: replicated store -> discovery service -> streaming config push to proxies
- Entry. The VIP is announced via BGP from several sites. If a site fails, its announcement is withdrawn and traffic reconverges in seconds. GeoDNS is a coarser second layer.
- L4 tier. Routers spread packets by ECMP. Each L4 node uses Maglev-style consistent hashing over the proxy pool, so every node chooses the same proxy for a flow. Losing or adding an L4 node does not break existing connections. Responses return directly (DSR), keeping the L4 tier out of the heavy egress path.
- L7 tier. Terminates TLS, parses HTTP, matches routes (host, path prefix, headers such as a version header), picks an endpoint, and keeps pooled HTTP/2 connections to backends.
Two tiers are worthwhile because L4 is cheap and scales to line rate, while the expensive feature work is isolated in an L7 tier that scales horizontally.
3. Control plane
Operators use a config API (routes, clusters with policy, health-check settings, slow-start window, stickiness). State lives in a Raft-replicated store (etcd/Consul) across three AZs, with versioned objects. A stateless, replicated discovery service watches the store and streams incremental, versioned updates to proxies, which apply them atomically. Proxies subscribe only to clusters they reference, which bounds config size.
Endpoints carry a state: WARMING, HEALTHY, DRAINING, UNHEALTHY.
4. Health monitoring
Combine three signals:
- Active probes every 1-5 s with jitter; unhealthy after 3 consecutive failures, healthy after 2 successes. To avoid N proxies x M endpoints probe load, either shard probing or use a dedicated health-checker service that writes results to the store.
- Passive outlier detection on real traffic (5xx rate, connect errors, timeouts). Eject locally for an exponentially growing interval. It reacts faster than probes and needs no coordination.
- Lifecycle events from the orchestrator (register as warming, mark draining before shutdown).
Safe scale-down: mark DRAINING, stop new requests, let in-flight requests finish within a drain timeout (say 30 s), send HTTP/2 GOAWAY, then terminate.
Panic threshold: if more than about 50% of a cluster appears unhealthy, ignore health status and spread across everything. A faulty health check should not black-hole a service.
5. Failure handling
- L7 node dies: L4 health-checks proxies about every second and removes it from the table. Only flows on that node break; clients retry, and idempotent requests are retried automatically.
- L4 node dies: ECMP/BGP removes it. Identical hashing on surviving nodes keeps flow-to-proxy mapping stable.
- Site dies: withdraw the Anycast announcement and let GeoDNS shift traffic.
- Control plane dies: the data plane fails static. Proxies keep serving with last-known-good config and continue local passive checks. Raft tolerates minority loss.
- Bad config: validate before applying and roll out progressively region by region so a single push cannot take everything down.
6. Scaling the tier itself
- Add L7 proxies and register them in the L4 table; autoscale on CPU and connection count with headroom.
- Add L4 nodes to ECMP groups; add regions or PoPs behind the same VIP.
- For very large tenants, use dedicated proxy cells to limit blast radius.
7. Key considerations
Sticky sessions. Prefer stateless services. If needed, use a cookie encoding the endpoint ID (works through any proxy) or consistent hashing on a session or user key to minimize remapping on membership change. Avoid source-IP affinity because NAT skews load. Always fall back if the pinned endpoint is unhealthy.
Thundering herd on recovery. Use slow start so a new or recovered endpoint's weight ramps over 30-60 s. Jitter health checks so proxies do not flip together. Prefer least-request over plain round robin. Let instances warm caches before reporting healthy.
TLS termination vs pass-through. Terminate at L7 when you need header/path routing, retries, WAF, or observability; this is required for the stated routing features. Re-encrypt to backends (mTLS) when internal traffic must be protected. Use pass-through (L4, routing by SNI only) when end-to-end encryption is mandated or keys must not reach the proxy, accepting that you lose content-based routing.
Common mistakes
- Putting the control plane in the request path, so its outage causes an outage.
- Using modulo hashing at L4, which reshuffles most flows on any change.
- Forgetting connection draining, so deploys cause error spikes.
- Letting every proxy probe every endpoint.
- No panic threshold, so bad health data empties the pool.
- Pushing config globally at once.
Trade-offs
Two tiers add a hop and operational complexity but buy scalability and failure isolation. Aggressive health thresholds detect failures faster but risk flapping. Cookie stickiness is robust but weakens even load spreading; consistent hashing needs no client state but still shifts some keys on churn.