Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

You need to rename a column used by a Spring Boot service with six replicas, with zero downtime. Describe the deployment and database migration sequence.

We never rename the column in one step. With the expand and contract pattern, we first add the new column next to the old one, then deploy code that writes both and still reads the old one, and backfill existing rows. Next we deploy code that reads the new column, then a release that stops writing the old one, and only in a later release do we drop the old column. Each migration runs through Flyway or Liquibase as its own step and stays compatible with the version of the code that is running at the time.

Why this question is asked

A column rename looks like a one-line change: ALTER TABLE customer RENAME COLUMN email TO email_address. With six replicas and a rolling deployment, that line causes an outage, because for a few minutes some pods still query the old name. Interviewers ask this to see whether we understand that application code and schema change at different moments, and how to sequence them so every running version always finds what it needs. In this answer, we will see why the direct rename fails, then walk through the expand and contract steps with the migrations and code at each stage, and finish with how to run the migrations safely.

1Why the Direct Rename Breaks

During a rolling deployment, Kubernetes replaces six pods one or two at a time, so old and new versions run together for several minutes. Suppose the new release renames the column and the new code uses the new name.

SQL
-- V12__rename_email.sql, runs before the new pods start
ALTER TABLE customer RENAME COLUMN email TO email_address;
-- an old pod, still running version 1, a second later:
SELECT id, email FROM customer WHERE id = 42;
-- ERROR: column "email" does not exist
-- every request on 5 of 6 pods fails until the rollout finishes

Running the migration after the rollout instead just moves the problem: then the new pods fail until it runs. And if we need to roll back, version 1 cannot work with the renamed column either. The root problem is that one schema state has to support two code versions at once. Expand and contract solves this by adding a schema state in between that supports both.

2Expand by Adding the New Column

The first release only adds the new column. Nothing reads or writes it yet, so the running code is unaffected. We make it nullable, because existing rows have no value yet and old code does not know to fill it.

SQL
-- V12__add_email_address.sql
ALTER TABLE customer ADD COLUMN email_address VARCHAR(320); -- nullable, no default
-- adding a nullable column without a default is a fast metadata change in PostgreSQL

Notice that this migration is backward compatible: version 1 of the code never mentions email_address, so it keeps working exactly as before.

3Write Both, Read Old, and Backfill

The next release changes the code to write both columns on every insert and update, while it still reads from the old one. With JPA, the simplest way is to map both columns and set them together.

Java
@Entity
class Customer {
@Column(name = "email") private String email; // still the source of truth
@Column(name = "email_address") private String emailAddress; // kept in sync
public void setEmail(String value) {
this.email = value;
this.emailAddress = value; // both columns written on every change
}
public String getEmail() { return email; } // reads the old column
}

While this version rolls out, old pods write only email and new pods write both, which is fine because everyone still reads email. Once every pod runs this version, we backfill the rows written before. On a large table we update in batches, so we never hold long locks or create one huge transaction.

4Running the Backfill in Batches

A single UPDATE on 40 million rows would lock and rewrite them all in one transaction, filling the write-ahead log and possibly blocking other writes for minutes. Batching keeps each transaction small.

Java
-- run repeatedly (from a job or script) until it updates 0 rows
UPDATE customer
SET email_address = email
WHERE id IN (SELECT id FROM customer
WHERE email_address IS NULL AND email IS NOT NULL
LIMIT 5000);
-- UPDATE 5000
-- ...
-- UPDATE 0 -> backfill done
SELECT count(*) FROM customer WHERE email_address IS DISTINCT FROM email; -- 0

The final count is our check that the two columns now agree on every row. Because new pods keep writing both columns, rows changed during the backfill also stay in sync.

5Step 3 and 4: Read New, Stop Writing Old, Then Drop

Now the next release switches reads to the new column while still writing both. Writing both matters here: if we must roll this release back, the previous version reads email, and that column is still current. Once we are confident, a following release stops writing the old column, and the entity maps only email_address. At that point no running code mentions email at all.

Only then, in a later release, do we contract by dropping the old column. Waiting a release is cheap insurance, because it keeps rollback possible until we are sure no version needs the old data. If the new column should be NOT NULL, we add that constraint once the backfill is verified, using a method your database can do without a long lock (in PostgreSQL, a NOT VALID check constraint validated separately is one option; check your version).

SQL
-- V15__drop_old_email.sql, deployed after the code stopped using it
ALTER TABLE customer DROP COLUMN email;
Expand and contract, release by release
ReleaseSchemaCode writesCode reads
1add email_address (nullable)emailemail
2both columns; backfill after rolloutemail and email_addressemail
3both columnsemail and email_addressemail_address
4both columnsemail_addressemail_address
5drop emailemail_addressemail_address
At every step the old and the new pods agree on a column that exists and is current.

6Running Migrations Safely

Flyway or Liquibase keep the schema changes in versioned files in the repository, so each step above is a reviewed, numbered migration. I would run them as a separate step in the pipeline, for example a Kubernetes Job that runs before the deployment, rather than letting each of the six replicas try to migrate at startup. A separate step makes failures visible in one place, avoids six pods racing for the migration lock, and lets the deployment wait until the schema is ready.

The rule that ties it together is simple: every migration must be compatible with the code version that is currently running and with the one being deployed. If a reviewer can find a running version that would break, the change is split into more steps.

7Follow-up questions

Could a database view or a generated column avoid the extra releases?

Sometimes. For example, after renaming the column, a view or a generated column with the old name could keep old code working for a while. But it adds database-specific behaviour, views are often not updatable in the way the ORM expects, and we still need a cleanup release. Expand and contract works the same way on every database and with every ORM, which is why it is the default.

What about renaming a column that other services read directly?

Then the contract phase waits until every consumer has moved, which can take weeks. This is one reason services should not share tables: with an API in between, the service can rename internally and keep the API field the same.

How long should we wait before dropping the old column?

At least until no deployed or rollback-candidate version uses it, which in practice means one full release after the code stopped writing it. Teams that keep backups for point-in-time restore should also check that no restore procedure depends on the old column.

8Conclusion

In this answer, we saw that a direct column rename breaks a rolling deployment because old and new code run together, and that expand and contract fixes it by adding a schema state that supports both. We add the new column, write both while reading the old one, backfill in batches, switch reads to the new column, stop writing the old one, and drop it in a later release. Running each migration as a separate Flyway or Liquibase step, always compatible with the running code, keeps every release reversible.

What to say in the interviewAbout 80 seconds aloud

Open with

I would not rename it in one step, because during a rolling deployment of six replicas old pods would query a column that no longer exists, and a rollback would break too.

Then, if they want more

I would use expand and contract over several releases. First, a Flyway or Liquibase migration adds the new column as nullable, which the running code ignores. Second, I deploy code that writes both columns on every insert and update but still reads the old one.

Once all pods run that version, I backfill existing rows in batches of a few thousand, so I never hold long locks, and I verify with a count that the columns match. Third, I deploy code that reads the new column but keeps writing both, so a rollback to the previous version still finds the old column current.

Fourth, a release stops writing the old column. Finally, in a later release, I drop the old column, and add a NOT NULL constraint if needed in a way that avoids a long lock.

I would run migrations as a separate pipeline step, for example a Kubernetes Job before the deployment, not from each replica at startup, and the review rule is that every migration must work with both the running version and the one being deployed.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You need to rename a column used by a Spring Boot service with six replicas, with zero...": https://scrivio-interview-library.netlify.app/spring-boot/production-operations/a6d0832dfb/