ASP.NET Core Web API Interview Question #172

How should database migrations be handled during API deployment?

Testing, HttpClient, Integration Testing, Background Services & Deployment Senior Advanced

Quick Interview Answer

Database migrations should be applied through a controlled deployment process appropriate to the system's scale and availability requirements. Automatically migrating at application startup can be convenient for small systems but can create race conditions or risky schema changes in scaled production environments.

Detailed Explanation

Database migrations should be applied through a controlled deployment process appropriate to the system's scale and availability requirements. Automatically migrating at application startup can be convenient for small systems but can create race conditions or risky schema changes in scaled production environments.

Larger systems often run migrations as a separate deployment step and design schema changes to remain compatible during rolling upgrades.

Code Example

// Controlled deployment example:
dotnet ef database update

// Then deploy application instances that are
// compatible with the updated schema.