The restaurant host, and the lunch rush
Sameer runs TiffinBox, an app that delivers home-cooked lunch. At 12:30 every weekday, 200,000 people open it in the same ten minutes. (Sameer, TiffinBox and every number here are made up for teaching.)
His sister runs a busy restaurant, and her host at the door does three jobs:
- Decide which table gets the next party.
- Notice when a table is out of service.
- Keep a regular customer with the waiter they like.
A load balancer does the same for requests and servers. At city level, a group of restaurants shares a call centre that sends you to the nearest branch. That is global traffic management.
Sameer's growing pains walk through both levels, and the network machinery underneath:
| Growing pain |
Idea it forces |
| "One server can't survive the lunch rush" |
A load balancer: layer 4 vs layer 7 |
| "One server is drowning while three sit idle" |
Balancing algorithms |
| "Customers' carts vanish when a server restarts" |
Sticky sessions vs stateless servers |
| "A database blip took every server out" |
Health checks done safely |
| "Customers in London say the app is slow" |
Global traffic: geo-DNS, anycast, regions |
| "The first screen is slow on 4G" |
DNS, TCP and the TLS handshake |
| "Images load one by one; Wi-Fi to 4G drops the order" |
HTTP/1.1, 2 and 3 |
| "Where do login checks and rate limits go?" |
API gateway vs load balancer vs proxy |
This guide follows Networking and APIs and precedes API design.
1. "One server can't survive the lunch rush": layer 4 vs layer 7
Sameer adds four more servers. Now something has to decide which server each request goes to, and that something is the host at the door. There are two kinds of host:
|
Layer 4 (transport) |
Layer 7 (application) |
| Sees |
IP addresses, ports, TCP/UDP |
HTTP method, path, headers, cookies |
| Speed |
Very fast, little work per connection |
Slower; parses requests |
| Can do |
Spread connections, TLS passthrough |
Path routing, header rules, rewrites, TLS termination, WAF, retries |
| Typical |
Cloud network load balancers |
Nginx, Envoy, HAProxy, cloud application load balancers |
You've reached the free preview of this post.
Subscribe to the Blogs plan (₹99/mo) — or use any Algomi Suite, Career, Investor, or Trader plan — to keep reading.
See plans