all work
shipped[2024]7

Load Balancer Lab

Nginx and Docker load balancing. Round robin, sticky sessions, health checks.

Problem

Understanding load balancing internals by implementing and breaking it, not just configuring it.

Built

Practical LB implementation and experiments: round-robin, IP hash, least connections, upstream health checks, zero-downtime deploys with Nginx + Docker Compose.

round-robin

LB

sticky

sessions

health

check failover

upstream

scaling experiments

The build

[Idea]

This was a 'learn by breaking things' project. I wanted to actually understand load balancing, not just configure Nginx once and move on, but watch the behavior, push traffic at it, and see what happens.

[Framing]

The setup is a Docker Compose stack with Nginx as the reverse proxy and load balancer, multiple upstream containers behind it, and a /app/test route that returns a server-specific response, so I can visually confirm which upstream handled a given request. The two strategies I demonstrated first were plain Round Robin (default Nginx upstream balancing, even distribution across upstreams) and Weighted Round Robin (per-server weight directives, three servers at 3:2:1 distribution).

[Build]

The make docker-up command creates the Docker network first, then brings up the whole stack. The network-first ordering matters because Nginx needs to resolve upstream hostnames at boot, not at first request. The manual mode, running each make command one by one, is the version I'd recommend for actually learning. You see each container come up in order and can verify the routing at each step. Animated GIFs in the README show the round-robin and weighted behavior.

[Deploy]

The original plan was to extend this into AWS-based load balancing (the project title says 'Docker as well as AWS and Other Experiments'), but I never got back to it. If I revive it, I'd add sticky-session experiments with cookie-based affinity, health-check failover, and a comparison page between Nginx, HAProxy, and Traefik on the same workload. The pattern of 'compose Nginx with upstreams and verify with a /test endpoint' is one I now reach for any time I want to understand how a load balancer actually behaves.

Stack

2 techs · grouped by layer

Infrastructure

  • Docker
  • Nginx

Also used

Docker ComposeShell scripting

Links

Related stack

techs used in Load Balancer Lab