Zero-Downtime Deploys with Traefik on a t4g.micro
Most blue-green deployment guides assume you have a load balancer and multiple servers. Here’s how MealPal does it on a single t4g.micro with Traefik.
The Problem
Section titled “The Problem”Traditional deployments have a brief downtime window when the old container stops and the new one starts. For an app with streaming chat (SSE), even a few seconds of downtime means dropped connections and a bad user experience.
The Solution: Traefik as a Local Load Balancer
Section titled “The Solution: Traefik as a Local Load Balancer”Traefik runs as a reverse proxy in Docker Compose, watching container labels for routing rules. The deploy script:
- Determines which slot is active (blue or green)
- Starts the new container in the inactive slot
- Waits for the health check to pass
- Updates Traefik labels to route traffic to the new container
- Gracefully stops the old container
# Simplified deploy logicif is_active "blue"; then deploy_to "green" switch_traffic "green" stop "blue"else deploy_to "blue" switch_traffic "blue" stop "green"fiThe Critical Flag
Section titled “The Critical Flag”The most important detail: docker compose up --no-recreate. Without this flag, Docker Compose will recreate the Traefik container when bringing up the new backend, causing a brief outage.
Lessons Learned
Section titled “Lessons Learned”- Traefik watches Docker labels — no config file reload needed
- Health checks are essential — never route traffic to an unhealthy container
--no-recreateis critical — prevents proxy restarts during deploy- Traefik can crash during Let’s Encrypt renewal — add a cron job to restart it