⬅ Previous Topic
API Gateway Pattern - System Design Explained for BeginnersNext Topic ⮕
Design URL Shortener⬅ Previous Topic
API Gateway Pattern - System Design Explained for BeginnersNext Topic ⮕
Design URL ShortenerThe Strangler Fig Pattern is a design strategy used in software architecture to gradually replace an old (legacy) system with a new one. Instead of rewriting the entire system in one go (which is risky and expensive), the new system is developed and integrated incrementally, while the old system is slowly "strangled" or phased out.
The pattern takes inspiration from the strangler fig tree in nature. This tree grows around an existing tree and eventually replaces it. Similarly, in software, the new system wraps around parts of the old system and eventually replaces them completely.
Many large-scale applications run on legacy systems that are difficult to change. They may be built on outdated technologies or have fragile codebases. Completely replacing them risks downtime and can be costly. The Strangler Fig Pattern helps mitigate that risk by allowing gradual and controlled migration.
Imagine you have an old eCommerce website written in PHP. You want to move to a modern microservices architecture using Node.js and React. Rewriting the entire platform at once could break things. So, you start small.
A routing layer (such as an API gateway or reverse proxy like Nginx) sits in front of the application. It decides whether to send user requests to the old PHP site or the new Node.js services.
You choose to migrate the "Product Listing" page first. You build the new version using React and Node.js, and deploy it under the same routing layer.
The routing layer is configured to send requests for /products
to the new Node.js service, while all other routes continue to go to the PHP backend.
You observe performance and user feedback. Once the new component proves stable, you migrate the next feature—say, the "Add to Cart" functionality—using the same approach.
Eventually, every major module is migrated, and the old system is no longer used. At that point, you decommission the PHP codebase entirely.
Answer: Rewriting an entire system is risky. You may introduce bugs, change business logic unintentionally, and require extended downtime. The Strangler Fig Pattern avoids these problems by allowing changes in small, manageable steps.
A bank’s legacy system written in COBOL handles customer transactions. But COBOL developers are hard to find, and maintaining this system is costly.
To migrate safely:
This allows developers to modernize while continuing to serve millions of users with minimal risk.
Answer: Since the migration is incremental, if something fails in the new service, it's easier to roll back or redirect traffic back to the legacy system temporarily.
The Strangler Fig Pattern is a safe and structured way to modernize legacy systems. Instead of throwing away the old system, you grow the new system around it, and gradually transition until the old system is no longer needed.
Answer: Yes. For example, you can gradually replace sections of a legacy UI with new components (e.g., React or Angular) while keeping the rest intact until you're ready to fully migrate.
⬅ Previous Topic
API Gateway Pattern - System Design Explained for BeginnersNext Topic ⮕
Design URL ShortenerYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.