← Docs

Recipe: Zero-downtime DB migration plan

Ship schema changes without taking Meridian offline. Follow this phased rollout to keep your licensing API hot while migrating.

Phase 1 — Expand

Add new columns as nullable, create new tables, and deploy a backward-compatible application release. The existing schema remains untouched; writes continue against old structures.

Phase 2 — Dual-write

Update the application layer to write to both old and new schemas. Reads still prefer the old path. Monitor error rates and latency for 24 hours before proceeding.

Phase 3 — Backfill

Run an idempotent backfill script that copies historical rows into the new shape. Use small batches with short transactions to avoid lock escalation.

Phase 4 — Switch reads

Flip a feature flag so reads come from the new schema. Keep dual-writes active. Validate correctness via reconciliation queries for 48 hours.

Phase 5 — Cleanup

Remove dual-write code, drop old columns and tables, and deploy a final release. Schedule during a low-traffic window and keep a rollback snapshot for 72 hours.

Pro tip: Use Meridian's built-in circuit breaker on the licensing endpoint during Phase 4. If reconciliation drifts beyond 0.1%, the breaker auto-reverts reads to the old schema.