A small Go (Gin) web API backed by MongoDB, orchestrated with Docker Compose and scaled behind an haproxy load balancer.
The full briefs and explanations live in docs/:
This README only lists what to run to make each part work.
- Docker (with Compose v2)
cp .env.example .env| Variable | Meaning | Default |
|---|---|---|
MONGODB_HOST |
MongoDB hostname | db |
MONGODB_PORT |
MongoDB port | 27017 |
Start the stack (app + MongoDB):
docker compose up --buildTest:
curl http://localhost:5000/ping # {"message":"pong"}docker compose watchEdit main.go line 57 (the pong message), save, then curl again to see the
new response. Compose rebuilds the app automatically.
Requires haproxy.cfg (at the repo root) and the lb service in compose.yml.
Start with 3 app replicas + haproxy:
docker compose up -d --scale app=3Test through the load balancer:
curl http://localhost:5000/ping # {"message":"pong"}Check the traffic is spread across the 3 replicas:
for i in $(seq 1 12); do curl -s http://localhost:5000/ping > /dev/null; done
for c in 1 2 3; do
echo "app-$c: $(docker logs simplon-compose-tp-app-$c 2>&1 | grep -c '"/ping"')"
doneCounts should be roughly equal (e.g. 7 / 7 / 7).
Connection reset by peer: thelbcontainer is down. Checkdocker compose logs lb.Missing LF on last line:haproxy.cfgmust end with a newline, or haproxy refuses to start.
docker compose down