System Design: load balancing layer 7
This course covers layer 7 load balancing, using a Rails application that runs kamal-proxy behind Cloudflare. It compares layer 4 and layer 7 balancers. It explains how a balancer picks a backend with round robin, least connections, hashing and weights. It covers how deep a health check should go and why a check on a shared database can remove every backend. It also shows how X-Forwarded-For and trusted proxies affect client addresses and rate limiting. It ends with path routing, the preconditions for fuller features and a least-connections exercise.
What you'll learn
- ✓The difference between layer 4 packet forwarding and layer 7 request parsing
- ✓Round robin, least connections, hashing and weighted backend selection
- ✓Choosing a health check depth that distinguishes one backend from the others
- ✓Reading client addresses safely with X-Forwarded-For and trusted proxies
- ✓When path routing fits and when the code has no real deployment boundary
- ✓Implementing least-connections selection with health filtering and stable ties
The two layers
A load balancer either understands your traffic or it doesn't, and that one distinction produces two families of product with almost nothing in common except the name.
Read the full lesson free →Curriculum
7 lessonsThe two layers
Compares layer 4 packet forwarding with layer 7 request parsing and TLS termination, and places kamal-proxy and Cloudflare.
Choosing a backend
Explains round robin, least connections, hashing and weighted variants, and why least connections is the usual default.
Health checks that mean something
Shows why health check depth matters, how a shared database check fails every backend, and how intervals are tuned.
What the balancer can see
Covers how a balancer hides client addresses, why X-Forwarded-For can be forged, and how trusted proxies handle it.
Routing by path
Explains path routing across independent deployments and why this application's namespaces stay inside one Rails process.
What this application would gain
Reviews what kamal-proxy already does, which features wait on preconditions, and what the application trusts Cloudflare about.
Putting it together
Summarizes the course and sets a challenge: least-connections backend selection with health filtering and stable tie-breaking.