Bird
Raised Fist0
HLDsystem_design~10 mins

Load balancing algorithms (round robin, least connections) in HLD - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the next server using round robin.

HLD
next_server = servers[[1] % len(servers)]
Drag options to blanks, or click blank then click option'
Acurrent_index
Bserver_count
Crandom_index
Dmax_connections
Attempts:
3 left
💡 Hint
Common Mistakes
Using random index instead of cycling
Using max connections for round robin
2fill in blank
medium

Complete the code to find the server with the least connections.

HLD
least_loaded_server = min(servers, key=lambda s: s.[1])
Drag options to blanks, or click blank then click option'
Aload
Bcapacity
Cconnections
Dlatency
Attempts:
3 left
💡 Hint
Common Mistakes
Using load or capacity instead of connections
Using latency which is unrelated
3fill in blank
hard

Fix the error in the round robin index update.

HLD
current_index = (current_index [1] 1) % len(servers)
Drag options to blanks, or click blank then click option'
A/
B-
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction which moves backward
Using multiplication or division which is incorrect
4fill in blank
hard

Fill both blanks to create a dictionary of servers with their connection counts, filtering servers with less than 10 connections.

HLD
{server.id: server.[1] for server in servers if server.[2] < 10}
Drag options to blanks, or click blank then click option'
Aconnections
Bload
Dcapacity
Attempts:
3 left
💡 Hint
Common Mistakes
Using different attributes for mapping and filtering
Using load or capacity instead of connections
5fill in blank
hard

Fill all three blanks to implement a function that selects a server using least connections algorithm.

HLD
def select_server(servers):
    return min(servers, key=lambda [1]: [2].[3])
Drag options to blanks, or click blank then click option'
Aserver
Bs
Dconnections
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names
Accessing wrong attributes

Practice

(1/5)
1. Which load balancing algorithm sends requests to servers in a fixed, repeating order without considering current load?
easy
A. Round Robin
B. Least Connections
C. Random Selection
D. IP Hash

Solution

  1. Step 1: Understand Round Robin behavior

    Round Robin cycles through servers one by one in order, ignoring current load or connections.
  2. Step 2: Compare with other algorithms

    Least Connections considers active connections, Random Selection picks randomly, IP Hash uses client IP. Only Round Robin ignores load.
  3. Final Answer:

    Round Robin -> Option A
  4. Quick Check:

    Fixed order without load check = Round Robin [OK]
Hint: Round Robin cycles evenly, ignores load [OK]
Common Mistakes:
  • Confusing Least Connections with Round Robin
  • Thinking Random Selection is fixed order
  • Assuming IP Hash ignores load
2. Which of the following is the correct pseudocode snippet for implementing Round Robin load balancing?
easy
A. server = server with minimum active connections
B. server = hash(client_ip) % total_servers
C. server = random.choice(servers)
D. server = servers[(current_index + 1) % total_servers]

Solution

  1. Step 1: Identify Round Robin logic

    Round Robin selects the next server by incrementing an index and wrapping around using modulo.
  2. Step 2: Match pseudocode to logic

    server = servers[(current_index + 1) % total_servers] uses (current_index + 1) % total_servers, which correctly cycles through servers.
  3. Final Answer:

    server = servers[(current_index + 1) % total_servers] -> Option D
  4. Quick Check:

    Modulo cycling index = Round Robin [OK]
Hint: Round Robin uses modulo to cycle servers [OK]
Common Mistakes:
  • Choosing minimum connections for Round Robin
  • Using random selection syntax
  • Using hash function for Round Robin
3. Given 3 servers with active connections: Server A=5, Server B=2, Server C=4, which server will Least Connections algorithm select for the next request?
medium
A. Server B
B. Server C
C. Server A
D. Server A or Server C (tie)

Solution

  1. Step 1: Identify server with fewest active connections

    Server B has 2 connections, fewer than A (5) and C (4).
  2. Step 2: Apply Least Connections selection

    Least Connections chooses the server with the minimum active connections, so Server B is selected.
  3. Final Answer:

    Server B -> Option A
  4. Quick Check:

    Fewest connections = Server B [OK]
Hint: Least Connections picks server with minimum active connections [OK]
Common Mistakes:
  • Picking server with most connections
  • Choosing Round Robin instead of Least Connections
  • Confusing ties with multiple servers
4. A load balancer using Least Connections algorithm always sends requests to Server A, even though Server B has fewer active connections. What is the most likely cause?
medium
A. Round Robin algorithm is being used instead
B. The connection count for Server B is not updated correctly
C. Server A has a lower IP address
D. The load balancer is using random selection

Solution

  1. Step 1: Analyze behavior mismatch

    Least Connections should pick server with fewer active connections, but always picks Server A.
  2. Step 2: Identify likely cause

    If Server B's connection count is stale or incorrect, the balancer wrongly thinks Server A has fewer connections.
  3. Final Answer:

    The connection count for Server B is not updated correctly -> Option B
  4. Quick Check:

    Incorrect connection tracking causes wrong Least Connections choice [OK]
Hint: Check if connection counts update properly for Least Connections [OK]
Common Mistakes:
  • Assuming algorithm is Round Robin without checking
  • Thinking IP address affects Least Connections
  • Ignoring connection count accuracy
5. You have 4 servers with varying capacities and active connections: Server A (capacity 10, connections 5), Server B (capacity 20, connections 15), Server C (capacity 15, connections 10), Server D (capacity 10, connections 2). Which server should a capacity-aware Least Connections algorithm select to balance load best?
hard
A. Server C
B. Server B
C. Server D
D. Server A

Solution

  1. Step 1: Calculate load ratio (connections/capacity) for each server

    Server A: 5/10 = 0.5, Server B: 15/20 = 0.75, Server C: 10/15 ≈ 0.67, Server D: 2/10 = 0.2
  2. Step 2: Select server with lowest load ratio

    Server D has the lowest ratio (0.2), so it is selected in capacity-aware Least Connections.
  3. Final Answer:

    Server D -> Option C
  4. Quick Check:

    Lowest load ratio = Server D [OK]
Hint: Consider connections relative to capacity, not just counts [OK]
Common Mistakes:
  • Picking server with fewest connections ignoring capacity
  • Ignoring capacity differences
  • Choosing server with lowest absolute connections only
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard