Strangler fig pattern explained

In programming, the strangler fig pattern or strangler pattern is an architectural pattern that involves wrapping old code, with the intent of redirecting it to newer code or to log uses of the old code. Created by Martin Fowler, its name derives from the strangler fig plant, which tends to grow on trees and eventually kill them.

The pattern can be used at the method level or the class level.[1]

Rewrites

One use of this pattern is during software rewrites. Code can be divided into many small sections, wrapped with the strangler fig pattern, then that section of old code can be swapped out with new code before moving on to the next section. This is less risky and more incremental than swapping out the entire piece of software.[2]

The strangler fig pattern can be used on monolithic applications to migrate them to a microservices architecture.[3]

Logging

Another use of this pattern is the addition of logging to old code. For example, logging can be used to see how frequently the code is used in production, which can be used to decide whether to delete low-usage code, or to rewrite high-usage code.[4]

See also

External links

Notes and References

  1. Book: Seemann, Mark . Code That Fits in Your Head: Heuristics for Software Engineering . . 2022 . 978-0-13-746440-1 . 228–237.
  2. Book: Newman, Sam . Monolith to Microservices: Evolutionary Patterns to Transform Your Monolith . . 2020 . 978-1-492-07554-7 . 79–97.
  3. Web site: Behara . Samir . 12 December 2018 . Monolith to Microservices With the Strangler Pattern . 12 March 2024 . DZone.
  4. Book: Clausen, Christian . Five Lines of Code: How and when to refactor . . 2021 . 9781617298318 . 206–208.