Legacy code refactoring: get back to changing your system with confidence, while the roadmap keeps moving

Our legacy code refactoring consultancy brings very senior extreme programmers into your codebase. They work alongside your team on the system in production and make it easy to change again, one step at a time, without pausing feature delivery.

The software works, but every change costs more than the last

Companies usually come to us when the product sells and the team is capable, yet every change to the system takes weeks and brings a regression or two, to the point where nobody can say with confidence when a feature will be ready.

  • Every feature takes longer than the one before, and estimates have stopped holding
  • A small change breaks something in a distant part of the system
  • There are modules the team avoids touching, and only one or two people really know them
  • Automated tests are few, so every release waits on long rounds of manual checking
  • A product change forces you to touch many modules unrelated to it
  • The team talks about rewriting everything

That friction hits hardest on the changes that matter to the business, which cost more every month and get harder to predict.

Incremental refactoring, inside your own code

Legacy code refactoring changes the structure of a system in production while leaving its behaviour unchanged. It proceeds in small steps protected by tests, until modifying the system is ordinary work again. We work on the code that ships every day, with no parallel copies, while your team keeps releasing. Every step is reversible and leaves the system working and easier to change than before.

Your system embodies years of domain knowledge, including edge cases nobody remembers handling. An incremental path keeps that knowledge, because it touches one piece at a time and the tests make it explicit. A rewrite has to rebuild it from scratch, and usually at a higher cost than planned.

The first measurable progress comes after at least three to six months, and we say so before we start. The full programme takes longer, depending on how much debt there is and where it sits, and the exit plan sets out the conditions for finishing from day one.

Two modes, chosen according to the damage

Technical debt hurts more in some areas of the system than in others, so we work in two modes and choose between them once we have measured it.

The main mode

Focused team

When debt is blocking delivery in central areas of the product

A pair of QMates developers joins a few developers from your team, and together they form a small team with a specific goal: to get delivery moving again in the area where it is stuck today. By working on the code, the focused team passes the techniques on to the rest of your team, who see them applied to their own system before using them themselves.

The light-touch mode

Opportunistic refactoring

When the damage is contained and the system still keeps up with the pace of the product

Teams keep shipping features and, before adding one, improve the code that feature has to touch. Refactoring follows the roadmap, concentrates where the product is heading and stays inside everyday work, with no separate budget or schedule.

Which of the two modes you need is decided by the technical debt assessment, the first step of the programme. It measures where the debt really bites and how much damage it is doing, and from there we decide whether you need a focused team or whether opportunistic refactoring is enough.

The techniques we use, and what they are for

Anyone who has worked on legacy code for years knows them all. The result depends on the order in which they are applied and on how you choose where to start.

  1. 01

    Characterisation tests as a safety net

    Before changing a part of the system, we pin down its current behaviour with tests that describe it as it is, bugs included. These tests flag straight away any change that alters behaviour unintentionally, and they let us work on code nobody has fully understood yet. Michael Feathers describes them in Working Effectively with Legacy Code; for us they are the prerequisite for everything else.

  2. 02

    Hotspot refactoring

    Debt is paid down where the code changes often. We cross-reference change history with code complexity and start from the hotspots, the few areas where complexity and change frequency add up. A complicated module nobody has touched in years can stay as it is.

  3. 03

    Module boundaries and coupling

    When one product change runs through ten modules, the flaw lies in the boundaries. We make them explicit, reduce the dependencies that cross them and move responsibilities to where the domain places them, until a change touches one place only.

  4. 04

    Strangler Fig for the monolith

    When part of the monolith has to be replaced, the switch happens in stages. The new code grows alongside the old code behind a clear boundary and takes over one function at a time, with the monolith still running, until the old code can be switched off.

  5. 05

    Architecture only where it is needed

    We intervene on architecture when a structural constraint stops the product from evolving, and only at that point. We propose microservices, events, new layers or a cloud migration when they resolve that constraint; often a modular monolith with clear boundaries is enough, and holds up well for years.

How we measure progress

At the start of the programme we agree a few metrics with you, tied to whatever costs too much today, and we track them over time. Which ones we pick depends on the system and on what is holding the business back. For example:

  • lead time for changes
  • regressions reaching production
  • how long a release takes
  • the time between deciding to build a feature and its arrival in production

Numerical targets are set after we have seen the code. The metrics start on day one, so that progress, or the lack of it, is visible to everyone.

Your team carries on without us

A successful refactoring leaves code that is easier to change and a team that knows how to keep improving it. The techniques pass to the team while we work together, pairing on real code, and our presence shrinks as the team uses them on its own. We step in where change costs most and stop when the team can carry on.

The exit plan is decided at the start

  1. 01We agree which skills the team must keep and how we will know it has kept them
  2. 02We reduce QMates' presence in stages, as the team takes over the areas already refactored
  3. 03We leave behind tests, boundaries and metrics the team can read and maintain
  4. 04We close when refactoring has become part of everyday work

When we advise against a rewrite, and when we don't

The question we hear most often is whether the system should be rewritten. Almost always we say no, because a rewrite costs more than it appears to: besides the features, it has to rebuild the knowledge hidden in the existing code.

We advise against a rewrite when

  • the system is in production and generates value, even if changing it is hard work
  • the problem is concentrated in a few areas of the code
  • the main problem is a lack of tests or knowledge, which a rewrite leaves untouched
  • the business cannot afford months of frozen features or two systems to maintain in parallel

We consider a rewrite when

  • the technology no longer receives security updates and has become a risk to service continuity
  • coupling is so pervasive that no part can be isolated, and every change persistently costs more than the value it brings
  • the business changes radically (a new model, an acquisition, a new platform) and the existing system no longer serves it, whatever its quality

Even then, replacement happens piece by piece, with the Strangler Fig. We have gathered the variables to weigh before deciding in our guide to when to live with legacy software, when to evolve it and when to rewrite it.

The time is right if

  • The product is growing and the code slows down every new feature
  • You are weighing a rewrite and want to know whether a less risky route exists
  • You have inherited a legacy system that the team struggles to understand and modify
  • Technical debt always loses priority to features, and meanwhile keeps growing

When the problem is a single technical problem, urgent and well bounded, the fastest route is Targeted Intervention.

If the team also needs to bring TDD and refactoring into its everyday work on new code, technical coaching in XP and TDD works alongside this service. If it is unclear where the boundaries between the parts of the system should run, architectural refactoring starts by mapping the domain with Domain-Driven Design and EventStorming.

Frequently asked questions

Do you also work on code without tests?
Yes, and it is the most common case. We start with characterisation tests, which pin down the system's current behaviour, bugs included, and become the safety net for changing it before every detail is understood. The tests grow alongside the refactoring, starting from the areas touched most often.
Do you write code, or do you run training?
We write code in your repository, pairing with your developers on real features and refactoring, and the techniques pass to the team as we work. When a dedicated training session is needed, we run it alongside the work on the code.
How does refactoring fit with feature development?
Refactoring happens inside delivery, in parallel with features. With opportunistic refactoring you improve the code the next feature has to touch; with a focused team you unblock one area while the rest of the team keeps releasing. Either way, the roadmap keeps moving.
Do you also work on monoliths?
Yes. Often it is enough to make the monolith modular, with clear boundaries inside it. Where a part really has to be replaced we use the Strangler Fig. The new code grows alongside the old code and takes over one function at a time while the monolith stays in service.
How long does a legacy code refactoring programme last?
The first measurable progress comes after at least three to six months. The overall duration depends on how much debt there is and where it sits, and the exit plan, with the conditions for closing, is defined at the start.
Where do we start?
With the technical debt assessment, which produces a map of the debt with priorities and an action plan, and also tells you which refactoring mode you need. If the team prefers to take that plan forward on its own, it can.

Do any of these sound familiar?

The situations that usually bring people to this service, with their likely causes.

Does legacy code slow down every new feature?

We start with a first conversation. You tell us about the system and we tell you whether an assessment is the right place to begin

We use your data to respond to your request. Read our Privacy Policy.