Skip to content

RobinsonLaw/scalable-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐳 Scalable Docker API (Flask + NGINX + Compose)

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.


πŸ“ Project Structure

.
β”œβ”€β”€ app.py              # Flask API returning hostname
β”œβ”€β”€ Dockerfile          # Containerizes the app
β”œβ”€β”€ nginx.conf          # Load balances across API containers
└── docker-compose.yml  # Defines and scales services

πŸš€ Quick Start

  1. Clone or create this project

    git clone https://github.com/your-username/scalable-api.git
    cd scalable-api
  2. Start it up and scale

    docker compose up --build --scale api=3 -d
  3. Visit your API Open your browser at: http://localhost:8080
    Refresh a few times β€” each response should show a different container hostname.


🧠 How It Works

  • The Flask api service 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.

βš™οΈ Commands

Scale up/down the number of containers:

docker compose up --scale api=5 -d

Stop and remove everything:

docker compose down

🚧 Possible Next Steps

  • Add automatic CPU-based scaling
  • Add monitoring with Prometheus + Grafana
  • Deploy on Kubernetes for production-ready orchestration

Made with 🧠 & 🐳 by RobinsonLaw

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages