Parallel Change
A technique to make a breaking change safely in three steps: expand the interface to support old and new, migrate all clients, then contract by removing the old.
Also known as: Expand and Contract, Expand-Contract Pattern, Expand/Migrate/Contract, Zero-Downtime Migration
Category: Software Development
Tags: software-development, software-engineering, refactoring, patterns, compatibility, deployment, databases
Explanation
Parallel change, also known as expand and contract, splits a risky incompatible change into steps that are each safe to release. Instead of changing an interface and all of its users in one coordinated big bang, you let the old and the new way exist side by side for a while.
**The three phases**:
1. **Expand**: Add the new version next to the old one. Both work. Nothing breaks
2. **Migrate**: Move the clients from the old to the new, one at a time, each at its own pace
3. **Contract**: Once nothing uses the old version anymore, remove it
**Example: renaming a database column**:
1. Add the new column. Change the code to write to both columns
2. Copy the existing data to the new column
3. Switch the reads to the new column
4. Stop writing to the old column
5. Drop the old column
Each step is a small, separate deployment. The application never stops, and each step can be rolled back.
**Other uses**:
- **APIs**: Add the new field or endpoint, mark the old one as deprecated, remove it when traffic reaches zero
- **Method signatures**: Add the new method, have the old one delegate to it, migrate callers, delete the old one
- **Message formats**: Publish both formats until every consumer has moved
- **Infrastructure**: Blue-green deployments and the strangler fig pattern follow the same logic on a larger scale
**Why it works**:
- No release has to be synchronized between teams or services
- The system is always in a working state, which is what continuous delivery requires
- Problems show up one client at a time, not all at once
**Pitfalls**:
- **Never contracting**: The migration stalls at 90%, and you now maintain two ways forever. Plan the contract phase, give it an owner and a date
- **Keeping both in sync**: During the migration, old and new have to stay consistent. Double writes need care
- **Not knowing who still uses the old way**: Measure usage. Don't guess
- **Overkill for small scopes**: Inside a single codebase with good tests, an automated refactoring is often enough
Related Concepts
← Back to all concepts