Interview: rename a column on a 600 GB table while 30 servers keep serving traffic
Rename a column on a live table with rolling deploys. Backward and forward compatibility, expand, migrate, contract, backfill, and why only the final drop…
More on Ticket interviews
- Database Interviews in the AI Era: The Ticket Format
- Interview: the same job runs twice
- Deadlock Interview Question: Find and Fix It in SQL
- Slow Query Interview: One Keyword Made It 40× Slower
- Interview: rate limit is 2/min, 30 requests get through
- Interview: “just add an index” slowed ingestion
- Interview: “I changed my name, refresh shows the old one”
- Interview: importing 10M rows takes six hours
- Interview: everything got slow and the disk keeps growing
- Lost Update Interview: Wallet Balance Wrong Under Load
- Interview: API p99 jumps 10× every night at 2 am
- Interview: profile lookups got 40× slower, writes are fine
- Interview: inserts stall, and only one page is hot
- Interview: the write succeeded, the next read shows an empty cart
- Interview: inventory stayed locked after the coordinator restarted
- Interview: for four minutes, both regions took orders
- Interview: shoes show a 0% discount, then the report crashes
- Interview: March gained $50 after the deploy, and the months don’t add up
- Interview: the new branch’s dashboard takes 38 seconds
- Interview: the index is right there, make Postgres use it
- Interview: warehouse and checkout overwrite the same order
- Interview: the bestsellers report now takes nine minutes
- Interview: an analyst query locked checkout
- Interview: the member is active and the email went out twice
- Interview: one shard is at 96% CPU and the other is idle
- Interview: the menu is slow, and the proposal is event sourcing
- Interview: four dashboards disagree about whether the database is slow
- Interview: checkout got slow the hour the warehouse job started
- Interview: the query is fast in staging and slow in production
- Interview: login looks up an email and reads the whole customers table
- Interview: the proposal splits one database into three shards
- Interview: the order page joins four tables on every view
- Interview: every page view is a read-write query on the leader
- Interview: Sarah and John both debit version 1
- Interview: the CTO read a blog post and wants to move Postgres to MySQL
- Interview: one table takes 50,000 writes a second, another feeds dashboards. Which engine for each?
- Interview: EU users wait on the ocean for every write, can both regions take writes?
- Interview: users search cars by color, but the table is sharded by car id
- Interview: we added a fourth node and most of the data moved
- Interview: two people book the same room at noon, both get a confirmation
- Interview: everything is on the strongest consistency and far requests crawl
- Interview: the order is saved, the message to search and email never left
- Interview: orders go to 16 shards in 2 regions, what should the order id be?
- Interview: one celebrity posts, and every timeline in the app slows down
- Interview: 5,000 customers share one database, and one of them slows down everyone
Keep learning
Overview
In simple words, what are backward and forward compatibility? explain simply Backward: new code reads old data. Forward: old code reads new data. Forward is harder: old code must ignore things it has never seen. A rolling deploy needs both at once: old and new servers share one database. Data outlives code: five-year-old rows keep their old shape. both directions named rolling deploy means a mix data outlives code What breaks if we just rename the column in one deploy? what breaks if Some servers fail for the whole rollout, whichever order you pick. Rename first: old servers ask for name, which is gone. Deploy first: new servers ask for full_name, which doesn’t exist yet. Rule: every step must work for both code versions. no atomic switch both orders fail steps that work for both versions Numbers: how long does the backfill take, and how do you run it? About 3 hours: 100,000 batches × ~100 ms each (illustrative). Small batches keep transactions short: brief locks, little replica lag. Restartable: walk the primary key, remember the last id, safe to rerun. small batches watch lag and latency The old column is dropped and a bug shows up a week later. What now? Only backups can help now. That is why the drop comes last. Before the drop, v2 writes both columns, so rolling back is easy. Before dropping: back up, wait a full cycle, check no one still reads it. backup first check other readers Which schema changes are cheap and which are not, and what else could you do? what would you do instead Most databases fill null for old rows on read, without rewriting them. Alternatives: a JSON column (no migrations, fewer checks) or an online copy tool. Always rehearse on a production-sized copy. real rewrites cost Our queue messages, caches and search index also carry this field. How does that change the plan? Every reader needs its own expand, migrate, contract timeline. Use a schema registry (a central list of shapes) to check compatibility before deploy. Never remove a field until the last consumer stops reading it. many readers, not one messages in flight schema registry contract after the last reader The rule Add the new column, empty and optional. Write both, backfill in batches, then read new. Back up, check readers, drop. No undo. Dropping the old name in the same deploy Switching reads before the backfill ends One giant UPDATE that floods replicas Forgetting queues, caches, reports, apps Defined backward and forward compatibility Old and new code coexist in a rolling deploy Expand, migrate, contract, in order Small, restartable backfill batches Drop last: the only step with no undo Mentioned queues, caches, other services A restaurant changes its menu. Three waiters still hold the old menu and three hold the new one. Both groups send orders to the same kitchen, which must understand both kinds of order until every waiter has the new menu. waiters with the old menu waiters with the new menu the kitchen = the database must read both kinds of order Old dishes are still on the tables: data outlives code. 1 Expand 2 Deploy v2 3 Backfill 4 Deploy v3 5 Contract v1 reads and writes name v2 writes both columns, reads full_name and falls back to name v3 reads and writes only full_name v3 servers read full_name, which is still empty for old rows. Users see blank names. Never switch reads before the backfill is complete. You dropped the only copy of the old names. Only a backup can bring them back. Everything runs v1 and reads the column name. Nothing has changed yet. The new column is added, empty and optional. v1 never asks for it, so it keeps working. Adding a column that may be empty normally does not rewrite old rows. A rolling deploy: v1 and v2 servers run side by side. v2 writes both columns, so any row can be read by either version. Rolling back is safe. You skipped the backfill. Old rows still have an empty full_name. The backfill copies name into full_name in small batches. Old rows were written before the new column existed. Data outlives code. v2 and v3 servers both work, because every row now has both columns. v3 no longer touches name. Done. This is the one step that cannot be undone: v2 needs name, so rolling code back now needs the column restored. Take a backup first. The rollout finished and everything works again, but users saw errors for the whole rollout. Nothing is deployed yet. The rename would have to happen at the exact instant the last server changes, and no rolling deploy can do that. users table (the schema) old column, holds every old value renamed away not added yet Rename users.name to users.full_name while 30 servers keep running Expand, migrate, contract One-step rename rename first, then deploy deploy first, then rename 30 app servers No server failing All servers run the same version in this step. Rolling deploy: the first servers are replaced, the rest still run the old code. Servers on the new code Backfill progress Skip the backfill (do not do this) Next step What to notice: in the three-step plan every step works for every mix of old and new servers. In the one-step rename some servers always fail, whichever order you pick. waiting for the save A new server added a key. An old server saves the same row. Old server behaviour old code drops keys it does not know old code keeps unknown keys row in the database old server (v1) copies theme along has no field for theme row after the save theme is gone for good nothing lost Old server saves the row the old code read the row into an object with no place for theme, then wrote the whole object back. The new key vanished. This is the trap for forward compatibility. old code must leave alone what it does not understand. Update only the fields you know, or carry unknown keys through unchanged. Two arrows. Backward compatibility: new code reads data written by old code. Forward compatibility: old code reads data written by new code. During a rolling deploy both happen at once. Backward compatible new code old data Easier: you know the old format. Forward compatible old code new data Harder: it must ignore what it has never seen. A rolling deploy needs both at once Old and new servers share one database, and a five-year-old row sits beside one written a second ago. Rename first old servers fail Deploy first new servers fail Two timelines of a rolling deploy lasting about twenty minutes (illustrative). If the column is renamed first, old servers fail during the whole rollout. If code is deployed first, new servers fail during the whole rollout. Errors during a one-step rename (rollout of about 20 minutes, illustrative) rollout starts rollout ends old and new code message queue old messages still waiting entries in the old shape search index built from old rows API clients mobile apps update late reports and exports may name the old column The users table in the middle with six other readers and writers around it: app servers, a message queue, a cache, a search index, API clients and reports. Each may run a different version of the schema. users table the schema rows (illustrative) batches of 10,000 per batch, incl. pause total backfill undo: easy Write both Read new Drop old undo: backup only Add optional column Cheap: old rows read as null. Value → list, or move table Costly: real rewrite. JSON column Online copy tool Copy, replay, swap. Extra disk.
Rename a column on a 600 GB table while 30 servers keep serving traffic
Servers never all switch at once. So every step must work for old and new code together. backward / forward compatibility rolling deploy expand → migrate → contract A one-step rename breaks servers for the whole rollout Old and new code share one database mid-deploy
A restaurant changes its menu
Old menu only Both menus in use kitchen reads both New menu only
Rename users.name to users.full_name with zero downtime
Servers update a few at a time (a rolling deploy). No maintenance window is allowed. 600 GB (illustrative) 1 billion (illustrative) app servers 20 min (illustrative) downtime allowed Restated: no single step may need all servers to switch together. Plan steps, not a rename.
Try the rename both ways
First step through the safe plan, then break it on purpose. The second lab shows the hidden trap with old code.
Four ways to change a schema
No downtime Easy rollback Few deploys DB checks shape One-step ALTER in a window Expand, migrate, contract Online copy tool Flexible JSON shape Four ways to change a schema. One-step ALTER pick when Small table, or app can go offline. Any live system with rolling deploys. Optional fields that change often. Rename name to full_name on the 600 GB table with no downtime. What do you ship? Expand, migrate, contract: add the column, write both, backfill in batches, switch reads, drop the old column last Downtime risk Ease of rollback Calendar time Copy the table with an online schema-change tool, then swap names at the end The tool does the rewrite, but the swap is one instant and old code still asks for name. Better for type changes. Run ALTER ... RENAME COLUMN during the deploy and keep the timing close Some servers always run the wrong version. Errors for the whole rollout, and no clean rollback.
A model spoken answer
How do you change a column on a live database with no downtime?
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.