Skip to content

prxssh/websocket-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

21 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Django WebSocket Blue/Green Deployment

A production-ready Django-based WebSocket service with zero-downtime blue/green Docker Compose deployment, observability, and health checks.

Grafana Dashboard

๐Ÿš€ Features

  • Blue/Green Deployment via Docker Compose (nginx reverse proxy with app_blue and app_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 green
    • scripts/monitor.sh: Tail logs for errors and print topโ€‘5 Prometheus counters every 10โ€ฏs
    • scripts/ws_test.js: k6 load test script for WebSocket performance

โš™๏ธ Prerequisites

  • Docker >= 27.0.0
  • Docker Compose >= 2.29.0

๐Ÿ› ๏ธ Quick Start

1. Clone the repository

git clone git@github.com:prxssh/prod-websocket-service && cd prod-websocket-service

2. Build and start the full stack

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

3. Verify Services

  • 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 credentials admin/admin)

โšก Blue/Green Deployment

To flip traffic from the current color to the standby color:

./scripts/promote.sh

This script will:

  1. Build and start the next color stack
  2. Run smoke tests against /healthz
  3. Update nginx to route traffic
  4. Tear down the old color stack

๐Ÿ“Š Monitoring

Tail real-time logs for errors and see topโ€‘5 Prometheus counters:

./scripts/monitor.sh

๐Ÿ’ฅ Load Testing

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

๐Ÿ“š Further Reading

About

websocket service with alerting, observability, blue-green deployments, and monitoring ๐Ÿš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published