|
|
Strangler Fig Pattern for Legacy Migration
Author: Venkata Sudhakar
The Strangler Fig pattern is a software migration strategy inspired by the strangler fig tree, which grows around an existing tree and gradually replaces it over years. In software migration, you build a new system alongside the existing legacy system and incrementally route features and traffic to the new system, one piece at a time, until the legacy system is completely replaced and can be decommissioned. At no point during the migration is the service unavailable to users. This pattern is particularly powerful for monolith-to-microservices migrations and legacy database modernisations. A routing layer (a proxy, API gateway, or feature flag system) sits in front of both the old and new systems. Initially all requests go to the old system. As each module or feature is rewritten and tested, the routing layer redirects those specific requests to the new system. The rest continue going to the legacy system unchanged. This allows teams to migrate at their own pace without a high-risk "big bang" rewrite. The below example shows how to implement a Strangler Fig routing proxy in Spring Boot that routes customer-related API calls to the new microservice while routing all other calls to the legacy monolith.
It gives the following output when requests are made,
Routing GET /customers/1001 -> NEW customer-service
Routing POST /customers -> NEW customer-service
Routing GET /orders/5001 -> LEGACY monolith
Routing GET /inventory -> LEGACY monolith
The below example shows how to use feature flags with AWS AppConfig to control the routing dynamically at runtime, allowing you to switch individual endpoints from legacy to new without redeploying the proxy.
It gives the following output,
# Before enabling flag in AppConfig:
Routing GET /orders/5001 -> LEGACY monolith
# After enabling "migrate.orders" flag in AWS AppConfig
# (no deployment needed, takes effect within seconds):
Routing GET /orders/5001 -> NEW order-service
# Instant rollback: just set flag back to false in AppConfig
Migration Progress Tracking: At any point in the Strangler Fig migration, you can measure progress as the percentage of API endpoints or traffic that has been switched to the new system. A typical enterprise migration might take 6 to 18 months, with each sprint completing one or two more modules. The legacy system is only decommissioned when 100% of traffic has been moved and the new system has been running stably in production for a defined period, usually 30 to 90 days.
|
|