Skip to content
Dev Dump

🔁 Load Balancer Fundamentals

  • Prevents single-node overload and removes single points of failure.
  • Improves latency by routing to healthy, nearby, or least-loaded instances.
  • Enables rolling deploys, blue/green releases, and maintenance without downtime.

Overview

  • Scalability: horizontally add or remove compute without impacting clients.
  • Availability: continue serving traffic when instances fail.
  • Performance: route requests using health, latency, or customized policies.
StrategyMechanismBest ForDrawbacks
Round robinRotate through backend listHomogeneous serversIgnores load differences
Weighted round robinPrefer nodes with higher capacity weightsMixed instance sizesStatic weights; no live feedback
Least connectionsPick node with fewest active sessionsLong-lived connectionsNeeds accurate connection tracking
Least response timeChoose node with fastest current latencyDynamic response environmentsRequires continuous measurements
IP hashHash client IP to select backendSession affinityCan create uneven load distribution
RandomRandomly pick serversLarge pools with similar healthNo awareness of hot nodes
Adaptive/dynamicExternal metrics (CPU, queue depth) inform routingHighly variable workloadsComplex to implement and tune

Stateful vs. Stateless Balancing 🧭

TypeHow It WorksProsCons
StatefulBalancer tracks session/user stateSeamless affinityHarder to scale/replicate balancer
StatelessEach request routed independentlyEasy to scale horizontallyNeeds external store for session data

Layer 4 vs. Layer 7

  • Definition: Operates at the transport layer of the OSI model.
  • Function: Directs traffic based on IP addresses and ports.
  • Advantages: Simple and fast due to minimal data inspection.
  • Disadvantages: Lacks ability to make decisions based on application-specific data.
  • Definition: Operates at the application layer of the OSI model.
  • Function: Directs traffic based on HTTP headers, cookies, and request content.
  • Advantages: Supports sophisticated traffic management such as routing by URLs or user agents.
  • Disadvantages: More complex and slower due to deep packet inspection.