Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
System Design topics
Lesson 4/ 31
Fundamentals & Networking

Load Balancing & Proxies

Distribute traffic cleanly across healthy backends while terminating TLS and enforcing routing rules.

BeginnerL4 vs L7 · Health Checks3 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
Layer 4 vs. Layer 7 Load Balancing

Compare packet-level speed (L4) against HTTP-aware smart routing (L7).

Beginner
Load Balancing Algorithms & Health Checks

Round Robin, Weighted, Least Connections, and active/passive health checks.

Beginner

In plain words

A load balancer is like a host at a busy restaurant who seats guests at whichever table is free, so no single waiter is overwhelmed.

Think of it like…

A restaurant host who sees which tables are open or busy and seats incoming guests evenly instead of crowding one waiter.

Where you’ve seen it

An online store runs 20 identical web servers. A load balancer spreads incoming shoppers across them and stops sending traffic to any server that crashes.

Words you’ll hear

Load balancer
A component that spreads incoming requests across many servers.
Health check
A regular ping to see if a server is alive before sending it traffic.
Reverse proxy
A server that sits in front of your servers and forwards client requests to them.
L4 vs L7
L4 routes by IP and port only; L7 can read the request (URL, headers) to route smarter.

Visual diagram

Loading interactive diagram
Loading interactive exercise

Theory & deep dive

Forward Proxy vs. Reverse Proxy

A forward proxy sits in front of clients (e.g., a company VPN or school filter) and hides who the client is from the internet. A reverse proxy sits in front of your backend servers (e.g., NGINX, Cloudflare, AWS ALB) and hides your internal servers from clients.

Almost every production web service uses a reverse proxy/load balancer for TLS termination, compression, caching, rate limiting, and routing traffic cleanly.

Key takeaway: Forward proxy protects/represents the client; reverse proxy protects/represents the servers.

Layer 4 (Transport) vs. Layer 7 (Application)

An L4 load balancer only reads IP addresses and TCP/UDP ports. It forwards raw packets at blisteringly high speed (millions of connections/sec) without reading HTTP headers.

An L7 load balancer reads the actual HTTP request - URL path (/api/search vs /api/billing), cookies, headers, and JWTs - so it can route smartly, terminate TLS, and enforce rate limits, at slightly higher CPU cost.

Choosing the right balancing algorithm

Round Robin sends requests in order (1, 2, 3, 1, 2, 3) - great when all requests cost the same. Least Connections picks whichever server currently has the fewest active requests - much better when some requests take 10 ms and others take 2 seconds.

Consistent Hashing routes by user ID or cache key so a local cache stays warm on the same node.

How it works, step by step

Step 1 of 4
Edge / VIP

1. Client connects to Load Balancer VIP

DNS resolves to a virtual IP (VIP) backed by redundant active-passive or active-active load balancers.

Avoid making the LB itself a single point of failure
Key numbers at this step
HA Pair
VRRP / Anycast
TLS
Terminated at LB

When to use it & trade-offs

What it is

A load balancer sits in front of backend servers, monitors health, terminates connections, and spreads incoming requests across healthy instances.

Why it matters: Without load balancing, you cannot scale horizontally or take a server down for deploys without dropping user requests.

When to reach for it

  • Spreading load across stateless web/API servers and microservice fleets
  • TLS termination, HTTP/2-to-HTTP/1.1 translation, and path-based routing
  • Zero-downtime rolling deploys via health checks and connection draining

When to avoid or be careful

  • Deploying a single load balancer instance with no failover pair
  • Enabling sticky sessions on stateless APIs (causes uneven skew during auto-scaling)

L4 vs. L7 & Balancing Algorithms

Layer 4 (Transport) LB
Best for: Extreme throughput, non-HTTP TCP/UDP, front tier before L7

Strengths: Minimal memory/CPU per connection; preserves low latency at millions of PPS.

Watch out: Cannot inspect URLs, headers, cookies, or retry idempotent HTTP GETs.

Layer 7 (Application) LB
Best for: Microservices routing, TLS termination, gRPC/WebSockets, WAF

Strengths: Routes by path/host, strips TLS, compresses responses, retries failed GETs.

Watch out: Higher CPU/memory overhead from parsing HTTP and maintaining two TCP connections.

Least Connections / P2C
Best for: Mixed request durations (heavy vs. fast endpoints)

Strengths: Avoids piling slow requests onto a single server (unlike blind round-robin).

Watch out: Requires tracking active in-flight requests per backend.

Interview signals & numbers to know

When this topic comes up

  • high throughput
  • reverse proxy
  • TLS termination
  • zero downtime deploy
  • routing by path

Benchmarks & rules of thumb

L7 LB hop overhead -
~0.5–2 ms
Health check interval -
5–10s
Idle keep-alive timeout -
60–300s
Graceful drain timeout -
30–60s

Common mistakes & follow-ups

Common interview mistakes

  • Forgetting that the load balancer itself must be redundant (active-passive or Anycast pool)
  • Using round-robin for WebSockets or uneven queries where least-connections prevents skew
  • Not forwarding X-Forwarded-For / Traceparent headers to downstream services

Likely interviewer follow-ups

  • Forward proxy vs. reverse proxy - how do their roles and placement differ?
  • How do you load balance long-lived WebSocket connections?
  • What is the Power of Two Choices (P2C) algorithm and why does Envoy use it?
Interview tip: If your design uses WebSockets or gRPC streaming, explicitly state L7 sticky/least-connections balancing and connection draining.

Knowledge check

Loading quiz

Put it into practice

Design full architectures with AI feedback

Apply Load Balancing & Proxies inside real High-Level Design prompts or review Q&A flashcards.

Open AI HLD Practice →SD Interview Q&A
Previous topic
DNS & Anycast Routing
Next topic
CDN & Edge Computing