A production-grade Content Delivery Network (CDN) system featuring intelligent load balancing, real-time metrics monitoring with Prometheus, WebSocket-based live dashboards, and fully containerized Docker deployment.
- Distributed Architecture: Multi-server video streaming with automatic failover
- Intelligent Load Balancing: 4-tier weighted algorithm based on CPU, memory, request rate, concurrent streams, and response time
- Real-Time Monitoring: Prometheus metrics collection with 1-second granularity
- Live Dashboard: WebSocket-powered real-time visualization using Chart.js
- Containerized Deployment: Docker Compose orchestration for reproducible environments
- HTTP Range Support: Efficient partial content delivery for video streaming
- Per-Server Metrics: Individual throughput and resource tracking
┌─────────────┐
│ Clients │
└──────┬──────┘
│
┌──────▼──────────────┐
│ Load Balancer │◄──── Prometheus
│ (Port 80) │ (Port 9090)
└──────┬──────────────┘
│
├──────┬──────┬──────┐
▼ ▼ ▼ ▼
┌────┐ ┌────┐ ┌────┐ ┌────┐
│ S1 │ │ S2 │ │ S3 │ │ SN │
└────┘ └────┘ └────┘ └────┘
Video Servers (Port 8080)
- Python 3.9+
- Docker & Docker Compose
- 2GB+ RAM recommended
- Linux/macOS (or WSL on Windows)
# Clone the repository
git clone
cd cdn-streaming-platform
# Place your video file
cp /path/to/your/video.mp4 ./OrcaDocu.mp4
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Access services
# - Video Stream: http://localhost/
# - Dashboard: http://localhost/dashboard
# - Prometheus: http://localhost:9090
# - Metrics API: http://localhost/metrics# Update system
sudo apt update && sudo apt upgrade -y
# Install Python packages
pip3 install -r requirements.txt
# Or install individually
pip3 install fastapi uvicorn psutil prometheus-client websockets# On each server node (repeat for Server 1, 2, 3)
python3 video_server.py
# Or with uvicorn directly
uvicorn video_server:app --host 0.0.0.0 --port 8080Edit load_balancer.py and update server IPs:
servers = {
"server1-ip": "http://server1-ip:8080/OrcaDocu.mp4",
"server2-ip": "http://server2-ip:8080/OrcaDocu.mp4",
"server3-ip": "http://server3-ip:8080/OrcaDocu.mp4"
}Start the load balancer:
sudo uvicorn load_balancer:app --host 0.0.0.0 --port 80# Download Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
tar xvfz prometheus-2.45.0.linux-amd64.tar.gz
cd prometheus-2.45.0.linux-amd64/
# Start Prometheus
./prometheus --config.file=../prometheus.yml| Endpoint | Description |
|---|---|
http://localhost/ |
Video streaming endpoint |
http://localhost/dashboard |
Real-time metrics dashboard |
http://localhost/metrics |
JSON metrics API |
http://localhost/prometheus |
Prometheus metrics endpoint |
http://localhost:9090 |
Prometheus UI |
ws://localhost/ws |
WebSocket live metrics stream |
Global Metrics:
- Request rate (requests/min)
- Concurrent streams
- Bandwidth usage (Mbps)
- Average response time
- CPU & Memory utilization
Per-Server Metrics:
- Individual throughput (Mbps)
- Server load scores
- Resource utilization
- Request distribution
Adjust weights in load_balancer.py:
weights = {
"cpu": 0.30, # CPU usage weight
"mem": 0.25, # Memory usage weight
"req": 0.20, # Request rate weight
"streams": 0.15, # Concurrent streams weight
"resp": 0.10, # Response time weight
}Modify tier boundaries:
def sort_tier(score: float) -> str:
if score < 25: return "tier1" # Low load
elif score < 50: return "tier2" # Medium load
elif score < 75: return "tier3" # High load
else: return "tier4" # Critical loadChange dashboard refresh rate (default: 1 second):
# In load_balancer.py WebSocket endpoint
await asyncio.sleep(1) # Adjust interval here# Install Apache Bench
sudo apt install apache2-utils
# Test with 100 concurrent connections, 1000 requests
ab -n 1000 -c 100 http://localhost/
# Monitor in real-time via dashboard
open http://localhost/dashboard# Check load balancer
curl http://localhost/metrics
# Check individual servers
curl http://server1-ip:8080/metrics
curl http://server2-ip:8080/metrics
curl http://server3-ip:8080/metrics
# Check Prometheus targets
open http://localhost:9090/targetscdn-streaming-platform/
├── README.md
├── requirements.txt
├── docker-compose.yml
├── prometheus.yml
├── Dockerfile.loadbalancer
├── Dockerfile.videoserver
├── load_balancer.py
├── video_server.py
├── OrcaDocu.mp4
└── docs/
└── architecture.md
# Start services
docker-compose up -d
# Stop services
docker-compose down
# Rebuild after code changes
docker-compose up -d --build
# View logs
docker-compose logs -f [service_name]
# Scale video servers
docker-compose up -d --scale server=5
# Check service status
docker-compose ps