0% completed
The Architecture of the Strangler Pattern
On This Page
Replacing the System One Area at a Time
The Facade
Migration in Phases
A Small Example
Replacing the System One Area at a Time
The pattern replaces the legacy system one area of work at a time. An area of work is something like user accounts or billing. Each area is rebuilt, routed and checked on its own.
The Facade
The facade is the component that decides where each request is handled. Every request passes through it, so it is the single place where the migration is controlled.
When a request arrives, the facade checks whether that piece of work has been moved. If it has, the request goes to the new system. If not, it goes to the legacy system. The client sees one address either way, and cannot tell which system answered.
Migration in Phases
The move happens in steps rather than all at once.
It starts with a piece of work that can be separated cleanly. That piece is rebuilt in the new system and tested there. When it is ready, the facade starts sending those requests to the new system, and keeps sending everything else to the old one.
Each step is small enough to watch, and small enough to undo. That is the core of the pattern: routing rules in one place, changed one piece at a time.
A Small Example
Suppose an old system handles user management, and getUserDetails is the first piece to move. A router decides which service answers each call.
class UserServiceRouter: def getUserDetails(self, userID): if self.useNewService(userID): return NewUserService().getUserDetails(userID) else: return OldUserService().getUserDetails(userID) def useNewService(self, userID): # Logic to decide which service to use. # For simplicity, let's say we use the new service for even userIDs. return userID % 2 == 0 class OldUserService: def getUserDetails(self, userID): # Old way of fetching user details pass class NewUserService: def getUserDetails(self, userID): # New, improved way of fetching user details pass
The choice is made per user id, which sends about half the traffic to the new service. As confidence grows, useNewService is changed to cover more users, until OldUserService receives nothing.
Ishani Parashar
· a year ago
Here, they have used an interface to explain facade. How will be this done in an actual scenario? Do we introduce a middleware which decides how to navigate the traffic?
Reading Progress
0%
On This Page
Replacing the System One Area at a Time
The Facade
Migration in Phases
A Small Example