Load Balancing interview problems
Load balancing questions ask you to pick a backend for each request. You will implement round robin with itertools.cycle or an index modulo the list length, weighted round robin, random choice with random.choices(backends, weights=...), least connections with a counter per backend, or power of two choices. Follow-ups add health. Mark a backend down after failures, skip it, and bring it back after a probe succeeds. Sometimes the question adds consistent hashing so a key keeps landing on the same backend when the pool changes.
The common bugs are a round robin index that breaks when a backend is removed, least-connections counters that never decrement when a request fails or is cancelled, and weighted schemes that send bursts to one backend instead of spreading them. A strong answer updates in-flight counts in try/finally, handles the case where every backend is unhealthy with a clear error, and keeps selection O(1) or O(log n). It also explains why least connections beats round robin when request costs vary widely.
2 locked
These open in order of demand. Open one and press I want this one to ask for it.
- 29Round-Robin Load Balancer Lockedeasy
Route async requests to model replicas in round-robin order, skipping replicas marked unhealthy and failing fast when none are left.
- 30Least-Loaded Replica Scheduler Lockedhard
Send each async request to the healthy replica with the fewest in-flight requests, wait when all are full, and react to health changes.