Bird
Raised Fist0
Nginxdevops~20 mins

Weighted round-robin in Nginx - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Weighted Round-Robin Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Weighted Round-Robin in NGINX

What does the weight parameter do in an NGINX upstream block using weighted round-robin?

AIt defines the timeout duration for requests to a server.
BIt sets the maximum number of simultaneous connections allowed to a server.
CIt assigns a relative load share to each server, so servers with higher weights receive more requests.
DIt specifies the priority order in which servers are tried sequentially.
Attempts:
2 left
💡 Hint

Think about how NGINX balances traffic among servers with different capacities.

❓ Configuration
intermediate
2:00remaining
Identify the Correct Weighted Round-Robin Configuration

Which NGINX upstream configuration correctly implements weighted round-robin with server1 receiving twice the traffic of server2?

A
upstream backend {
    server server1.example.com weight=2;
    server server2.example.com weight=1;
}
B
upstream backend {
    server server1.example.com weight=1;
    server server2.example.com weight=2;
}
C
upstream backend {
    server server1.example.com max_fails=2;
    server server2.example.com max_fails=1;
}
D
upstream backend {
    server server1.example.com;
    server server2.example.com;
}
Attempts:
2 left
💡 Hint

Look for the weight values assigned to each server.

💻 Command Output
advanced
2:00remaining
Output of NGINX Weighted Round-Robin Load Distribution

Given this upstream configuration:

upstream backend {
    server 10.0.0.1 weight=3;
    server 10.0.0.2 weight=1;
}

After 8 requests, how many requests will each server have received?

A10.0.0.1: 3 requests, 10.0.0.2: 5 requests
B10.0.0.1: 6 requests, 10.0.0.2: 2 requests
C10.0.0.1: 4 requests, 10.0.0.2: 4 requests
D10.0.0.1: 8 requests, 10.0.0.2: 0 requests
Attempts:
2 left
💡 Hint

Calculate requests proportional to weights: 3 parts vs 1 part.

❓ Troubleshoot
advanced
1:30remaining
Troubleshooting Weighted Round-Robin Misconfiguration

An NGINX server block uses weighted round-robin, but traffic is not distributed according to weights. Which misconfiguration is most likely causing this?

AAll servers have the same weight value or no weight specified.
BThe <code>max_fails</code> parameter is set too high.
CThe <code>keepalive</code> directive is missing.
DThe <code>proxy_pass</code> directive is outside the server block.
Attempts:
2 left
💡 Hint

Check if weights differ between servers.

✅ Best Practice
expert
2:30remaining
Best Practice for Weighted Round-Robin with Dynamic Server Health

In a weighted round-robin setup, what is the best practice to ensure traffic is not sent to unhealthy servers while maintaining weight distribution?

ASet all server weights to zero when a server is unhealthy.
BManually remove unhealthy servers from the upstream block and reload NGINX configuration.
CDisable weighted round-robin and use simple round-robin instead.
DUse <code>max_fails</code> and <code>fail_timeout</code> to mark servers as down and exclude them from load balancing temporarily.
Attempts:
2 left
💡 Hint

Consider automatic health checks and failover mechanisms.

Practice

(1/5)
1. What does the weight parameter control in nginx's weighted round-robin load balancing?
easy
A. The maximum number of connections a server can handle
B. The timeout duration for server responses
C. The order in which servers are listed in the config
D. The number of requests sent to a server relative to others

Solution

  1. Step 1: Understand the role of weight in load balancing

    The weight defines how many requests a server receives compared to others.
  2. Step 2: Relate weight to request distribution

    Higher weight means more requests go to that server, balancing load by capacity.
  3. Final Answer:

    The number of requests sent to a server relative to others -> Option D
  4. Quick Check:

    Weight controls request share [OK]
Hint: Weight sets request share per server [OK]
Common Mistakes:
  • Confusing weight with timeout
  • Thinking weight limits connections
  • Assuming weight sets server order
2. Which of the following is the correct syntax to assign weights to servers in nginx for weighted round-robin?
easy
A. server backend1.example.com weight:3;
B. server backend1.example.com weight 3;
C. server backend1.example.com weight=3;
D. server backend1.example.com weight(3);

Solution

  1. Step 1: Recall nginx upstream server syntax

    Weights are assigned using weight=number with an equal sign and semicolon.
  2. Step 2: Check each option's syntax

    Only server backend1.example.com weight=3; uses the correct weight=3; format.
  3. Final Answer:

    server backend1.example.com weight=3; -> Option C
  4. Quick Check:

    Correct syntax uses equal sign and semicolon [OK]
Hint: Use weight=number; syntax for servers [OK]
Common Mistakes:
  • Omitting equal sign
  • Using colon instead of equal sign
  • Using parentheses incorrectly
3. Given this nginx upstream block:
upstream backend {
  server backend1.example.com weight=3;
  server backend2.example.com weight=1;
}
If 8 requests arrive, how many requests will backend2 receive approximately?
medium
A. 2
B. 6
C. 4
D. 1

Solution

  1. Step 1: Calculate total weight

    backend1 weight=3, backend2 weight=1, total = 4.
  2. Step 2: Calculate requests for backend2

    Requests for backend2 = (1/4) * 8 = 2.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    Requests proportional to weight [OK]
Hint: Requests split by weight ratio [OK]
Common Mistakes:
  • Ignoring total weight sum
  • Assigning equal requests despite weights
  • Miscounting total requests
4. You configured nginx with weighted round-robin but all servers receive equal requests. What is the most likely cause?
medium
A. nginx does not support weighted round-robin
B. Weights were not specified correctly in the config
C. The servers have identical IP addresses
D. The upstream block is missing the weight directive

Solution

  1. Step 1: Understand weighted round-robin requires correct weight syntax

    If weights are missing or incorrect, nginx defaults to equal distribution.
  2. Step 2: Analyze the options

    Weights were not specified correctly in the config states weights not specified correctly, which explains equal requests.
  3. Final Answer:

    Weights were not specified correctly in the config -> Option B
  4. Quick Check:

    Incorrect weights cause equal load [OK]
Hint: Check weight syntax if load is equal [OK]
Common Mistakes:
  • Assuming nginx lacks weighted support
  • Confusing IP issues with load balancing
  • Missing weight directive entirely
5. You have three servers with weights 5, 3, and 2. You want to add a fourth server but keep the total weight sum at 10. What weight should you assign to the new server to maintain the same total weight and keep the relative proportions of the first three servers?
hard
A. 0 (do not add the server)
B. 5
C. 2
D. 1

Solution

  1. Step 1: Calculate current total weight

    Sum of existing weights = 5 + 3 + 2 = 10.
  2. Step 2: Determine weight for new server

    To keep total sum at 10 when adding a fourth server, assign weight=0 to it.
  3. Step 3: Verify proportions

    Weight=0 means no requests to the new server, so first three retain exact proportions (5:3:2 out of total 10).
  4. Final Answer:

    0 (do not add the server) -> Option A
  5. Quick Check:

    Weight=0 keeps total and proportions unchanged [OK]
Hint: Assign weight=0 to keep total sum and proportions [OK]
Common Mistakes:
  • Assigning positive weight that increases total sum
  • Forgetting to maintain exact total of 10
  • Ignoring impact on relative proportions
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