KatInterview

Build a Traffic Distributor for L4 and L7 Backend Pools

System DesignModel answer
MediumModel answerSystem Designload-balancinghigh-availabilityhealth-checks

Last updated

Design a software traffic distributor that spreads L4 and L7 requests across a backend pool, with health monitoring, sticky sessions, failover, and its own horizontal scaling.

Task

You are asked to design a software traffic distributor that sits in front of a fleet of application servers. It accepts client connections and forwards them to healthy backends. It must work for both L4 (raw TCP) and L7 (HTTP/HTTPS) traffic.

Functional requirements

  • Distribute traffic by a configurable policy: round robin, least connections, or weighted distribution.
  • Probe backends periodically and take unhealthy ones out of rotation, then bring them back when they recover.
  • Support session affinity ("sticky sessions") for L7 traffic, so a returning user tends to reach the same backend.

Non-functional requirements

  • High availability: the distributor must tolerate failures of its own nodes without dropping the service.
  • Scalability: it must hold thousands of concurrent connections, and scale out as load grows.
  • Latency: it should add minimal overhead on the request path.

Scale assumptions

  • Peak load of 100,000 requests per second.
  • A pool of 50 backend servers.

What to deliver

  1. A high-level architecture, described in text (components and how they connect).
  2. How state is managed: connection tracking, backend health, configuration, and session affinity.
  3. The request flow for L4 traffic and for L7 traffic.
  4. A strategy for scaling and protecting the distributor itself.

State your assumptions, size the system with rough numbers, and call out the trade-offs you are making.

Hints

Hint 1

Start with numbers: 100K RPS over 50 backends is about 2K RPS each. Estimate concurrent connections and egress bandwidth, and ask whether TLS terminates at the distributor.

Hint 2

Separate the control plane (config, health, membership) from the data plane (packet and request forwarding). The data plane should keep serving if the control plane is unreachable.

Hint 3

Ask which state truly needs to be shared. Connection tables can be rebuilt from a deterministic hash, load counts can stay local (try sampling two backends), and stickiness can live in a signed cookie.

Hint 4

For failover, think about how a front tier spreads flows across distributor nodes (ECMP/BGP with a stable VIP) and how a node dying avoids breaking existing connections.