ASP.NET Core Interview Question #243
How would you perform a zero-downtime deployment when the database schema changes?
Senior ASP.NET Core Real-World Scenarios Senior Advanced
Quick Interview Answer
Use backward-compatible schema evolution so the old and new application versions can operate during the deployment overlap. A common expand-and-contract approach first adds compatible schema, then deploys code that can use it, migrates data if necessary, and only later removes obsolete columns or behavior.
Detailed Explanation
Use backward-compatible schema evolution so the old and new application versions can operate during the deployment overlap. A common expand-and-contract approach first adds compatible schema, then deploys code that can use it, migrates data if necessary, and only later removes obsolete columns or behavior.
Avoid deploying code that immediately requires a destructive rename or column removal while old instances are still running. Review migration locking and duration, especially on large tables.
Rollback planning must include data compatibility; rolling application binaries back is not sufficient if the database change cannot safely be reversed.
Code Example
// Example sequence:
// 1. Add NewColumn as nullable/compatible.
// 2. Deploy code that understands old + new representation.
// 3. Backfill data.
// 4. Switch reads/writes to NewColumn.
// 5. Remove old schema in a later release.