Design a zero-downtime deployment process for an ASP.NET Core API with database changes.
Zomato · Full Stack Developer · 3-4-years · technical
Published
Year not specified · .NET, Azure, DevOps
Community answers
Posted by wasAsked editorial collection
Use backward-compatible, staged releases. Deploy additive database changes first, then application code that can handle old and new representations, backfill in bounded batches, switch reads, and remove obsolete structures in a later release.
Run multiple healthy instances behind a load balancer with readiness checks and graceful shutdown. Use rolling, blue-green, or canary deployment; stop and roll back automatically on error rate, latency, or business-metric regression. Keep configuration and secrets external, make startup migrations controlled and observable, and ensure background jobs have single-owner/idempotency protection. A rollback plan must cover schema and message compatibility, not only the application binary.
Backbencher Developer · · 0 likes
Zero-downtime deployment needs both the application rollout and the database changes to be backward compatible.
Application rollout
- Run at least two instances behind a load balancer, or use deployment slots in Azure App Service: deploy to staging, warm it up, then swap.
- Use rolling or blue-green deployments in Kubernetes or containers, with readiness probes so traffic only reaches instances that are ready.
- Handle graceful shutdown: stop accepting new requests and let in-flight requests finish (configure the host shutdown timeout).
Database changes: expand and contract
Old and new versions of the code run at the same time, so every schema change must work with both.
1. Expand: add new nullable columns or tables, new indexes (online where supported), and keep old columns. Deploy the migration before the code.
2. Deploy code that writes to both old and new structures and reads safely from either.
3. Backfill data in small batches to avoid long locks.
4. Switch reads to the new structure.
5. Contract: in a later release, remove old columns and code once no running version uses them.
Never rename or drop a column in the same release as the code that stops using it.
Tooling
- Run EF Core migrations as a separate pipeline step or idempotent script (dotnet ef migrations script --idempotent), not on application startup across several instances.
- Review generated SQL for locking operations on large tables.
Safety nets
- Health checks and automated smoke tests after deployment.
- Feature flags to turn new behaviour on gradually and off instantly.
- Monitor error rates and latency; roll back by swapping slots back. Because schema changes are backward compatible, the previous version still works.
- Take a backup or point-in-time restore point before risky migrations.