Interview › Databases & Caching
How do you make a schema change backward compatible during a rolling deploy?
Databases & Caching · Intermediate level
Answer
For rolling deploys, I make schema changes backward compatible with expand-and-contract: add new structures first, deploy code that supports old and new, backfill, switch reads, then remove old structures later.
Technical explanation
Old and new app versions may run at the same time, so schema must support both during rollout.
Large table rewrites, blocking locks, foreign-key validation, and index builds can cause outages if done naively.
Always rehearse on production-sized data and set lock_timeout and statement_timeout.
Hands-on example
Expand-contract example:
ALTER TABLE users ADD COLUMN full_name text;Deploy app that dual-writes name and full_name and reads COALESCE(full_name, name).
Backfill in batches.
After all old app versions are gone, add constraints and later drop the old column.
Foreign key safer pattern:
ALTER TABLE orders ADD CONSTRAINT orders_customer_fk FOREIGN KEY (customer_id) REFERENCES customers(id) NOT VALID;
ALTER TABLE orders VALIDATE CONSTRAINT orders_customer_fk;Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Databases & Caching interview questions
- What is schema migration, and how do you run migrations safely in production?
- What is AWS DMS, and when would you use it?
- What is connection exhaustion, and how do you prevent it?
- What is ElastiCache, and what does it manage?
- What is the difference between ElastiCache Redis and Memcached?
- What is WAL (write-ahead logging), and how does it support durability and replication?
- What is Redis, and what core data types does it support?
- What is a transaction, and what do the ACID properties mean?