QA
Senior LevelExpress JS

How do you manage breaking database schema migrations in continuous deployment Express architectures without downtime?

❓ Interview Prompt: Explain zero-downtime database migrations, Expand-Contract (Parallel Change) pattern, and multi-version database backward compatibility.

Renaming or dropping a database column in a single migration breaks running Express server instances instantly.

The Expand-Contract (Parallel Change) Pattern:

1
Phase 1 (Expand): Add the new column to the database as nullable. Deploy Express v2 to write to both old and new columns.
2
Phase 2 (Migrate): Run an asynchronous background script backfilling old rows into the new column.
3
Phase 3 (Contract): Deploy Express v3 to read strictly from the new column. In a subsequent deployment, drop the old database column!

Code Implementation Example

javascript
// Phase 1 (Expand): Dual-writing to old 'name' and new 'full_name' columns
async function createUser(data) {
  return await db.user.create({
    data: {
      name: data.fullName,      // Dual-write old column
      full_name: data.fullName  // Dual-write new column
    }
  });
}
💡Executing dual-writes during Phase 1 of Expand-Contract zero-downtime database migrations.
🎯 Interview Key Takeaway

Use the Expand-Contract pattern (Expand, Migrate, Contract) across separate deployments for zero-downtime database schema migrations.

#Zero-Downtime#Migrations#Database#Senior
Back to all Express JS Questions→

More Express JS Interview Questions

Beginner LevelExpress JS

What is Express.js and how does the middleware pipeline work?

Beginner LevelExpress JS

What is the difference between req.params, req.query, and req.body?

Beginner LevelExpress JS

How does express.Router() work for building modular route controllers?