A production-ready Django-based WebSocket service with zero-downtime blue/green Docker Compose deployment, observability, and health checks.
-
Blue/Green Deployment via Docker Compose (nginx reverse proxy with
app_blue
andapp_green
services) -
WebSocket Endpoint at
/ws/chat/
powered by Uvicorn + Django Channels -
Observability with Prometheus metrics (
/metrics
) and Grafana dashboards -
Health Checks:
/healthz
(liveness) and/readyz
(readiness) -
Automation Scripts:
scripts/promote.sh
: Flip traffic from blue to greenscripts/monitor.sh
: Tail logs for errors and print topโ5 Prometheus counters every 10โฏsscripts/ws_test.js
: k6 load test script for WebSocket performance
- Docker >= 27.0.0
- Docker Compose >= 2.29.0
git clone git@github.com:prxssh/prod-websocket-service && cd prod-websocket-service
This command first spins up the required prerequisites for the application (Grafana, dashboards, k6, nginx) and then starts both app_blue and app_green services.
docker-compose --env-file dev.env -f docker/compose.yml up -d
- WebSocket:
ws://localhost:80/ws/chat/?session=<uid>
- Liveness:
http://localhost:80/healthz
- Readiness:
http://localhost:80/readyz
- Metrics:
http://localhost:80/metrics
- Grafana:
http://localhost:3000
(default credentialsadmin/admin
)
To flip traffic from the current color to the standby color:
./scripts/promote.sh
This script will:
- Build and start the next color stack
- Run smoke tests against
/healthz
- Update nginx to route traffic
- Tear down the old color stack
Tail real-time logs for errors and see topโ5 Prometheus counters:
./scripts/monitor.sh
By default, Docker Compose will run the k6 load test automatically when the application starts, writing results to k6-results/ (or you can view them via the k6 container logs).
To run the load test manually, execute:
k6 run scripts/ws_test.js
- See DESIGN.md for concurrency and deployment rationale
- See OBSERVABILITY.md for Prometheus/Grafana setup