πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
NEWSLIVESearch All Content
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Load Balancing

InfrastructureTraffic Distribution🟒 Free Lesson

System Design β€” Infrastructure

Load Balancing

Load balancing distributes incoming traffic across multiple servers to ensure high availability, reliability, and optimal resource utilization. It's one of the most critical components in any scalable system.

  • Algorithms β€” Round-robin, least connections, consistent hashing
  • L4 vs L7 β€” Transport vs application layer balancing
  • Health Checks β€” Detecting and removing unhealthy servers

If you have more than one server, you need a load balancer.

What Is Load Balancing?

Load Balancer Placement

ClientsDNS LBGlobal LB (GSLB)L7 LB (US-East)L7 LB (EU-West)Srv 1Srv 2Srv 3Srv 4Multi-tier load balancing: DNS β†’ Global LB β†’ Regional L7 LB β†’ Servers

Load Balancing Algorithms

Round Robin

Distributes requests sequentially across servers.

Pros: Simple, even distribution for uniform workloads Cons: Ignores server capacity and current load

Weighted Round Robin

Assigns weights proportional to server capacity.

Least Connections

Routes to the server with fewest active connections.

Pros: Adapts to varying request durations Cons: Requires tracking connection state, doesn't account for connection weight

Consistent Hashing

Maps servers and requests to a hash ring, minimizing redistribution when servers are added or removed.

S1 (0Β°)S2 (90Β°)S3 (180Β°)S4 (270Β°)Each request walks clockwise to the first server node

Pros: Minimal redistribution on scaling, works well with caches Cons: May be uneven without virtual nodes

Least Response Time

Routes to the server with the lowest average response time and fewest active connections.

L4 vs L7 Load Balancing

FeatureL4L7
OSI LayerTransport (TCP/UDP)Application (HTTP)
Routing basisIP, portURL, headers, cookies
ThroughputHigher (no payload inspection)Lower (full inspection)
SSL terminationCan terminateTypically terminates
Content-based routingNoYes (URL, header)
WebSocket supportYes (pass-through)Yes (with upgrade)
Use caseHigh-throughput, simple routingContent routing, SSL offload

Health Checks

Load balancers must detect and remove unhealthy servers.

Health Check Types

TypeDescriptionGranularity
TCPCan establish TCP connectionPort-level
HTTPHTTP 200 response from health endpointApplication-level
gRPCgRPC health check protocolService-level
CustomApplication-specific checkBusiness-level

Health Check Configuration

Architecture Diagram
Health Check Parameters:
- Interval: 10 seconds (how often to check)
- Timeout: 5 seconds (max wait per check)
- Healthy threshold: 2 (consecutive successes to mark healthy)
- Unhealthy threshold: 3 (consecutive failures to mark unhealthy)

Global Server Load Balancing (GSLB)

For multi-region deployments, GSLB distributes traffic across data centers.

GSLB Strategies

StrategyHow It Works
GeoDNSResolves to nearest data center by IP geolocation
AnycastMultiple data centers share same IP; BGP routes to nearest
Latency-basedRoutes to data center with lowest measured latency
WeightedDistributes traffic by configurable weights

Practice Exercises

  1. Design: Design a load balancing strategy for a real-time gaming platform with 100M concurrent users. Consider: sticky sessions, geographic distribution, failover, and latency requirements.

  2. Algorithm Selection: You have 5 servers with different capacities (2x, 1x, 1x, 1x, 0.5x). Which load balancing algorithm would you use? How would you configure it?

  3. Architecture: Compare L4 and L7 load balancing for: (a) a TCP-based database proxy, (b) an API gateway with content-based routing, (c) a WebSocket chat service.

  4. Troubleshooting: A load balancer is distributing traffic unevenlyβ€”server 1 gets 40% while others get 20% each. What could cause this? How would you diagnose and fix it?


What to Learn Next

-> Message Queues Kafka, RabbitMQ, event-driven architecture.

-> Microservices Service decomposition, discovery, and API gateways.

-> CAP Theorem Consistency models, availability, and partition tolerance.

-> Scalability Fundamentals Vertical vs horizontal scaling and capacity planning.

-> Databases SQL vs NoSQL, indexing, replication, and sharding.

-> API Design REST, GraphQL, gRPC, versioning, and rate limiting.


Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type β€” Always start by categorizing the problem
  2. Incorrect formula application β€” Verify the formula applies to your specific case
  3. Unit errors β€” Always check units are consistent throughout
  4. Sign errors β€” Pay careful attention to positive and negative values
  5. Rounding too early β€” Keep full precision until the final answer
  6. Forgetting constraints β€” Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

β€”
β˜†β˜†β˜†β˜†β˜†
0 ratings

Rate & Feedback

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement