# Strangler fig pattern

## What it is

The strangler fig pattern replaces a running system in stages by gradually moving pieces of its work to a new implementation. A routing layer or another stable entry point decides which implementation handles each operation. Users can keep working while the team completes the new path a piece at a time. The older path is removed once its responsibilities, relevant data and consumers have moved.

The choices available depend on the public interface and the existing state. An HTTP service might route particular paths or groups of accounts to a replacement. A worker can direct a defined class of jobs to a new consumer. A data service might move a read operation before moving the write that owns the underlying structure. Give the choice an observable rule. An operator should be able to tell which version received an operation and why.

Replacement is also a question of ownership. Two implementations can serve the same public surface during the transition while an underlying decision still has one authoritative owner. Decide where writes go, what data other components can read, and how the old behaviour remains available for recovery. Routing is one part of the migration. Data consistency and user-visible outcomes need their own evidence.

## Why it matters

Large systems often have more behaviour than a replacement team initially knows. An unusual error code might drive retries in a client. A field that looks optional could supply a required report default. Moving one operation at a time gives the team a chance to discover those expectations while the rest of the system continues to operate. The lessons from the first slice can inform later ones.

A staged change can also make recovery more focused. If a new read path handles one part of the workload, switching that path back may be possible while the old data remains compatible. Once a new implementation owns writes or introduces a new representation, recovery can require a data plan. Establish those conditions before treating a route switch as the complete rollback procedure.

The cost of a long transition can become substantial. Both implementations may need maintenance, and the routing layer adds another place to observe and understand. Choose slices that retire a real responsibility and keep a clear list of remaining consumers. A transition has made progress when it moves a behaviour and gives the team a credible way to remove the old part.

## What it looks like in practice

Imagine replacing an API for customer order history. Put the existing public route behind an entry point that can choose the implementation. Move one read operation first. Compare the old and new response for representative records, including an unknown record and a record with optional fields. Compare outcomes that callers interpret, such as error status, ordering and pagination. Use a common operation identifier so observations from both paths can be compared.

Switch a limited part of traffic after the comparison has passed. Record the selected implementation on the service side without changing the response contract. Test a representative slow request and an unavailable dependency. The operator should know when to keep a request on the new route, when to restore the old one and how to make sure the data remains readable by both. Explicit observations make the route switch a measured operation.

Engineer's typed API migration case study describes moving routes to Huma over the existing Fiber runtime and verifying that registered routes and the published API description agree. It shows the value of checking parity along the way. The order-history example extends that reasoning to a migration that routes users between implementations. If the old response makes a documented promise, add a separate case to verify that the replacement still fulfils it.

Before moving a write, rehearse the ownership transition and its failure modes. Record which path is authoritative at each stage and how it handles a retry from a client that saw an uncertain result. Test what a read sees before and after the change. These checks can distinguish a successful move of the route from a successful move of the durable responsibility behind it.

## Where it goes wrong

A common problem is leaving both implementations active without a retirement plan. As the routing logic grows, some users can remain on an old path because they fall into an untested case. Confirm each migrated route and the consumers that still use it. Write down what can be removed after the final supported request has moved and which archived data remains useful for recovery or compliance.

Shared writes can create another problem. If a request is sent to two stores and only one commits, the systems have different histories. Avoid treating two acknowledgements as one durable outcome. Give one path authority during each phase and decide how any replicated view catches up. Use stable event or operation identities, and test the state after interruptions at the boundary.

Finally, measure responses throughout the move. A switch can preserve status codes but increase latency, change the way a result is sorted, or remove a piece of context a caller depends on. Use a small group of relevant observations and verify them at the actual entry point. A staged replacement works when the team can explain which behaviour now belongs to the new system, how users can recover after a failure and why the old part can be retired.

## Further reading
* Microsoft Azure Strangler Fig guidance. Discusses staged replacement through a preserved entry point.
* AWS prescriptive guidance on the Strangler fig pattern. Describes migration and routing trade-offs.
* Amazon API Gateway HTTP API routes. Gives a concrete example of request route selection.

=> /portfolio/migrated-the-api-to-huma-v2-at-100-parity/ typed API migration case study
=> https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig Microsoft Azure Strangler Fig guidance
=> https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html AWS prescriptive guidance on the Strangler fig pattern
=> https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-routes.html Amazon API Gateway HTTP API routes

=> https://engineer.company/glossary/strangler-fig-pattern/ This page on the web
