How would you design your load balancing algorithm? Go!

Google for DevelopersAbout 3 min readJun 24, 2025Watch original
THE SUMMARYAI-generated

Key Concepts:

  • Load Balancing: Distributing incoming network traffic across multiple servers to prevent overload and ensure optimal resource utilization.
  • Proportional Distribution: Allocating traffic to servers based on their processing capacity.
  • Random Number Generator: Using a random number generator (1-100) to make load balancing decisions.
  • Server Capacity: The number of requests per second a server can handle (Server A: 10, Server B: 15, Server C: 20, Server D: 25, Server E: 30).

Load Balancing Algorithm Design

The challenge is to design a load balancing algorithm that distributes incoming traffic across five servers (A, B, C, D, and E) with varying processing capacities (10, 15, 20, 25, and 30 requests per second, respectively), using only a random number generator that produces integers from 1 to 100. The goal is to ensure that each server handles requests proportionally to its capacity.

Step-by-Step Approach

  1. Calculate Total Capacity: Determine the total processing capacity of all servers.

    • Total Capacity = 10 (A) + 15 (B) + 20 (C) + 25 (D) + 30 (E) = 100 requests per second.
  2. Determine Proportional Ranges: Assign a range of numbers (1-100) to each server based on its proportional capacity.

    • Server A: 1-10 (10% of total capacity)
    • Server B: 11-25 (15% of total capacity)
    • Server C: 26-45 (20% of total capacity)
    • Server D: 46-70 (25% of total capacity)
    • Server E: 71-100 (30% of total capacity)
  3. Random Number Generation: For each incoming request, generate a random number between 1 and 100.

  4. Server Selection: Based on the generated random number, route the request to the corresponding server.

    • If the random number is between 1 and 10, route the request to Server A.
    • If the random number is between 11 and 25, route the request to Server B.
    • If the random number is between 26 and 45, route the request to Server C.
    • If the random number is between 46 and 70, route the request to Server D.
    • If the random number is between 71 and 100, route the request to Server E.

Efficiency for Large-Scale Systems

  • Computational Complexity: The algorithm has a low computational complexity (O(1)) because it involves generating a random number and performing a simple range check. This makes it efficient for large-scale systems with high traffic volumes.
  • Scalability: The algorithm can be easily scaled by adding or removing servers. The proportional ranges need to be recalculated based on the new total capacity.
  • Lookup Table: For improved performance, the proportional ranges can be stored in a lookup table or an array. This eliminates the need for multiple conditional checks for each request.

Example

Suppose a random number of 62 is generated. According to the proportional ranges, the request would be routed to Server D (46-70).

Conclusion

The proposed load balancing algorithm effectively distributes incoming traffic across servers based on their processing capacities using a random number generator. Its simplicity and low computational complexity make it suitable for large-scale systems. The key is to accurately calculate the proportional ranges and efficiently map the random numbers to the corresponding servers.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.