# Zero-Downtime Deployments: How to Deploy Without Interrupting Users
Every deployment is a risk — the brief moment between stopping the old version and starting the new one is when users see errors. Zero-downtime deployment strategies eliminate this risk by ensuring the old version keeps serving traffic until the new version is ready and healthy.
Here is a practical guide to zero-downtime deployments on PandaStack.
1. What Causes Downtime During Deployments?
Downtime during deployment happens when:
- The old container is stopped before the new one is healthy
- Database migrations break backwards compatibility with the running code
- A process restarts and takes 30+ seconds to initialize before accepting connections
- A deployment fails midway, leaving neither version running correctly
Each of these has a solution.
2. Rolling Updates (PandaStack Default)
PandaStack container deployments use rolling updates by default. When you push a new deploy:
- 1A new container starts with the updated code
- 2PandaStack waits for the health check to return HTTP 200
- 3Only when the new container is healthy does PandaStack stop the old one
During this process, both containers run briefly in parallel. Traffic is routed to the healthy container. If the new container never becomes healthy, the old one stays live and the deployment fails gracefully.
This means zero downtime for most deployments — as long as you have a proper health check.
3. Add a Health Check Endpoint
The most important thing you can do for zero-downtime deployments is add a /health endpoint to your application:
Node.js/Express:
app.get('/health', (req, res) => {
// Optionally check database connectivity
res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() })
})Python/FastAPI:
@app.get("/health")
async def health():
return {"status": "ok"}Django:
from django.http import JsonResponse
def health(request):
return JsonResponse({"status": "ok"})This endpoint should return 200 only when your application is fully initialized and ready to handle requests. PandaStack uses this endpoint to determine when the new container is ready.
4. Database Migrations: The Hard Part
Database migrations are the most common source of deployment downtime. The solution is to write backwards-compatible migrations:
Rules for backwards-compatible migrations:
- 1Add columns with defaults — never add a NOT NULL column without a default
- 2Rename in two steps — add the new column, update code to write to both, migrate data, remove old column
- 3Never delete columns in the same deploy — delete only after the code that used them is gone
- 4Test migrations on a copy of production data before deploying
Migration order:
- 1Deploy migration (add columns, create tables) — old code still works
- 2Deploy new application code — reads from new columns
- 3Deploy cleanup migration — remove old columns (later, after verifying)
5. Feature Flags
Decouple deployment from feature release using feature flags:
- 1Deploy new code with the feature disabled
- 2Enable the feature via a flag (environment variable or config service)
- 3Roll out to 1% of users, then 10%, then 100%
- 4If problems arise, disable the flag without redeploying
This is the safest deployment approach — the code ships to production but users are not affected until you choose.
6. Graceful Shutdown
Ensure your application handles shutdown signals gracefully:
Node.js:
process.on('SIGTERM', async () => {
console.log('Received SIGTERM, shutting down gracefully')
// Stop accepting new connections
server.close(async () => {
// Close database connections
await db.disconnect()
process.exit(0)
})
// Force exit after 30s if graceful shutdown hangs
setTimeout(() => process.exit(1), 30000)
})This ensures in-flight requests complete before the container stops.
7. Rollback in One Click
If a bad deployment reaches production despite precautions:
- 1Go to your deployment in [dashboard.pandastack.io](https://dashboard.pandastack.io)
- 2Click Deployment History
- 3Select the last known-good deployment
- 4Click Redeploy
The previous version is live in under 30 seconds.
8. Set Up Uptime Monitoring
Configure monitoring alerts so you know immediately if a deployment causes an issue:
- Dashboard → Monitoring → Add Alert
- Alert type: HTTP status check on your app URL
- Notification: Slack, email, or webhook
- Check frequency: every minute during deployments
Full docs: [docs.pandastack.io](https://docs.pandastack.io).