Prepare for infrastructure interviews with 25+ questions on load balancing algorithms, patterns, and best practices.
Round Robin: sequential distribution, simple. Weighted Round Robin: server capacity considered. Least Connections: send to server with fewest active connections. IP Hash: consistent mapping based on client IP (session affinity). Least Response Time: fastest server gets request. Random: simple, effective at scale. Choose based on workload characteristics.
L4 (Transport layer): routes based on IP and port, faster, no content inspection. L7 (Application layer): routes based on content (URL, headers, cookies), more flexible, can do SSL termination, caching. L4 for: TCP/UDP traffic, maximum performance. L7 for: HTTP routing, content-based decisions, API gateway features.
Health checks verify backend availability. Types: TCP (port open), HTTP (status code), custom scripts. Parameters: interval, timeout, threshold (unhealthy after N failures). Remove unhealthy servers from pool, add back when healthy. Implement: /health endpoint checking dependencies. Avoid: checks that overwhelm backends.
Methods: (1) Cookie-based (LB sets cookie with server ID), (2) IP hash (same IP to same server), (3) Application-managed sessions (externalize to Redis). Trade-offs: sticky sessions simpler but uneven distribution, server failure loses sessions. Prefer: stateless design with external session store. Sticky sessions as last resort.
GSLB: distribute traffic across geographically distributed data centers. Uses DNS to route users to nearest/healthiest DC. Features: geographic routing, latency-based routing, failover, health monitoring. Implementations: AWS Route 53, Cloudflare, Akamai. Consider: DNS caching (TTL), failover time, multi-region architecture complexity.
Practice with interactive quizzes and get instant feedback.
Start Free Practice