← ProjectsDocker · NGINX · Redis

Building a multi-container counter application

A Docker Compose stack combining NGINX, multiple web containers and Redis-backed shared state.

DockerComposeNGINXRedisFlask
01 — Overview

What I built.

The project demonstrates how a small application can scale horizontally while keeping shared state consistent. Docker Compose runs NGINX, three interchangeable web containers and Redis. NGINX provides the single entry point, the web service can be scaled independently, and Redis stores the counter so requests do not depend on which application container handles them.

3Scaled web containers
NGINXReverse proxy entry point
RedisShared counter state
5050Application entry port
02 — Architecture

How the stack fits together.

Architecture & runtime flow

Application architecture

Switch between request handling and the Compose service structure.

03 — Implementation

How it was implemented.

  1. 01Containerised the web application and Redis service.
  2. 02Added NGINX as the entry point and reverse proxy for the web service.
  3. 03Scaled the web service to three containers to demonstrate horizontal distribution.
  4. 04Used Redis as shared state so the counter was not tied to one application container.
  5. 05Exposed the application through port 5050 and tested the counter endpoint.
docker · nginx · redis
04 — Troubleshooting

Issues resolved.

01Compose networking

Services could not rely on host-style addressing

ProblemContainers communicate through the Compose network, so service names and internal ports must be correct.

FixUsed the Compose service names and container-facing ports consistently between NGINX, the web service and Redis.

02Shared state

Scaling the web layer could not duplicate state

ProblemKeeping the counter inside one web container would make results depend on which replica received the request.

FixMoved the counter to Redis so all three web containers use the same shared state.

03Traffic routing

The scaled containers needed one entry point

ProblemClients should not need to know about individual application containers.

FixPlaced NGINX in front of the web service and routed external requests through the proxy.

Outcome.

Requests could be distributed through NGINX while all three web containers used the same Redis-backed counter state. The project demonstrated the separation between routing, application replicas and shared data inside a Docker Compose network.