Cloud load balancing
medium 25 minA cloud load balancer is a load balancer you rent.
See it run
A balancer you rent: the same path in three clouds, what grows by itself, what happens when a zone fails and what you pay for.
Operations
One path, three clouds
The same three stops on AWS, Google Cloud and Azure: a global entry, a load balancer, and regions.
Step 1 of 5
AWS: the entry
Users find the entry with Route 53 or CloudFront.
Step 1: AWS: the entry
def handle(request): entry = nearest_entry(request.client) region = choose_region(entry, healthy_regions()) target = pick(region.target_group) # healthy only return forward(request, target)- Reacts in
- Milliseconds
- You pay
- Hour + usage
- Own proxies
- machines, patches, on-call
The names change between clouds. The three questions (near whom, which region, which server) do not.
In the real world
The same cloud load balancing doing real jobs. Pick one and step through it.
A global entry over two regions of equal size.
Step 1 of 4
Both serve
Half and half
Each region works at 45% of its capacity.
Step 1: Both serve
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Believing the balancer scales the servers
criticalIt grows alone. The servers behind it need their own scaler.
Wrongcreate(load_balancer)# "it is managed, it scales"Rightcreate(load_balancer)create(auto_scaler, requests_per_target=800)schedule(servers=24, before="sale")Storing the address
majorAddresses behind the name change when the balancer scales.
WrongAPI = "203.0.113.10"RightAPI = "api.example.com" # or a kind with static addressesNo spare zone
criticalWhen one of three zones fails, the other two receive 50% more each.
Wrongper_zone = peak / (per_server * 3)Rightper_zone = ceil(peak / (per_server * 2))Leaving health checks at the default
majorA dead server may receive traffic for about a minute.
Wronghealth_check(path="/") # 30 s, 2 failuresRighthealth_check(path="/health", interval=10, timeout=2, unhealthy=2)
Interview tips
How to explain it
- A load balancer you rent.
- The provider scales, patches and replaces it.
- You choose kind, zones, checks and spare capacity.
Memory trick: CLOUD
- Configuration as code, Load distributed.
- On-demand scaling, Uptime agreement.
- DNS built in.
Choose by
- Web requests or connections?
- One region or many?
- Must the address be fixed?
Check before launch
- Cross-zone setting.
- One zone of spare.
- Detection time and draining.
- The largest billed measure.