Scrivio Interview library
ScenarioFoundations7 min read · updated 12 November 2026

In a live Spring Boot service, you need to split a customers.address text column into structured columns without downtime. What steps would you take?

I would use an expand and contract sequence over several releases. First a Flyway migration adds the new structured columns as nullable and leaves the old address column in place, then a release writes both old and new columns, then existing rows are backfilled in small batches to avoid long locks and replication lag. After verifying counts and sample rows, a release switches reads to the new columns, and only in a later release, once no code uses it, is the old column dropped.

Why this question is asked

Changing a column that a live service reads and writes is a common task, and doing it in one step is a common cause of outages. During a rolling deployment, old and new versions of the application run at the same time against the same database, so the schema must work for both. Interviewers ask this to see whether a candidate knows the expand and contract approach and the practical details of backfilling. In this answer, we will see why one migration is not enough, then go through each release: add the columns, write both, backfill, verify and switch reads, and finally drop the old column.

1Why One Migration Is Not Enough

Our table has a column address with values such as '12 High Street, Leeds, LS1 4AB, UK'. We want street, city, postcode and country columns. The naive plan is one Flyway script that adds the new columns, fills them, and drops address, deployed with the new code.

That fails in two ways. During a rolling deployment, pods with the old code are still running and still read and write address, which no longer exists, so they throw errors until they are replaced. And filling every row in one statement holds locks and generates a large burst of changes, which can block other queries and make read replicas fall behind. The fix is to split the change into steps where every step is compatible with the code before and after it.

Expand and contract, one release per row
ReleaseSchemaCode writesCode reads
1. Expandadd nullable new columnsaddress onlyaddress
2. Dual writeunchangedaddress and new columnsaddress
3. Backfill jobunchangedbothaddress
4. Switch readsunchangedbothnew columns
5. Stop old writesunchangednew columns onlynew columns
6. Contractdrop addressnew columnsnew columns
Every release works with the schema and code of the release before it.

2Release 1: Adding the New Columns

Flyway is a database migration tool that Spring Boot runs at startup; each versioned SQL file runs once, in order. Our first migration only adds columns, all nullable and without defaults, so existing rows and existing code are untouched.

SQL
-- V12__add_structured_address.sql
ALTER TABLE customers ADD COLUMN street varchar(200);
ALTER TABLE customers ADD COLUMN city varchar(100);
ALTER TABLE customers ADD COLUMN postcode varchar(20);
ALTER TABLE customers ADD COLUMN country varchar(2);
-- PostgreSQL: adding a nullable column with no default only changes the catalog, so it is fast
-- address is NOT dropped

Notice that we do not add NOT NULL constraints yet, because old rows have no values. Adding a nullable column is quick in PostgreSQL and in MySQL 8 with the instant algorithm, but it still needs a brief lock on the table, so we set a lock timeout in the migration where supported, to fail fast rather than queue behind a long-running query.

3Release 2: Writing Both Old and New Columns

The next release changes the code so that every save writes both the old text column and the new structured columns. Reads still use address, because most rows do not have structured values yet.

Java
@Entity
class Customer {
@Column(name = "address") private String address; // still written, still read
private String street, city, postcode, country; // now written too
void changeAddress(Address a) {
this.street = a.street(); this.city = a.city();
this.postcode = a.postcode(); this.country = a.country();
this.address = a.toSingleLine(); // "12 High Street, Leeds, LS1 4AB, UK"
}
}

From the moment this release is fully deployed, every new or changed customer has both forms. That is why the backfill comes after this step: rows changed during the backfill are already written correctly by the application, so the backfill never fights with live updates over the new columns.

4Release 3: Backfilling in Small Batches

Now we fill the new columns for the older rows. Splitting free text into parts usually needs code, such as an address parser in Java, rather than pure SQL, so the backfill is a job, for example a Spring Batch job or a scheduled task, that processes rows in small batches by primary key.

Java
// Process 1,000 rows at a time, each batch in its own short transaction
long lastId = 0;
while (true) {
List<Customer> batch = repo.findTop1000ByIdGreaterThanAndStreetIsNullOrderById(lastId);
if (batch.isEmpty()) break; // done
for (Customer c : batch) c.applyParsed(parser.parse(c.getAddress()));
repo.saveAll(batch); // commit: locks released after each batch
lastId = batch.get(batch.size() - 1).getId();
Thread.sleep(200); // give replicas and other queries room
}
// 2,000,000 rows -> 2,000 batches, roughly 15 minutes with the pause

Small batches keep each transaction short, so locks are held for milliseconds and other queries are not blocked. The pause and batch size control the rate of changes, which keeps replication lag low; we watch the replica lag metric and slow down if it grows. Rows that the parser cannot handle are logged with their id for manual review rather than guessed.

5Release 4: Verifying and Switching Reads

Before trusting the new columns, we check them. Counts first: how many rows still have street IS NULL while address IS NOT NULL? That should be zero, apart from the logged rows we decided to handle manually. Then samples: pick a few hundred random rows and compare toSingleLine() of the structured values with the original text.

SQL
SELECT count(*) FROM customers WHERE address IS NOT NULL AND street IS NULL; -- 0
SELECT count(*) FROM customers
WHERE address <> concat_ws(', ', street, city, postcode, country); -- 37: review these

When the numbers are explained, a release switches reads to the new columns, ideally behind a feature flag so we can flip back to address without redeploying. The code still writes both columns, so flipping back is safe.

6Releases 5 and 6: Dropping the Old Column Later

After reads have used the new columns for a while, a release stops writing address and removes it from the entity. Only when that release is fully deployed, and nothing else, such as reports, other services or ETL jobs, still reads the column, does a final Flyway migration drop it. At that point we can also add NOT NULL constraints on the new columns if the data allows it.

Leaving the drop to a later release costs a little disk space for a few weeks and buys a simple rollback at every earlier step. It is also the step people most often rush, and a dropped column cannot be brought back without a restore.

7Follow-up questions

Why not use a database trigger to keep the columns in sync instead of dual writes in code?

A trigger can work, and it covers writes from other systems too. But parsing free text in a trigger is awkward, triggers are easy to forget and hard to test, and they add work to every write. When the service owns the table, dual writes in code are clearer, and the backfill job handles the old rows.

How do you make sure nothing else reads the old column before dropping it?

Search all code bases and reporting tools for the column name, ask the data team about ETL jobs, and check database statistics or query logs for statements that reference it over a few weeks. In PostgreSQL, pg_stat_statements helps find queries that still mention the column.

Does Flyway run the migration on every pod at startup?

Each pod tries, but Flyway takes a lock in the database and records applied versions, so only the first pod applies a migration and the others see it is done. Some teams prefer to run migrations as a separate job before the deployment, which keeps startup simple and makes failures visible earlier.

8Conclusion

In this answer, we split a customers.address column into structured columns without downtime using expand and contract. We added nullable columns with Flyway and kept the old one, released code that writes both, backfilled old rows in small batches to keep locks short and replication lag low, verified with counts and samples before switching reads behind a flag, and dropped the old column only in a later release once nothing used it.

What to say in the interviewAbout 90 seconds aloud

Open with

I would do it as expand and contract over several releases, because during a rolling deployment old and new code run against the same schema. First, a Flyway migration adds street, city, postcode and country as nullable columns and does not touch the address column.

Then, if they want more

In PostgreSQL that is a quick catalog change. Second, I release code that writes both the old text column and the new columns on every save, while still reading the old one.

Third, I backfill existing rows with a job that processes them in small batches by primary key, say a thousand rows per transaction with a short pause, because one big update would hold locks and cause replication lag. Rows the parser cannot handle get logged for manual review.

Fourth, I verify: count rows that have an address but no street, which should be zero, and compare a sample of rows by rebuilding the single-line address from the parts. Then I switch reads to the new columns, ideally behind a feature flag so I can flip back.

Finally, in a later release, I stop writing the old column, check that no other code, reports or ETL jobs use it, and only then drop it with another migration and add constraints if needed. Each step can be rolled back, which is the whole point.

About this answer

Last updated
12 November 2026
Versions it names
MySQL 8
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. 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 "In a live Spring Boot service, you need to split a customers.address text column into...": https://scrivio-interview-library.netlify.app/architecture/modernization/d43a97ea64/