DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • How the Web Works
  • Browsers: The Engines
  • Networking & Latency
  • HTTPS & TLS Handshake
  • CDNs & Edge Computing
  • WebSockets & WebRTC
  • RESTful Architecture
  • GraphQL Architecture
  • CORS (Cross-Origin Resource Sharing)
  • Load Balancing
  • Critical Rendering Path Deep Dive
  • DOM vs. CSSOM Construction
  • The Rendering Engine: Layout, Paint, Compositing
  • JavaScript Engine: V8 Internals
  • The Event Loop: Macro vs. Micro Tasks
  • Garbage Collection
  • Browser Storage Architecture
  • Service Workers & PWAs
  • Web Workers: Multi-Threading
← From Beginner to Expert in Fundamentals of Frontend

Load Balancing

15 min read
Load BalancerRound RobinLeast ConnectionsHealth ChecksHorizontal ScalingSticky Sessions

Load Balancing: Distributing Traffic Across Servers

When a single server can't handle all traffic, you add more servers. A load balancer sits in front and distributes incoming requests across them.

Load Balancing Algorithms

AlgorithmHow It WorksBest For
Round RobinRequests go to servers in order: A, B, C, A, B, C...Equal-capacity servers
Weighted Round RobinStronger servers get more requestsMixed-capacity servers
Least ConnectionsSend to the server with fewest active connectionsVarying request durations
IP HashSame client IP always goes to the same serverSession persistence
RandomRandomly pick a serverSimple, surprisingly effective

Health Checks

Load balancers periodically ping each server (e.g., GET /health). If a server fails to respond, it's removed from the pool until it recovers.

Sticky Sessions

Some apps store session data in server memory. If a user's second request goes to a different server, their session is lost. Sticky sessions (via cookies) ensure the same user always hits the same server.

Better alternative: Store sessions in a shared store (Redis) so any server can handle any request.

Why Frontend Devs Should Care

  • WebSocket connections need sticky sessions or a shared pub/sub layer (Redis).
  • File uploads to one server won't be visible on another without shared storage.
  • Caching: Each server has its own in-memory cache. Use a shared cache (Redis/Memcached) instead.
  • Debugging: An error on "server 3" won't reproduce if you hit "server 1". Use request IDs for tracing.

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.