Lesson 8 of 8 Modernization Patterns

Modernising Incrementally with the Strangler Fig Pattern

This lesson explains how the strangler fig pattern replaces a monolith piece by piece behind a stable interface, so each step delivers value and can be rolled back, in scenarios where a full rewrite is too risky and slow.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how the pattern works.
  • Choose a routing layer.
  • Explain how data is handled during the transition.
  • Choose what to extract first.

How the pattern works

The strangler fig pattern replaces a monolith gradually. The pattern proceeds as follows.

  1. Add a routing layer

    Put a routing layer in front of the monolith so clients use one stable endpoint.

  2. Build one capability

    Build one capability as a new service.

  3. Route it

    Route that capability's requests to the new service; everything else still goes to the monolith.

  4. Repeat and retire

    Repeat until the monolith serves nothing, then retire it.

Deleting a route sends traffic back to the monolith, so every step is reversible.

Routing layer options

In the strangler fig pattern, a routing layer in front of the legacy system sends each request either to the old system or to a new service, and more routes move to new services over time until the old system can be retired. API Gateway routes by path and method and adds throttling, authorisation and usage plans; its private integrations reach on-premises or VPC backends through VPC links. An Application Load Balancer routes by path, host, headers and query strings. Weighted target groups move traffic gradually, and IP targets reach on-premises servers. CloudFront routes path patterns to different origins at the edge, through cache behaviours. The following table summarises the options.

LayerRoutes onNotes
API GatewayPath and methodThrottling, auth and usage plans; private integrations reach on-premises or VPC backends through VPC links
Application Load BalancerPath, host, headers, query stringsWeighted target groups move traffic gradually; IP targets reach on-premises servers
CloudFrontPath patterns per cache behaviorDifferent origins per path at the edge

The data problem

Routing is the easy part of the strangler fig; data is the hard part. The new service should own its data, but during the transition the monolith still reads and writes the same records. One approach keeps the monolith as the writer and uses change data capture, with DMS, to copy changes from the monolith's database into the service's store. Another makes the new service the writer: it publishes events that the monolith consumes, or a reverse synchronisation updates the old schema.

An anti-corruption layer translates between the monolith's model and the new service's model, so legacy concepts and naming do not leak into the new design. The most common mistake is to let new services share the monolith's database, which keeps them coupled: a schema change for one breaks the other, and neither can be deployed or scaled independently.

Choosing what to extract first

The first extraction teaches the team the pattern, so it should succeed. Good candidates have clear boundaries and few dependencies on the rest of the monolith, change often, so that independent deployment pays off quickly, or have scaling needs different from the rest, such as search or image processing.

The core transactional heart of the system, such as order processing in a retailer, is usually not the first candidate: it carries the most risk and the most dependencies. Experience gained on lower-risk capabilities makes its eventual extraction safer.

Worked example

A retailer's Java monolith on EC2 serves the website. The catalogue search must scale independently for seasonal peaks, and the team wants to move it to a new service without a big-bang release or changing URLs used by mobile apps.

Put an ALB (or API Gateway) in front of the monolith, add a path rule for /search/* to the new service, perhaps on Lambda or ECS with OpenSearch, and feed the search index from the monolith's database with CDC. URLs stay the same, the change is reversible, and search scales independently.

Check yourself

What is usually the hardest part of the strangler fig pattern?

Show answer

The data: the new service needs its own data while the monolith still uses the old database, so data must be synchronised or its ownership moved carefully.

Exam Tips

Remember for the exam

  • The strangler fig replaces a monolith capability by capability behind a stable routing layer.
  • API Gateway, ALB path rules or CloudFront behaviors provide the routing layer.
  • Deleting a route rolls traffic back to the monolith.
  • Give new services their own data; use CDC and an anti-corruption layer during the transition.
  • Avoid sharing the monolith's database with new services.