Strangler Facade Pattern
Description
The Strangler Facade pattern is a software architecture pattern that provides a simplified interface to a complex system to allow replacement of components without affecting the client. This pattern is useful when a system is being replaced or refactored, and the client needs to continue to interact with the system during the transition. The facade acts as a layer between the client and the system, providing a consistent interface that the client can use.
In most implementations, the facade is responsible for routing requests from the client to the appropriate component in the system. This allows the system to be refactored or replaced without affecting the client. The facade can also provide additional functionality, such as caching or logging, to improve performance or provide additional features to the client.
Diagram
Let's say we want to replace some old system that provides some meaningful functionality to the client. The first step is to add a layer between the client and the old system. This layer is the facade. The client now only interacts with the facade, which in turn interacts with the old system.
As the replacement systems are developed, they can be added to the facade, taking over functionality from the old system. The facade can route requests to the appropriate system based on the functionality being requested.
When to Use
This pattern is best used when an old service needs to be replaced with one or more new ones. If the old service needs to remain available during the transition, the Strangler Facade pattern can be used to provide a consistent interface to the client while the new services are developed. This pattern is also useful when the client needs to interact with multiple services that provide similar functionality, as the facade can route requests to the appropriate service based on the functionality being requested.
Advantages
The main advantages of using the Strangler Facade pattern are:
- Allows for the gradual replacement of a complex system
- Reduces the risk of breaking the client during the transition
- Provides a consistent interface to the client, even as the underlying system changes
- Can provide additional functionality, such as caching or logging, to improve performance or provide additional features to the client
Disadvantages
There are some disadvantages to using the Strangler Facade pattern:
- Requires careful attention to routing and network management to ensure that requests are routed to the appropriate system
- Refactoring efforts are often stuck using the same interface as the old system, which can limit the ability to take advantage of new features or improvements in the replacement systems
- Introduces an additional layer of complexity to the system, which can make debugging and maintenance more difficult
- Rollback plans can be complex, as the facade may need to be updated to route requests back to the old system if the replacement systems fail