Load balancing and scaling practice
45 min · Intermediate
Load balancing questions in interviews and code reviews come down to four skills: tracing an algorithm by hand, spotting the concurrency bug in a balancer, turning traffic into a server count, and deciding which requests should never reach your servers at all.
Topics in this lesson
- Tracing round robin and least connections
- Fixing a balancer that is not thread-safe
- Servers for traffic and failure tolerance
- CDN or app server?
Key points
- Round robin ignores server state; least connections tracks open requests and avoids busy servers.
- A safe round robin uses
AtomicInteger.getAndIncrement()andMath.floorMod, over an immutable server list. - Servers = ⌈peak ÷ (RPS × use)⌉ plus spares; zone failure and database connections can raise or cap that number.
- Static, versioned files go to the CDN; personal and secret responses never do.
Interview questions this lesson answers
- How does a load balancer know a server is down?
- Round robin or least connections for ShopLite's API?
- How would you make a round robin balancer thread-safe in Java?
- How many servers do you need for 6,000 RPS?
- What would you serve from a CDN?
- Why are sticky sessions a problem, and what do you do instead?
- What happens to in-flight requests when you deploy a new version?
Sign in to continue this lesson
Create an account to read every lesson, practise with the exercises and keep track of your progress.