Branch by Abstraction
You'll learn how to introduce a layer of abstraction to safely transition legacy code to new implementations without breaking production.
The Core Idea
Branch by Abstraction is a technique for making large-scale changes to production systems without using long-lived feature branches or risky "big bang" deployments. Instead of replacing legacy code directly, you create an abstraction layer (like an interface) that both the old and new implementations can sit behind. This lets you gradually switch traffic from the old to the new implementation in production, with an instant rollback path if problems arise.
Think of it like replacing the engine in a moving car: instead of stopping the car, you build an adapter that lets either engine power the wheels. You keep the old engine running while installing the new one, then gradually shift power over, ready to switch back instantly if the new engine sputters.
The Process
- Introduce the abstraction — Create an interface or wrapper around the code you want to replace
- Route through the abstraction — Make all callers use the new abstraction instead of calling legacy code directly
- Implement the new approach — Build your new implementation behind the same abstraction
- Switch implementations — Use feature flags or configuration to route traffic to the new code
- Remove the old — Once confident, delete the legacy implementation and potentially the abstraction itself
The key advantage: every step is a small, safe, production-ready change. You maintain working software throughout, and your safety net of characterization tests protects each step.
Key Takeaway: Branch by Abstraction lets you replace legacy implementations incrementally by introducing an abstraction layer that isolates the old code and enables parallel development of the new, with production traffic switchable at runtime.