Stage 4 · Reliability · Medium · 14 min

Changing a database table without downtime

How to rename a column on a table that a live app is using. It takes six small steps, each safe beside the code that is already running.

What each interview level is expected to know

Learn first: Choosing a database and modelling data, CI/CD and safe deployments

After this lesson you can:

  • Rename a live column in six safe steps, each working beside the running code.
  • Explain why the old rows must be copied before reads move to the new column.
  • Spot the step that breaks if it runs too early or is skipped.

Start here

See it in 60 seconds

Rename a column while the app runs

One rename breaks the running code, so the safe way adds a second column and moves over in six small steps.

Scene 1 of 7 · Rename in one step

The column becomes full_name, so every request from the old code for name fails.

Old code, reads name, FAILEDOld codereads namewrites nameFAILEDNo release now, nothing being shipped, IDLENo release nownothing being shippednot runningIDLEusers tableusers tablecolumns: id, full_name
  • Old code — reads name — FAILED — writes name
  • No release now — nothing being shipped — IDLE — not running
  • users table — healthy — columns: id, full_name
Some rows of the users table
Usernamefull_name
Ashano columnAsha
Benno columnBen
Requests failed
3
Names shown blank
0
Names lost for good
0
  1. Rename in one step. The column becomes full_name, so every request from the old code for name fails.
  2. Add, do not rename. Start again: keep name, add an empty full_name beside it, and the old code still works.
  3. Write to both. A release ships code that writes each new name to both columns.
  4. Copy the old rows. A copy job fills full_name in the older rows, such as those of Asha and Ben.
  5. Read the new column. The next release reads full_name, and still writes both for the older code beside it.
  6. Stop the old writes. The release after that writes only full_name, and once it is out, no running code uses name.
  7. Remove the old column. Only now is name removed, and not one request failed on the way.
  8. Now you try. Run the six steps again, but skip one. Which step do you skip? For example: No request fails, but names show blank 16 times, and 4 names are lost for good. Rows from before the double write have an empty full_name, and reading an empty cell is not an error.

Scene 1 of 7: Rename in one step. The column becomes full_name, so every request from the old code for name fails.

Key points

  1. During every release, two versions of the code share one table.
  2. Add the new column first, and remove the old one last.
  3. The code must write both columns before the copy runs.
  4. A skipped step may give no error, only blank or lost names.

Go deeper in the Table change: rename a column with no downtime lab →

In plain words

Say a table called users has a column called name, and the team wants to call it full_name. The app is live, and its code reads and writes name all day. If you rename the column in one step, the running code asks for a column that is gone, and its requests fail. The safe way is to add before you remove. Add full_name beside name. Change the code in small releases until nothing uses name. Then remove name. For a while the table holds both columns, so old code and new code can both work. This method is often called .

In practice the rename takes five releases. First, add full_name, empty. Next, make the code write to both columns. Then copy the old values across in small batches, so the table is never locked for long. After that, switch reads to full_name and stop writing name. Last, drop name.

The problem it solves

Shipping new code takes time. For some minutes, old code and new code run side by side on one table. So there is no single moment when you can change the table and all the code together. A change that suits the new code breaks the old code, and the other way round. The worst faults give no error at all: a page shows a blank name, and nobody is told.

Why it matters

Almost every feature changes a table sooner or later: a new column, a new name, a new type. The app cannot stop while that happens. An interviewer who asks "how would you change this table?" wants the order of the steps, and what each step protects.

A worked example

Say 4 users signed up through code that wrote only the old column: Asha, Ben, Chen and Dina. The plan skips the step that copies old rows. Later sign-ups are written to both columns, so they look right. Then the code starts to read full_name. Those 4 users show a blank name, and no error appears. When the old column is removed, their 4 names are gone for good.

Think of it like…

Think of a shop that moves to a new street. It opens the new shop first, puts a sign on the old door, and moves the stock over. It closes the old shop only when no customer comes there any more.

Where this analogy stops working

Opening the new before you close the old is the useful part. But a customer can read the sign and walk over. Old code cannot: it keeps asking for the old column until someone ships new code. So the old column must stay until no running code uses it.

Try it

See it working

Lab · Reliability

Table change: rename a column with no downtime

A live app reads and writes the column name. Rename it to full_name in one step, or in six safe steps. Skip a step, and see which version of the code breaks.

Try it

Old code, reads nameOld codereads namewrites nameusers table, 2 rowsusers table2 rowscolumns: id, name
  • Old code — reads name — healthy — writes name
  • users table — 2 rows — healthy — columns: id, name

Next: step 1, Add the new column.

The users table, row by row
idnameWritten by
1AshaBefore the plan
2BenBefore the plan

What the last step did

Nothing yet. After each step, each running version of the code signs up one user, then loads the list of users. A load is one read for each row.

The plan

  1. Add the new columnDatabase change. Add full_name to the table. It is empty in every row. Next
  2. Write to both columnsCode release. Ship code that writes each name to name and to full_name. Later
  3. Copy the old rowsDatabase change. Copy name into full_name in every row where full_name is empty. Later
  4. Read the new columnCode release. Ship code that reads full_name. It still writes both columns. Later
  5. Stop writing the old columnCode release. Ship code that writes full_name only. Later
  6. Remove the old columnDatabase change. Remove name from the table. Later
Sign-ups failed
0/ 0
the code wrote a column that is not there
Reads that failed
0/ 0
the code read a column that is not there
Names shown blank
0
the cell the code read was empty
Names lost for good
0
in no column that still exists

Numbers add up:0 sign-ups = 0 ok + 0 failed · 0 reads = 0 ok + 0 blank + 0 failedThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

The plan

Add a second column, move the code and the data over, then remove the old column.

What this model simplifies
  • The table is tiny. On a table with millions of rows, the copy runs in small batches for hours, so it does not slow the live app.
  • A release is one round here, with the older and the newer code side by side. A real rolling release moves over server by server.
  • The only requests are sign-ups and loads of the user list. If the double write is skipped, a user who changes their name adds another fault: the new column keeps the old name.
  • A cell may be empty here. If the real name column is marked as required, sign-ups fail at step 5 unless that rule is removed first.
  • Adding a column is instant here. On some databases, adding a column locks a large table for a while.
  • The code writes both columns itself. Many teams use a migration tool or a database trigger to do the double write and the copy.
  • In a real plan, the first four steps can be undone at once. After step 5 the old column is out of date, so teams wait and check before they go on.

Also try: Deployments · Replication

Mechanics

How it works

The pictures follow this page's example: the users table, where name becomes full_name while the app is live. They show the first step, the and the last step, where most mistakes happen.

  1. Add the new column

    Pick a case to follow below

    With this case: Renaming in one step broke the running code at once: it asked for name, and name was gone.

    Running code, serves usersRunning codeserves usersusers table, the live table, NOWusers tablethe live tablefull_name onlyNOW
    • Running code — serves users — healthy
    • users table — the live table — healthy — NOW — full_name only
    • Error
    Step 1 of 2

    Step 1 of 2 · users table

    Watch: The column name is renamed to full_name

    What happens
    One command renames the column in the table.
    Why
    It looks like the quickest way to make the change.
    What changes
    The running code was not changed, and it still asks for name.
    Next
    The running code asks for name, and gets an error
    Columns
    full_name
    Running code uses
    name
    Requests
    working
    users are served

    Step 1 of 2: users table. The column name is renamed to full_name. One command renames the column in the table.

    Add full_name to the table, empty in every row. The old code never asks for it, so nothing changes for users. This is the expand half: the table grows first.

    In the picture, a one-step rename breaks the running code at once: its queries ask for name, and name is gone.

    Adding full_name beside name changes nothing for that code, so users see no errors.

  2. Write to both columns

    Ship code that writes each new name to name and to full_name. It still reads name. Once this release has finished, every new row is right in both columns.

  3. Copy the old rows

    Pick a case to follow below

    With this case: With no backfill, the page for user:7 showed a blank name, and no error was raised anywhere.

    Running code, serves usersRunning codeserves usersusers table, the live table, NOWusers tablethe live tableuser:7: emptyNOWBackfill job, 1,000 rows at a timeBackfill job1,000 rows at a time
    • Running code — serves users — healthy
    • users table — the live table — healthy — NOW — user:7: empty
    • Backfill job — 1,000 rows at a time — healthy
    • Rows
    Step 1 of 2

    Step 1 of 2 · users table

    Watch: user:7 has an empty full_name

    What happens
    user:42 signed up after the code began writing both columns, so it has both. user:7 is older.
    Why
    Writing both columns only fixes rows written from then on.
    What changes
    Nothing copies the old rows.
    Next
    The page for user:7 shows a blank name
    user:7 full_name
    empty
    Watch: saved before step 2
    user:42 full_name
    Leo Park
    written to both columns
    Page for user:7 shows
    –
    not read yet

    Step 1 of 2: users table. user:7 has an empty full_name. user:42 signed up after the code began writing both columns, so it has both. user:7 is older.

    Rows from before step 2 still have an empty full_name. A copy job fills them from name. This is called a backfill. On a large table it runs in small batches, such as 1,000 rows at a time, so the live app stays fast.

    In the picture, user:7 signed up before the code wrote both columns, so its full_name is empty. Without a backfill, code that reads full_name shows a blank name, and no error is raised anywhere.

    With the backfill run first, the page shows "Asha Rao".

  4. Read the new column

    Ship code that reads full_name. It still writes both columns, because the release before it still reads name. While this release goes out, both versions run side by side and both see every name.

  5. Stop writing the old column

    Ship code that writes only full_name. When this release has finished, no running code reads or writes name.

  6. Remove the old column

    Pick a case to follow below

    With this case: Removing name while the code still wrote it made every sign-up fail.

    Running code, serves users, NOWRunning codeserves userswrites bothNOWusers table, the live tableusers tablethe live table
    • Running code — serves users — healthy — NOW — writes both
    • users table — the live table — healthy
    • Query
    • Error
    Step 1 of 3

    Step 1 of 3 · Running code

    Done: The running code still writes both columns

    What happens
    The release that reads full_name is live. It still writes name, for the release before it.
    Why
    Step 5 has not shipped yet.
    What changes
    The team removes name.
    Next
    The column name is removed
    Running code writes
    name + full_name
    Columns
    name, full_name
    Sign-ups
    working
    new users can join

    Step 1 of 3: Running code. The running code still writes both columns. The release that reads full_name is live. It still writes name, for the release before it.

    What these pictures simplify. These pictures use two rows and stated releases. A real table may hold millions of rows, and adding a column can lock the table on some databases and versions. The table change lab above runs all six steps.

    Remove name from the table. This is the contract half, and it cannot be undone. Many teams wait some days first, and check that nothing has read the column.

    In the picture, removing name while the running code still writes it makes every sign-up fail. Removing it after step 5 has finished changes nothing for users.

Use it when

  • Any change that running code would notice: a renamed column, a changed type, one column split in two, or one table split in two.
  • Any table too large to change in one quick step, where a lock would stop the app.

Skip it when

  • A new column that no code uses yet: add it in one step, and ship the code that uses it after.
  • A system that can stop for a planned window, such as an office tool used only in the day. One step in the window is cheaper.
  • A feature that has no real data yet: change its table freely until real users arrive.

Check yourself

What is the safe order for renaming a column with no downtime?

Judgement

Trade-offs and how it fails

What you give up

Speed
One rename is one step and takes seconds, but the running code fails until the new code has replaced it.
Safety
Six steps break nothing, and the first four can be undone at once. The price is three releases, a copy job, and a table that holds the names twice for a while.

Failure modes

  • A skipped copy: no request fails, but old rows show a blank name. In the lab, 4 names are lost when the old column goes.
  • A copy that runs too early: code that still writes only the old column adds rows behind the copy. In the lab, 2 names are missed.
  • An old column removed too soon: code that still writes it fails on every sign-up.
  • A copy in one big step: it locks or slows a large table, and the live app times out.
  • A copy that overwrites: it must fill only empty cells, or it can put an older name over a newer one.

In the real world

  • GitHub built gh-ost to change large MySQL tables. It copies the rows into a new table in small batches, then swaps the two tables.
  • Stripe has described moving data in four stages: write to both places, change the reads, change the writes, then remove the old data.
  • PostgreSQL 11 and later can add a column with a fixed default value without rewriting the table. Older versions rewrote every row. Source: PostgreSQL 11 release notes (checked 14 October 2026)
  • Tools such as Flyway and Liquibase keep every table change in files stored with the code, and run the changes in a fixed order.

Trade-offs to be ready to discuss: One step vs six steps · Backfill speed vs load

Check yourself

Why does the copy job fill the old rows in small batches, such as 1,000 at a time?

Interview

What interviewers look for

  • Say the rule first: add before you remove, and each release must work beside the one before it.
  • For a large table, say that the copy runs in small batches and can be paused.
  • Say what going back costs. Up to step 4 it is one . After step 5 the old column is out of date, and after step 6 it is gone.
  • The same rule holds for messages and API fields. The API styles page shows it in "Changing a record without breaking readers".

Say it out loud: Why must the code write to both columns before the copy runs, and not after?

A plan adds full_name, ships code that writes both columns, then ships code that reads full_name. It skipped the copy. What do users see?

Expected depth by interview level

Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.

JuniorUseful
Why one rename breaks running code, and the rule: add before you remove.
MidExpected
The six steps for a rename, and what each skipped step costs.
SeniorExpected
A change plan for a large table: batches, a check between steps, and how to go back.
StaffExpected
Table changes across teams: who reads a column, how long old code lives, and what a failed step costs.

Practice

Apply it

Three harder questions

The first two use the idea on a new case. The last asks you to judge a design.

Apply it

A backfill copies 10 million rows in batches of 1,000, one batch every 100 ms. About how long does it take?

Apply it

The live release reads full_name and still writes both columns. A bug appears. Can you roll back to the release that reads name?

Judge a design

A backfill sets full_name from name in every row, even rows the new code has already filled. What is the risk, and what is better?

Next: where the copies of your app run: containers, and the system that places and repairs them.

Go deeper

Sources and further reading

First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.

  • Engineering guideParallelChangeMartin Fowler (Danilo Sato)Expand, migrate, contract: changing an interface in steps so old and new callers both work.
  • Engineering guideEvolutionary Database DesignSadalage and FowlerSmall, versioned database changes that ship with the code that needs them.
  • Official docsCREATE INDEXPostgreSQL documentationBuilding an index CONCURRENTLY so writes are not blocked, and its caveats.