Learnitweb

Strangler Fig Pattern

Introduction

The Strangler Fig Pattern is a modern software design strategy for incrementally replacing or modernizing a legacy system. Inspired by the growth pattern of a strangler fig tree, which gradually envelops and replaces its host tree, this approach allows teams to safely transition away from legacy systems without disrupting business operations.

Incrementally migrate a legacy system by gradually replacing specific pieces of functionality with new applications and services. As features from the legacy system are replaced, the new system eventually replaces all of the old system’s features, strangling the old system and allowing you to decommission it.

Context and problem

As systems age, their development tools, hosting technologies, and underlying architectures can become outdated. This, coupled with the addition of new features over time, often leads to increased complexity, making the system more difficult to maintain and less adaptable to future needs.

Replacing a legacy system entirely is a daunting task, especially for large and intricate applications. A more practical approach is to gradually migrate to a modern system while retaining the legacy system for functionalities that are yet to be transitioned. However, this dual-system approach requires clients to be aware of where each feature resides. Each time a feature is migrated, client configurations must be updated to align with the new system’s structure.

Solution

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 approach reduces the risks associated with migrating an entire system by spreading the development effort across a manageable timeline. The façade acts as a reliable intermediary, directing users to either the legacy system or the new services as appropriate. This allows you to introduce new functionality at a comfortable pace while maintaining the operational stability of the legacy system. Gradually, as features are migrated, the legacy system becomes redundant and can be decommissioned, completing the transition seamlessly.

Key Concepts of the Strangler Fig Pattern

  • Incremental Replacement: Replace specific pieces of functionality one at a time, rather than re-writing the entire system from scratch.
  • Façade Layer: Introduce a façade that acts as an intermediary between users and the underlying systems. It routes requests to either the legacy system or the new system.
  • Seamless Transition: Ensure users interact with a consistent interface, regardless of whether a feature is handled by the legacy system or the new system.
  • Gradual Decommissioning: Over time, as all functionality is migrated, the legacy system is retired.

Issues and considerations

  • 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. For example, strive to have clear demarcations between parts of your solution so that you can migrate each part individually.
  • At some point, when the migration is complete, the strangler fig façade will probably go away. Alternatively, you can maintain the façade as an adaptor for legacy clients to use while you update the core system for newer 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.

When to use this pattern

Use this pattern when gradually migrating a back-end application to a new architecture.

This pattern may not be suitable:

  • When requests to the back-end system cannot be intercepted.
  • For smaller systems where the complexity of wholesale replacement is low.

How the Strangler Fig Pattern Works

Step 1: Analyze the Legacy System

  • Identify the components, features, or services that need to be replaced.
  • Evaluate dependencies, shared data stores, and interactions between components.
  • Prioritize features based on their importance, complexity, or risk.

Step 2: Introduce a Façade

  • Implement a façade layer that intercepts user requests.
  • Route requests to either the legacy system or the new system based on the availability of features.
  • Ensure the façade is transparent to users, maintaining a consistent interface.

Step 3: Build and Deploy New Functionality

  • Develop new components or services to replace legacy features.
  • Ensure these new components integrate seamlessly with the façade and any shared resources.
  • Test thoroughly to verify correctness and performance.

Step 4: Migrate Features Gradually

  • Migrate features in manageable increments, ensuring each migration step is stable and functional.
  • Update the façade to redirect requests for migrated features to the new system.
  • Monitor performance and resolve issues promptly.

Step 5: Retire the Legacy System

  • Once all features have been migrated, decommission the legacy system.
  • Evaluate whether to retain the façade as an adapter for backward compatibility or retire it as well.