A simple microservices architecture demonstration with three services: a User Management API, a Data Ingestion Simulator, and a Frontend Dashboard.
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Data Ingestion │───▶│ User API │◀───│ Frontend │
│ Simulator │ │ (FastAPI) │ │ (Streamlit) │
│ (Faker + HTTP) │ │ │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
Creates fake Stores users Visualizes
users every in memory as age distribution
few seconds (name, age) tuples as histogram
- Technology: FastAPI
- Port: 8000
- Purpose: RESTful API for user CRUD operations
- Features: Create, read, update, delete users with health checks
- Technology: Python + Faker
- Purpose: Generates and sends fake user data to the API
- Features: Configurable intervals, realistic fake data, error handling
- Technology: Streamlit
- Port: 8501
- Purpose: Web interface to visualize user age distribution
- Features: Interactive histogram, real-time data fetching, statistics
- Python 3.8+
- pip
cd api
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
fastapi dev main.py
# API available at http://localhost:8000cd data_ingestion_simulator
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python main.pycd frontend
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
streamlit run app.py
# Frontend available at http://localhost:8501docker network create microservicesdocker build -t user-api ./api
docker build -t data-simulator ./data_ingestion_simulator
docker build -t frontend-app ./frontenddocker run \
--name api0 \
--network microservices \
-p 8000:8000 \
user-apidocker run \
--name sim0 \
--network microservices \
-e API_BASE_URL=http://api0:8000 \
-e SIMULATION_INTERVAL=5 \
data-simulatordocker run \
--name frontend0 \
--network microservices \
-p 8501:8501 \
-e API_URL=http://api:8000/users/ \
frontend-app# Check running containers
docker ps
# View logs
docker logs api0
docker logs sim0
docker logs frontend0The easiest way to run all services together:
# Clone the repository
git clone <repository-url>
cd ce290i-microservices
# Start all services
docker-compose up --build
# Access the services
# - API Documentation: http://localhost:8000/docs
# - Frontend Dashboard: http://localhost:8501Access the interactive API documentation at: http://localhost:8000/docs
GET /health- Health checkPOST /users/- Create user (params: user_id, name, age)GET /users/{user_id}- Get specific userGET /users/- Get all usersPUT /users/{user_id}- Update user (params: name, age)DELETE /users/{user_id}- Delete user
# Create a user
curl -X POST "http://localhost:8000/users/?user_id=123&name=Alice&age=30"
# Get a user
curl "http://localhost:8000/users/123"
# Get all users
curl "http://localhost:8000/users/"
# Update a user
curl -X PUT "http://localhost:8000/users/123?name=Alice%20Johnson&age=31"
# Delete a user
curl -X DELETE "http://localhost:8000/users/123"| Service | Variable | Default | Description |
|---|---|---|---|
| Data Simulator | API_BASE_URL |
http://localhost:8000 |
API base URL |
| Data Simulator | SIMULATION_INTERVAL |
5 |
Seconds between requests |
| Frontend | API_URL |
http://localhost:8000/users/ |
Full API endpoint URL |
docker-compose down# Stop containers
docker stop api0 sim0 frontend0
# Remove containers
docker rm api0 sim0 frontend0
# Remove network
docker network rm microservices
# Remove images (optional)
docker rmi user-api data-simulator frontend-appThis project demonstrates:
- Microservices Architecture: Independent, loosely coupled services
- API Design: RESTful API with proper HTTP methods
- Service Communication: HTTP-based inter-service communication
- Containerization: Docker for consistent deployment
- Service Discovery: Docker networking for service-to-service communication
- Data Visualization: Real-time data processing and visualization
- Development vs Production: Different deployment strategies
To understand how Docker provides isolation and see the effects of Dockerfile commands, you can inspect running containers:
# List running containers
docker ps
# Get detailed container information
docker inspect api0
# Check container resource usage
docker stats api0# Execute interactive shell inside the API container
docker exec -it api0 /bin/bash
# Or use sh if bash is not available
docker exec -it api0 /bin/shOnce inside the container, you can explore the filesystem and see how Dockerfile commands affected the environment:
# Check current working directory (set by WORKDIR in Dockerfile)
pwd
# Should show: /app
# List files in the working directory
ls -la
# You'll see: main.py, crud.py, requirements.txt, __pycache__/
# Check Python packages installed by pip install
pip list
# Explore the container's filesystem
ls /
# See root filesystem: bin, etc, usr, var, app, etc.
# Check environment variables
env | grep -i python
# See which Python executable is being used
which python
which fastapi
# Check the container's network configuration
cat /etc/hosts
# You'll see container hostname and network mappings
# Check running processes inside the container
ps aux# Exit the container
exit
# Compare with host system
ls -la ./api/
# Same files but in host filesystem
# Check host Python environment (likely different)
pip list # Your host packages
# Check host network
ifconfig # Different network interfaces# View the image layers and history
docker history user-api
# See what each Dockerfile command created
docker image inspect user-api# View container logs
docker logs api0
# Follow logs in real-time
docker logs -f api0
# Check container processes from host
docker top api0# Create a file inside the container
docker exec api0 touch /app/test-file.txt
# Check if file exists on host
ls ./api/test-file.txt # File doesn't exist on host!
# The container filesystem is isolated from the host
docker exec api0 ls /app/ # File exists in container# Check container's internal IP
docker exec api0 hostname -I
# Check container's view of network
docker exec api0 cat /etc/hosts
# Container has its own network namespace
# but can communicate through Docker networks- Filesystem Isolation: Files created/modified inside containers don't affect the host
- Process Isolation: Container processes are separate from host processes
- Network Isolation: Each container has its own network interface
- Environment Isolation: Different Python environments, packages, and configurations
- Resource Isolation: Containers have their own CPU, memory limits (if set)
This demonstrates how Docker provides operating system-level virtualization without the overhead of full virtual machines.
- Backend: FastAPI (Python)
- Data Generation: Faker (Python)
- Frontend: Streamlit (Python)
- Containerization: Docker
- Orchestration: Docker Compose
- Networking: Docker Bridge Networks
- Data Storage: In-memory (educational purposes)