GoodNotes Architect Journal
🏠 Index 1. Single Server 2. Selecting DB 3. Relational & SQL 4. ACID Integrity 5. NoSQL Types 6. Scaling Guide 7. Load Balancing 8. SPOF & HA 9. API Design 10. Comm Protocols 11. TCP & UDP 12. REST Design 13. GraphQL Architecture 14. Authentication Protocols 15. JWT & OAuth 2 16. Authorization Models
System Design Chapter 7

Load Balancer Algorithms & Health Checks

7 Traffic Routing Strategies, Session Persistence, & Failover Management

β˜… Essential for high availability, fault tolerance & scaling!

A Load Balancer distributes incoming client traffic across multiple backend servers to ensure no single server bears too much load, preventing bottlenecks and single points of failure (SPOF).

❓ Core Question: How does a Load Balancer distribute traffic?

Load balancers utilize 7 core algorithms and strategies depending on server capacity, session requirements, and geographical proximity.

7 Load Balancing Strategies & Algorithms

πŸ”„ 1. Round Robin

Redirects incoming requests in sequential cyclical order: Server 1 βž” Server 2 βž” Server 3 βž” Server 1.

πŸ’‘ Best for: Environments where all servers have identical hardware specifications and request processing times are uniform.

πŸ”— 2. Least Connections

Redirects traffic to the server currently handling the fewest active connections.

πŸ’‘ Best for: Applications with long-lived persistent connections (e.g. WebSockets, streaming) where session lengths vary significantly.

⚑ 3. Least Response Time

Redirects traffic to the server that is most responsive and serving responses with the lowest latency.

πŸ’‘ Best for: Providing the fastest response times when backend servers have different performance specs.

πŸ”‘ 4. IP-Hash

Hashes the client’s IP address to consistently map future requests from that IP to the exact same server.

πŸ’‘ Best for: Session persistence (Sticky Sessions) when user state/session info is stored locally on a specific server and not synced across nodes.

βš–οΈ 5. Weighted Algorithms

Servers are assigned weights based on capacity. Higher-capacity servers receive a proportionally larger share of traffic.

πŸ’‘ Best for: Heterogeneous server clusters where nodes have different CPU, RAM, or network bandwidth specifications.

πŸ—ΊοΈ 6. Geographical Algorithms

Redirects traffic to the server located closest to the user’s Geographical IP location.

πŸ’‘ Best for: Global applications requiring latency reduction and localized content delivery (Geo-DNS routing).

β­• 7. Consistent Hashing (Popular but Complex)

Standard hashing (Server = hash(key) % N) breaks down when servers scale up or down because almost 100% of keys get remapped. Consistent Hashing solves this by mapping both servers and keys onto a circular ring topology.

β­• Consistent Hash Ring & Clockwise Routing

Both servers and user requests are mapped onto a 360Β° circular hash ring. Requests travel clockwise to hit the first available server node.

Clockwise SearchS1Server 1S2Server 2S3Server 3Key 1HASH RING0 βž” 2Β³Β² - 1

πŸ’‘ How Consistent Hashing Works (Step-by-Step):

  1. Ring Topology: Backend servers (S1, S2, S3) are hashed by IP/name and placed at fixed points along a 360Β° circular ring.

  2. Clockwise Request Lookup: When a user request (Key 1) arrives, its hash location is calculated on the ring. The system moves clockwise around the ring to find the first server it hits (S2).

  3. Minimal Remapping on Crash/Add: If S2 crashes, only requests mapped to S2 move to S3. Keys on S1 & S3 remain 100% untouched!

🩺 Health Checks & Failover Management

❓ How does a Load Balancer know a server is offline?

The load balancer constantly sends periodic Health Check ping requests (e.g., HTTP /healthz endpoints or TCP heartbeats) to all registered backend servers.

  • Server Offline Detection: If a server fails to respond within a timeout window or returns error status codes, the load balancer automatically flags it as UNHEALTHY.
  • Traffic Rerouting: It immediately stops sending traffic to the failed server and reroutes incoming requests to remaining active servers.
  • Auto-Recovery: It continues background probing, and once the server becomes active and healthy again, it re-introduces it into the server pool automatically.