Beginner LevelSystem Design & Architecture
How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?
β Interview Prompt: Explain Load Balancing layer 4 (TCP/UDP) vs layer 7 (HTTP), Round Robin, Least Connections, Weighted Round Robin, and IP Hash algorithms.
A Load Balancer acts as a reverse proxy traffic cop, routing incoming client requests across a pool of backend servers:
Load Balancing Algorithms:
β’
Round Robin: Routes requests sequentially across the server pool ($S_1 \rightarrow S_2 \rightarrow S_3 \rightarrow S_1$).
β’
Least Connections: Directs new traffic to the server with the fewest active connection sockets (ideal for long-lived HTTP/WebSocket sessions).
β’
Weighted Round Robin: Assigns higher traffic ratios to more powerful server instances.
β’
IP Hash: Hashes the client IP address to route the user to the same server consistently (Sticky Sessions).
Code Implementation Example
markdown
Load Balancer Architecture Flow:
[Clients] ββ> [Layer 7 Load Balancer (NGINX/HAProxy)]
βββ> [Server Node 1 (Active: 10)]
βββ> [Server Node 2 (Active: 3)] <-- Least Connections Route!
βββ> [Server Node 3 (Active: 12)]π‘Load Balancer distributing requests using Least Connections.
π― Interview Key Takeaway
Use Layer 7 Load Balancers with Least Connections or Weighted Round Robin to distribute traffic evenly across server pools.
#System Design#Load Balancing#Algorithms#Layer 7#Beginner
Back to all System Design & Architecture Questionsβ