Global and local load balancing
medium 25 minTraffic is steered twice: a global step picks the region with DNS or anycast, and a local step picks a server inside it.
See it run
Follow one request through both steps, compare policies, and watch a region fail with DNS and with anycast.
Operations
One request, two steps
A user in Tokyo. GeoDNS picks the region, the local balancer picks a server.
Step 1 of 6
A request starts
Which region?
The user opens api.example.com.
Step 1: A request starts
def handle(user, request): region = dns(request.host, near=user) # global, cached return region.balancer.forward(request)def forward(request): # local, every time pool = [s for s in servers if s.healthy] return min(pool, key=open_requests).handle(request)- Failover
- Server: at once
- Decided by
- Place, then load
- Example regions
- Tokyo, Singapore; EU West, EU North; US East, US West
The global step is cached. The local step happens every time.
In the real world
The same global and local load balancing doing real jobs. Pick one and step through it.
Weights move with the working day, in UTC.
Step 1 of 3
02:00
- Asia-Pacific
- 70%
- Europe
- 10%
- Americas
- 20%
Mostly Asia-Pacific
Asia-Pacific is at work and carries most of the traffic.
Step 1: 02:00
Common mistakes
The bugs interviewers watch for, with the fix beside each.
No room in the other region
criticalThe failover succeeds and the second region falls over.
Wrongtwo regions at 70%Righttwo regions at 40%shed low-priority work firstGeolocation without a default
majorUsers whose place is unknown get no answer.
WrongEU -> eu, NA -> usRightEU -> eu, NA -> useveryone else -> usPromising instant failover with DNS
majorDetection and caches take time, and some clients never ask again.
WrongRTO: 5 s, TTL: 300 sRight10 * 3 + 60 = 90 splus a tailMoving traffic before data
criticalThe new region shows old data, or two regions accept the same write.
Wrongroute(user, B)Rightstop_writes(A)wait_for_replication(B)route(user, B)
Interview tips
How to explain it
- Global: which region.
- Local: which server.
- Different information, different speed.
Memory trick
- First the mountain, then the lift.
- Booking picks the airport, staff pick the counter.
- Health filters, policy chooses.
Numbers to say
- Interval × failures + TTL.
- Use at most (n-1)/n of the limit.
- About 5 ms per 1,000 km, one way.
Be careful with
- Data that has not arrived.
- Resolvers far from users.
- Untested standby regions.