This is a simple horizontally-scalable API demo using Docker Compose, Flask, and NGINX.
Each API container responds with its own hostname, so you can see which container handled each request β perfect for understanding how container scaling and load balancing works locally.
.
βββ app.py # Flask API returning hostname
βββ Dockerfile # Containerizes the app
βββ nginx.conf # Load balances across API containers
βββ docker-compose.yml # Defines and scales services
-
Clone or create this project
git clone https://github.com/your-username/scalable-api.git cd scalable-api -
Start it up and scale
docker compose up --build --scale api=3 -d
-
Visit your API Open your browser at: http://localhost:8080
Refresh a few times β each response should show a different container hostname.
- The Flask
apiservice runs in multiple containers. - NGINX receives all incoming traffic and forwards it to a randomly selected container.
- Docker Compose handles building, scaling, and networking between services.
Scale up/down the number of containers:
docker compose up --scale api=5 -dStop and remove everything:
docker compose down- Add automatic CPU-based scaling
- Add monitoring with Prometheus + Grafana
- Deploy on Kubernetes for production-ready orchestration
Made with π§ & π³ by RobinsonLaw