Shipping / 3 / 4
Zero-downtime migrations
A shop wants customer phone numbers in one normalised format, in a new column of a 40-million-row table, without stopping checkout. A plain rename breaks the pods that still run the old code, and a 5 ms ALTER stops every query because it waits for a lock behind a long report. The safe way is expand and contract: add a nullable column, write both, backfill in batches, verify and switch reads, stop the old writes, and drop the old column last, with a way back at every phase.
- 15 min
- Advanced
- 10 steps
- Checkout errors
- 0.1 %
- Longest blocked query
- 0 s
- Rows backfilled
- 0 %
- Time to roll back
- 15 min
- request
- reply
- redelivery
- duplicate
- lost
Numbers are a model scenario, not measurements
The real request
Migrations → Customers DBRequest
-- migration 0042, runs right before the rollout1
ALTER TABLE customers
RENAME COLUMN phone TO phone_e164;23
-- then deploy v2, which reads phone_e164
-- customers: 40 M rows, checkout writes 900 rows/s4
Response
ALTER TABLE 12 ms
0042— The migration runs in the pipeline, just before the new code.RENAME COLUMN— Instant: it only changes the name in the catalog.phone_e164— The name the new code expects.40 M rows— A big, hot table: every lock on it is felt at checkout.
Build it yourselfCheat sheetCompare lessons
Course: 74 lessons
01 Foundations
02 Scaling
03 Data & storage
04 Communication
05 Reliability
06 Architecture
07 Security
08 Shipping
09 Whole systems
10 Business processes
11 Case studies