Architecture as a hedge against certainty
The most common mistake in architecture is trying to build a system that is "right" for a future that hasn't happened yet. We spend weeks modeling complex scenarios, trying to account for every possible requirement, only to find that the actual needs of the system have shifted by the time we hit production.
I've learned that the best architecture isn't the one that solves every known problem, but the one that makes it easiest to solve the problems you haven't seen yet.
The Compatibility Window
When you need to replace an internal API, the impulse is often to do it all at once: update the definition, update the callers, and delete the old version. But in a growing codebase, that "all-at-once" approach is a high-risk maneuver. It forces a massive, synchronized change that can easily break the build or introduce subtle regressions.
A more resilient approach is to implement a compatibility window. This involves providing a bridge between the old and new ways of doing things, allowing you to migrate callers incrementally rather than all at once.
A Worked Example: The User Service
Imagine we have a userService that provides user data. Our current implementation is quite simple:
// The legacy API
// Called as: const user = userService.get(userId);
// Returns: { name: string }
export const getUser = (id: string) => {
return { name: "Alice" };
};
We want to move to a more robust system where we return a full UserProfile object, which includes more metadata. The new API looks like this:
// The new API
// Called as: const profile = userService.getProfile(userId);
// Returns: { id: string, name: string, email: string, role: string }
export const getUserProfile = (id: string) => {
return { id, name: "Alice", email: "alice@example.com", role: "admin" };
};
To avoid breaking every component that relies on getUser, we introduce a compatibility layer.
1. The Old Caller Behavior
We keep getUser alive, but we redefine it to call our new logic. We also add a warning to signal that this path is deprecated.
export const getUser = (id: string) => {
console.warn("DEPRECATION WARNING: userService.get() is deprecated. Use getUserProfile() instead.");
const profile = getUserProfile(id);
// We return a subset of the data to maintain the expected shape
return { name: profile.name };
};
2. The New Caller Behavior
New features and refactored components can immediately start using the richer API:
const profile = userService.getProfile(userId);
console.log(profile.email); // Works!
3. When to Close the Window
The compatibility window shouldn't last forever; it's a temporary bridge, not a permanent fixture. To decide when it's safe to remove the legacy getUser function, we look for two things:
- Zero Warnings: We monitor our logs or use a search tool to ensure no active call sites are still triggering the deprecation warning.
- Code Coverage: We verify that all modules that previously relied on the old shape have been successfully migrated to the new one.
Once these criteria are met, we can safely delete the legacy function.
4. The Rollback Condition
Even with a compatibility window, things can go wrong. A rollback condition for this pattern is: If the new getUserProfile implementation exhibits unexpected side effects or performance regressions that the legacy getUser did not.
Because getUser now relies on the new logic, we have effectively decoupled the interface from the implementation, but the underlying data source is still the same. If the new profile structure causes issues in downstream systems, our compatibility layer ensures we can still provide the old, simplified object if we need to revert the data shape temporarily.
Preserving your options
The goal of this pattern is to delay the "hard" part of a migration—the moment when you finally delete the old code—until you have enough confidence that the new system is stable.
By building these temporary bridges, you ensure that your architecture remains a tool for progress, rather than a series of rigid obstacles.
