News for hackers. Stuff that matters.
Re:Using the expand and contract pattern for schema changes by sarchertech on Monday November 10, 2025 @08:30AM (#45875822)
This is just the natural solution that falls out if you want to change a schema with no downtime. I always just called it “dual writing”.
Re:Using the expand and contract pattern for schema changes by evancordell on Monday November 10, 2025 @09:57AM (#45876602)
We always called these "four-phase migrations". An old Stripe article used similar naming[0].

[0]: https://stripe.com/blog/online-migrations

Re:Using the expand and contract pattern for schema changes by sarchertech on Monday November 10, 2025 @11:59AM (#45877939)
I’ve heard that one too. I think the key insight is that you need to “stop the bleeding” (stop creating more old data that needs to be migrated) before you do any backfilling. That’s why I always called it dual writing because that’s the stop the bleeding step.
Re:Using the expand and contract pattern for schema changes by manmal on Monday November 10, 2025 @11:05AM (#45877260)
In the step where writes are added, from the client to the new schema instance, how does this work when writes depend on existing data, when the existing data hasn’t even been copied? Constrains like foreign keys will prevent this from working, no?
Re:Using the expand and contract pattern for schema changes by sarchertech on Monday November 10, 2025 @11:50AM (#45877836)
You wouldn’t enable foreign key constraints until you finish backfilling the old data in that case. Or you do it in phases where you do all of these steps and migrate the dependency first.