#🧱 Building Block: Load Balancer
#Overview
A Load Balancer (LB) distributes incoming network traffic across a group of backend servers, also known as a server farm or server pool.
#Key Concepts
- L4 Load Balancing: Operates at the transport layer (TCP/UDP). Faster but lacks content awareness.
- L7 Load Balancing: Operates at the application layer (HTTP/HTTPS). Can route based on URL path, headers, or cookies.
- Health Checks: Periodically checking if backend servers are responsive before sending traffic.
#Algorithms
- Round Robin: Distributes requests sequentially.
- Least Connections: Sends requests to the server with the fewest active connections.
- IP Hash: Uses the client's IP address to determine which server receives the request (session persistence).
- Consistent Hashing: Minimizes disruption when servers are added or removed.
#When to Use
- Scalability: When a single server cannot handle the traffic.
- High Availability: To ensure service continues even if some servers fail.
#Trade-offs
- Pros: Increases capacity, improves reliability, enables zero-downtime deployments.
- Cons: Becomes a single point of failure (unless configured in high-availability mode), adds latency.