HandbookXI the TabulariumMigrations without downtime
XIthe Tabularium, Model the dataMigrations without downtime
In plain words
A zero-downtime migration changes the schema in small steps that both the old and the new code can live with, often called expand and contract, so the app keeps working during and after the deploy.
Where you see it
Harbor renames invoices.total to amount_cents. Done in one migration, every server still running the old code fails with column "total" does not exist for the minutes the deploy takes. Done in steps, nobody notices.
What goes wrong
- Renaming or dropping a column in one step
Old servers, background jobs and cached code still use the old name while the deploy rolls out. Add the new column, move reads and writes over, and drop the old one in a later release.
- Locking a big table
Some changes take a lock that blocks every write until they finish, and on a large table that means minutes of failed checkouts. Create indexes concurrently, outside a transaction, add constraints as not valid and validate them later, and set a lock_timeout.
create index invoices_team_idx on invoices (team_id); -- blocks writes while it builds - Backfilling millions of rows in one update
One giant update holds locks for a long time and can time out halfway. Backfill in batches of a few thousand rows, with a short pause between them.
What to tell your agent
Quick check
Sign in to earn +10 XP for itHarbor needs to rename invoices.total to amount_cents with no downtime. What's the safe first step?