Coders.dev Partner

Monolith to Microservice

Monolith to Microservice
Article

The Strangler Fig pattern is an approach for gradually replacing parts of a legacy system with new applications and services. As the new system takes over features from the old one, the old system is eventually phased out. This strategy is helpful when aging systems become complex and challenging to maintain. By using a façade to route requests to the old or new components, features can be migrated gradually without disrupting clients. This minimizes risk, spreads development effort, and allows the old system to be retired once the migration is complete. Considerations include managing shared resources, designing new components for easy replacement, and ensuring the façade's reliability. This pattern is particularly useful for backend application migration, but may not suit scenarios where interception of requests is not feasible or for smaller systems with low replacement complexity.

 

The Strangler Fig pattern is a strategy for incrementally migrating a legacy system by gradually replacing specific pieces of functionality with new applications and services. As features from the old system are replaced, the new system eventually takes over all of the old system's features, effectively "strangling" the old system until it can be decommissioned.

As systems age, the development tools, hosting technology, and even system architectures they were built on can become increasingly obsolete. Adding new features and functionality can increase the complexity of these applications dramatically, making them harder to maintain or add new features to. Completely replacing a complex system can be a massive task. Often, a gradual migration to a new system is required, while keeping the old system to handle features that haven't been migrated yet. However, running two separate versions of an application means that clients have to know where particular features are located. Every time a feature or service is migrated, clients need to be updated to point to the new location.

The solution is to incrementally replace specific pieces of functionality with new applications and services. Create a façade that intercepts requests going to the backend legacy system. The façade routes these requests either to the legacy application or the new services. Existing features can be migrated to the new system gradually, and consumers can continue using the same interface, unaware that any migration has taken place.

This pattern helps to minimize risk from the migration, and spread the development effort over time. With the façade safely routing users to the correct application, you can add functionality to the new system at whatever pace you like, while ensuring the legacy application continues to function. Over time, as features are migrated to the new system, the legacy system is eventually "strangled" and is no longer necessary. Once this process is complete, the legacy system can safely be retired.

There are several considerations to keep in mind:

 

  • Consider how to handle services and data stores that are potentially used by both new and legacy systems. Make sure both can access these resources side-by-side.
  • Structure new applications and services in a way that they can easily be intercepted and replaced in future strangler fig migrations.
  • At some point, when the migration is complete, the strangler fig façade will either go away or evolve into an adaptor for legacy clients.
  • Make sure the façade keeps up with the migration.
  • Make sure the façade doesn't become a single point of failure or a performance bottleneck.

This pattern is useful when gradually migrating a back-end application to a new architecture. However, it may not be suitable when requests to the back-end system cannot be intercepted, or for smaller systems where the complexity of wholesale replacement is low.