Part 5 of 8 · 2 min read
The strangler pattern
Replace a system piece by piece behind a front door.
Sometimes the old system cannot be easily taken apart, for example a bought product or a very old application. The strangler application pattern handles this. Put a new layer in front that intercepts the calls. For each kind of call, the layer decides whether to send it to the old system or to new code. Over time more calls go to the new code, and the old system is retired without a big-bang rewrite.
Strangler application pattern
The strangler application pattern puts a new front layer ahead of an old system. It routes each request to old or new code, and moves requests across one by one until the old system can be switched off.
Example: a proxy sends /search to the new search service and everything else to the old application.
BM names a close relative: a façade service. In one project, a CRM (a system for managing customers) owned the idea of a "project", and many other systems used it. The team made a project service that offered projects as REST resources. Other systems moved their connections to it. Inside, the service only hid the CRM. When the day came to leave the CRM, each façade could be looked at in turn and given a new home, either custom code or a product.
With microservices the front layer may be several services and not a single application. Capturing and redirecting calls then gets harder, and BM notes that a proxy may be needed. BM also records a warning from a project using a strangler as a proxy, where a bug caused wrong cache headers to be passed through. The proxy has real power over traffic, so it needs care and tests.
A worked example (made up). A shop has an old application that does search, cart and checkout. A proxy is placed in front. Week 1: all traffic goes to the old one. Week 3: 5 percent of search calls go to the new search service as a trial, and the proxy compares results. Week 6: all search goes to the new service. Cart and checkout still go to the old one. Each move can be undone by changing one routing rule.
Check yourself: 1. What decides where a request goes in a strangler? 2. How is a façade service different from the strangler layer? 3. Why is the proxy itself a risk?