Migrating from monolithic apps to efficient ones is a widespread software challenge. Fortunately, there’s a proven strategy that can guide this process, known as the Strangler Fig Pattern. Coined by Martin Fowler, this pattern outlines a gradual approach to migrating a application by iteratively transferring its functionality to a new system. The end result is a more readable, maintainable, and feature-rich application that aligns with modern technology trends.
The term ‘Strangler Fig’ originates from a tree enveloping and replacing a host tree as it grows. In a similar fashion, the Strangler Fig Pattern involves gradually growing a new application around the existing one until the legacy system is fully replaced.
Understanding the Strangler Fig Pattern
The primary goal of the Strangler Fig Pattern is to facilitate the migration of features from an outdated system to a new one.
Note that this pattern doesn’t assure fast migration but provides a stable framework to perform it. It allows for the implementation of enhancements that might have been challenging to achieve in the old system, such as introducing new features, improving speed, and enhancing system stability.
The process of applying the Strangler Fig Pattern involves several stages:
1. Identifying Features for Migration
Before anything else, it’s essential to understand which features need to be moved and define the scope of the migration.
This involves transferring only the functionality that is actively used by customers, leaving behind legacy code and irrelevant databases.
Additionally, this migration presents an opportunity to adopt modern technologies, including changes in programming languages, architecture, and database engines.
2. Creating the New Application and Establishing Foundations
In the new application, a new architecture to be used is defined, and the Strangler Facade is introduced. This facade is responsible for directing traffic from the old application to the new one.
It acts as a simple API gateway, routing user requests to the appropriate application. This mechanism allows for a gradual and controlled migration, as traffic can be directed to the new app or reverted to the old one if issues arise.
3. Weighing the Migration Trade-offs
During this migration, it’s crucial to exert control over the creation of new features. This helps prevent writing code in the old application that would require rewriting in the new one shortly after.
To achieve this, collaboration with the business side is necessary to ensure they won’t prioritize new features and that they understand the benefits of the migration and the new potential features it enables.
To support this, it’s common to prioritize other features that showcase the advantages of the new application.
This intentional feature planning results in a more informed prioritization of value.
4. Moving Features to the New Application
Unlike a big bang rewrite, where legacy code is often ignored, the Strangler Fig Pattern involves understanding the existing codebase and assessing its value before deciding whether to migrate it to the new application.
This process demands more effort than starting from scratch, and it may carry over some of the quirks of the old code.
Consequently, migrating a feature entails not just moving the code, but also refactoring it to achieve a simpler, more readable, and scalable version compared to the original.
5. Creating New Data Sources for Data Storage
Migrating features might necessitate a rewrite of the database model. This presents a challenge: maintaining data consistency between the old and new systems.
To address this, information that existed in the old database needs to be replicated in the new data sources. This step is pivotal, as data consistency ensures that rolling back a feature doesn’t result in data loss.
Specific patterns must be applied to address the migration of data sources.
6. Eliminating the Old Application
As more functionalities and workloads transition to the new system, the old system becomes less essential. Eventually, there comes a point where the old system can be retired without disrupting business operations.
After users have been successfully migrated to the new application and the old system’s usage dwindles, the facade can be removed.
Conclusions
The Strangler Fig Pattern, despite its meticulous nature, provides a clear path for transforming a monolithic application into a robust, modern system.
This approach allows organizations to reap the benefits of contemporary technologies, enhance user experiences, and ensure smoother maintenance in the long run.
By following these stages and embracing the gradual migration process, businesses can effectively modernize their applications while minimizing risks.
References
https://www.linkedin.com/pulse/taming-legacy-systems-my-journey-strangler-fig-pattern-selim-reza/
https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig


Be First to Comment