# Zero-Downtime Deploys and Migrations

> Ship code and schema changes to a live system without outages using rolling, blue-green and expand-contract techniques. Free notes, key concepts, resources and...

Canonical: https://www.internhack.in/roadmaps/tracks/backend/zero-downtime-changes
Last updated: 2026-11-28

Ship code and schema changes to a live system without outages using rolling, blue-green and expand-contract techniques.

Advanced · about 4 hours · difficulty 4/5

Learn first: [Schema Migrations](https://www.internhack.in/roadmaps/tracks/backend/schema-migrations), [Continuous Integration and Delivery](https://www.internhack.in/roadmaps/tracks/backend/ci-cd), [Vertical and Horizontal Scaling](https://www.internhack.in/roadmaps/tracks/backend/scaling-strategies)

At scale, "we will take the site down for maintenance on Sunday" stops being acceptable. Every deploy and schema change must happen while traffic flows.

### Deployment strategies

- **Rolling**: replace instances a few at a time. Old and new versions run side by side briefly, so they must be compatible.
- **Blue-green**: run the new version as a full parallel environment and switch traffic at once, with instant rollback by switching back.
- **Canary**: send a small percentage of traffic to the new version, watch error and latency metrics, then expand or roll back automatically.

All rely on health checks, graceful shutdown (drain in-flight requests on SIGTERM) and good metrics.

### Expand and contract for schemas

Because two app versions overlap, never make a breaking schema change in one step. Renaming a column, for example:

1. **Expand**: add the new column; deploy code that writes to both.
2. **Migrate**: backfill existing rows in batches.
3. Switch reads to the new column.
4. **Contract**: stop writing the old column, then drop it in a later release.

### Safe migration habits

- Know which DDL takes heavy locks. Adding a column with a volatile default, adding a non-concurrent index or changing a type can block writes on large tables. Use `CREATE INDEX CONCURRENTLY`, add constraints as `NOT VALID` then validate, and set a `lock_timeout`.
- Backfill in small batches with pauses, never one giant `UPDATE`.
- Make every migration reversible or have a documented forward fix.

### Feature flags

Deploying code is not the same as releasing a feature. Ship code dark behind a **feature flag**, enable it for staff, then a percentage of users. Remove flags once rolled out.

You are ready to move on when you can rename a column on a table under constant load with no errors, using expand and contract across multiple deploys.

## Key concepts

- **Rolling deployments**
- **Blue-green deployments**
- **Canary releases**
- **Expand and contract migrations**
- **Lock-safe DDL**
- **Batched backfills**
- **Feature flags**

## Mini project

While a load test runs against your API, rename a column using expand and contract over three deploys and show zero failed requests in your metrics.

## Check yourself

Why can you not drop an old column in the same deploy that stops using it during a rolling deployment?

## Free resources

- [ParallelChange (expand and contract)](https://martinfowler.com/bliki/ParallelChange.html) (Martin Fowler)
- [BlueGreenDeployment](https://martinfowler.com/bliki/BlueGreenDeployment.html) (Martin Fowler)
- [Feature Toggles](https://martinfowler.com/articles/feature-toggles.html) (Martin Fowler)

Previous: [Throttling, Backpressure and Graceful Degradation](https://www.internhack.in/roadmaps/tracks/backend/load-management) · Next: [API and System Design Reviews](https://www.internhack.in/roadmaps/tracks/backend/api-design-review)

## More in Building for Scale and Resilience

- [Vertical and Horizontal Scaling](https://www.internhack.in/roadmaps/tracks/backend/scaling-strategies)
- [Timeouts, Retries and Circuit Breakers](https://www.internhack.in/roadmaps/tracks/backend/resilience-patterns)
- [Throttling, Backpressure and Graceful Degradation](https://www.internhack.in/roadmaps/tracks/backend/load-management)
- [Zero-Downtime Deploys and Migrations](https://www.internhack.in/roadmaps/tracks/backend/zero-downtime-changes)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
