The Desi Architect
Notes / Docker Sandboxes / Nginx Load Balancer: Round-Robin, Least-Connections & Failover
Docker Sandboxes · Tier 1: Building Blocks · Lab 11

Nginx Load Balancer: Round-Robin, Least-Connections & Failover

One server is not enough, so you run three and put nginx in front. See round-robin deal requests like cards, watch a slow node drag everything down and least_conn route around it, stop a node and see nothing fail, bring it back, and give a bigger server a bigger share.

Time40 minutes
Stacknginx 1.27Ports 18080
MemoryAbout 40 MB
Before thisLab 02Docker Compose in Practice
Verified runWindows, Mac, LinuxBash and PowerShell
  1. 1PrepareWhat you will learn
  2. 2PredictGuess before you run
  3. 3RunStep by step
  4. 4ObserveWhat you should see
  5. 5Break itChange one thing
  6. 6Clean upLeave nothing running
On this page
  1. 00 / What You Will Learn
  2. 01 / Why It Matters
  3. 02 / What We Are Building
  4. 03 / Words You Need
  5. 04 / Predict First
  6. 05 / Step by Step
  7. 06 / What You Should See
  8. 07 / Look Inside
  9. 08 / Break It, Fix It
  10. 09 / In Real Projects
  11. 10 / Interview Corner
  12. 11 / Clean Up

00 /What You Will Learn

By the end you will be able to
  • Say what a load balancer does and what upstream means.
  • Compare round-robin, least_conn and weighted balancing, with real numbers.
  • Show how one slow node hurts round-robin and how least_conn avoids it.
  • Explain passive health checks: max_fails, fail_timeout and proxy_next_upstream, and what a failure costs a customer.
  • Say what a zone is for.

Before you start

Finish Lab 10 (Nginx Basics) first. You should be able to read a location block and know what nginx -s reload does. Docker Desktop must be running.