Product
|
Cloud costs
|
released
April 26, 2021
|
3
min read
|

Strangler Pattern: How to Deal With Legacy Code During the Container Revolution

Updated

When we say “technical debt,” what’s the first thing that comes to your mind? Is it the accumulation of code in an outdated system that’s seen changes from tens, or even hundreds, of developers over the years? Is it a codebase with poorly-written methods following convoluted logic and hard-to-follow patches for production issues? It’s both, really.

Technical debt is bound to accumulate at every company, whether it’s a mammoth Enterprise or a bright-eyed AI-Machine-Learning-Blockchain startup. There will always be tasks that we could (and probably should) do to improve software quality. Any time we choose not to do them, whether to save time or money or because we just have to deploy something, we contribute to our technical debt.

Before you know it, you might find yourself preparing to transition a massive, complex monolith application to Microservices and realize that you have no idea where to start and there’s no one left at the company that knows how the foundational code of the software works.

That’s when the Strangler Pattern might come in handy.

What is the Strangler Pattern?

While on a trip to Australia in 2004, Martin Fowler witnessed a peculiar tree and came to a new understanding of how outdated applications can be updated.

“One of the natural wonders of this area [Australia] is the huge strangler vines. They seed in the upper branches of a fig tree and gradually work their way down the tree until they root in the soil. Over many years they grow into fantastic and beautiful shapes, meanwhile strangling and killing the tree that was their host.”

Similar to the way fresh and new vines replace the original base of the tree, new code is written around the edges of the outdated system in such a way that the old system is eventually “strangled” and replaced by the new one.

Legacy code is harder to maintain, and it’s time to understand how we can dig our way out of the hole that our previous selves dug us into. Replacing code that’s not working as it should is a difficult, and sometimes dangerous, a task that could lead to the application behaving differently or, worse, breaking entirely. We need to replace the old with the new, but we need to do it the smart way.

The good news is that it’s possible, through a graduate process in which we rewrite the old code, run the new code in parallel, test the environment and make sure everything is working as it should.

Microservices to the Rescue?

With Microservices, different sections of the application are separated and encapsulated, each with its own logic, data, structure, and so on, and perform a specified function.

This “buzzword” has been around for a while, and companies are adopting and adapting the new elements that come with it. It’s no wonder, considering it brings a lot of benefits into our workflow and builds methods including shorter development times and increased flexibility.

Unlike monolithic architecture, microservices make it easier for us to understand, develop and test individual elements of the main product, and it helps make each part much more resilient to architectural erosion.

Microservices allow us to redesign and rewrite critical elements within a codebase in parallel to the old methods and code that are currently in use. In return, it’s easier to control the gradual transition from the old to the new, ensuring that the application is still up and running as expected.

There are a few essential benefits microservices introduce into our workflow. The first one is that it prevents our monolith structure from becoming even more unmanageable. The second benefit is that it helps dev and Ops teams move forward with certain elements within the application or product faster, without relying on other teams or areas to finish or deploy their changes.

Microservices can also improve the build-test-deploy-monitor cycle. They allow teams to complete this cycle for individual elements within the application much faster, without having to wait for testing or deploying other features. You can iterate faster.

However, it’s not all sunshine and rainbows in the microservice architecture, and there are a few downsides that come when switching to this method. One of the most critical elements we need to remember when moving toward a microservice architecture is: with distributed systems comes distributed…everything

There are quite a few problems we’re likely to face both during and after the transition to microservices. One of the biggest is monitoring. We now have an entire application that lives on “containerized” services. Each service can use its own language, and technology, live on a different machine or have different version control, and it’s up to our teams to monitor and identify issues as they occur.

Luckily, APMs will still tell us when performance drops and where, and logs will still tell us about issues we foresaw. Everything beyond that gets much more complicated though. Not only do we need to understand in which machine, container, or server this issue happened, but we also need to be able to understand the path the code took to get there and how other services may be involved.

While it might sound like a knock against microservices, it doesn’t mean that we shouldn’t make the move. It just means that we need to be aware of these challenges and that we need to consider new capabilities we’ll require when setting up the monitoring for our environment.

Final Thoughts

The industry’s move towards Microservices is well underway, but teams with a lot of technical debt or massive legacy codebases may find themselves unsure of where, or how, to start. Adopting the Strangler Pattern as a design framework can help during the transition and continue to help keep your application up, running, and optimized as your software grows and advances.

Whether you’re dealing with legacy code or beginning the process of “strangling” your old system or running a newly containerized application, you need to understand the quality and reliability of your system. When something goes wrong, you need to understand what path the system took to get there and why.

Sign up now

Sign up for our free plan, start building and deploying with Harness, take your software delivery to the next level.

Get a demo

Sign up for a free 14 day trial and take your software development to the next level

Documentation

Learn intelligent software delivery at your own pace. Step-by-step tutorials, videos, and reference docs to help you deliver customer happiness.

Case studies

Learn intelligent software delivery at your own pace. Step-by-step tutorials, videos, and reference docs to help you deliver customer happiness.

We want to hear from you

Enjoyed reading this blog post or have questions or feedback?
Share your thoughts by creating a new topic in the Harness community forum.

Sign up for our monthly newsletter

Subscribe to our newsletter to receive the latest Harness content in your inbox every month.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Service Reliability Management