Skip to content

Modernising an application step by step while it stays in use

An application that has grown over the years carries day-to-day business. Stopping it for a year to rewrite it is rarely possible and even more rarely wise. The alternative replaces it piece by piece while it keeps running — and follows its own rules.

  • Who it is forBusinesses, project leads, developers
  • LevelIn depth
  • Reading timeabout 10 minutes
  • Last updated24 October 2026

What you will learn

  • Why a complete rewrite often takes longer than planned
  • How to capture today’s behaviour before you change it
  • What seams are, and how old and new code run side by side
  • In which order to replace areas — and when a stage is finished

The answer first

Modernise in small stages that can each be deployed on their own. For every area, first capture today’s behaviour in tests, then create a seam at which old and new code are interchangeable. The new part runs alongside the old one for a while, until it demonstrably does the same thing. Only then do you switch over — and delete the old part.

Martin Fowler named this approach after the strangler fig, a plant that slowly grows around a tree and eventually replaces it. The application stays in use the whole time, and each stage delivers value on its own.

Why the big rewrite so often takes longer

The plan “we will build it all again, just modern” sounds tidy. Fowler names the obstacles it usually runs into in practice: replacing a serious system takes a long time, and users cannot wait that long for new features. Existing behaviour is hard to specify completely, because much of it is written down nowhere. And some of that behaviour is no longer needed at all — rebuilding it one to one is wasted work.

Then there is an effect anyone who has accompanied a rewrite will recognise: while the new system is being built, the old one still has to be maintained. Every change is made twice, or it is postponed “until the new one is ready”.

Whether an application can be renewed step by step at all is settled beforehand by an inventory; how that works is described in Taking over existing PHP software. This article starts after that: the decision for the gradual route has been made, and the question now is how.

First, capture today’s behaviour

Before an area is rebuilt, it has to be clear what it does today — not what it ought to do. That is what characterisation tests are for, a term from Michael Feathers’ book “Working Effectively with Legacy Code”. You call the existing code with typical cases and edge cases and record the actual result as the expectation, even if it looks odd.

Such tests do not judge; they only report when something changes. If a result turns out to be plainly wrong, it is noted and the business side decides whether to correct it — separately from the rebuild. Doing both in one step means that afterwards nobody can tell whether a difference was intended. The distinction is described in Bug or change request.

  • For calculations: inputs from real, anonymised cases and today’s results.
  • For pages and interfaces: stored responses to defined requests.
  • For exports: a reference file against which every new output is compared.

Seams: where old and new can be separated

A seam is a point at which behaviour can be swapped without changing the surrounding code. In an application that has grown over time, seams often have to be created first. Typical candidates:

  • An interface in the code: the calling code only knows the description “calculate shipping costs”, not the implementation. Behind it, the old class can be replaced by a new one. Fowler calls this branch by abstraction.
  • A URL: a router placed in front sends individual paths to the new part already, and all others to the old one.
  • A background process: an export or import can be replaced as a whole, because it has a clear start and a result that can be checked.
  • A system boundary: where data is exchanged through an API, one side can be rebuilt without the other noticing.

The code the transition needs — redirects, comparison layers, switches — is not waste. Fowler calls it transitional architecture and points out that the reduced risk and earlier value outweigh its cost. It simply has to be planned as temporary from the start.

Old and new side by side for a while

Once the seam is in place, the new part is built and first used in shadow mode: both parts calculate, users still receive the old result, and differences are logged. Real operation then shows whether the new implementation does the same thing, without an error affecting anyone.

PHPPHP 8.3 to 8.5 · excerpt, tested with PHP 8.3, 8.4 and 8.5 CLI
// Shadow mode: answer with the old result, compare with the new one, log differences.
final class ShadowShippingCost implements ShippingCost
{
    /** @var list<string> */
    public array $differences = [];

    public function __construct(private ShippingCost $old, private ShippingCost $new) {}

    public function forOrder(int $weightGrams, string $country): int
    {
        $expected = $this->old->forOrder($weightGrams, $country);
        $actual = $this->new->forOrder($weightGrams, $country);
        if ($expected !== $actual) {
            $this->differences[] = "{$weightGrams} g {$country}: old {$expected}, new {$actual}";
        }
        return $expected; // users still get the old answer
    }
}

$cost = new ShadowShippingCost(new LegacyShippingCost(), new TariffShippingCost());
$cost->forOrder(2000, 'DE');
$cost->forOrder(5000, 'DE');
$cost->forOrder(7500, 'AT');
echo implode(PHP_EOL, $cost->differences ?: ['no differences']), PHP_EOL;
The old and new shipping cost calculations sit behind the same ShippingCost interface (not shown in the excerpt; amounts in cents). Output of the full script: 5000 g DE: old 490, new 790 — the new version differs exactly at the 5 kg boundary. Shadow mode finds edge cases like this before a customer does.

Shadow mode suits calculations and read access. Where the new part writes data, sends e-mails or calls other systems, it may only pretend in shadow mode — otherwise everything happens twice.

The switch itself is best made with a feature toggle that can be reversed without a new deployment, at first for some users or locations only. Pete Hodgson’s article on martinfowler.com describes how such toggles tend to multiply and carry an ongoing maintenance cost; some teams therefore create the task for removing a toggle as soon as they add it. The same applies here: once the new part is established, the toggle, the comparison layer and the old code are deleted.

A hypothetical example

An order management system in four stages

An order management system that has grown over several years is to be modernised. Instead of a rewrite, the team defines four stages, each of which can be deployed on its own:

  1. Delivery note generation is moved behind an interface and switched to a maintained PDF library. Reference files show that the content stays the same.
  2. Price calculation gets characterisation tests, then a new implementation in shadow mode. After two weeks without unexplained differences, it is switched over.
  3. The order list is built as a new page, and a router redirects its URL. The old list stays available until staff are comfortable with the new one.
  4. Only at the end is the order data storage changed, with a planned migration.

The application is running at every point, and each stage brings a visible benefit. Leaving data storage until last is deliberate: as long as old and new code use the same tables, the way back stays simple. How such a change is planned is covered in Planning a data migration.

In which order?

There is no universal order, but there are useful criteria:

  • Small and well-bounded first. The first stage should test the approach and build trust, not solve the biggest problem.
  • Where changes happen most often. An area touched every month pays back the work faster than one that has been dormant for years. How to measure this is explained in Prioritising technical debt.
  • What is due anyway. An unsupported PHP version or an abandoned library sets a deadline; see Upgrading the PHP version.
  • Mind the dependencies. Whatever many other parts rely on is replaced only once a seam stands in front of it.

An end point matters just as much. For each stage, agree beforehand when it is finished: when the old code has been deleted, not when the new code is running. Without that rule you end up with two applications, both of which need maintaining.

Limits and typical mistakes

  • Transitional code that stays. Toggles and comparison layers that are never removed leave the application more complicated than before.
  • Stages with no benefit for the business. Purely technical rebuilds lasting months lose support within the organisation. Every stage should improve something that someone notices.
  • Shared data underestimated. If the old and new parts interpret the same data differently, errors arise that neither part shows on its own.
  • No structure to build on. If not a single usable seam can be created, a planned rewrite may be the cheaper route. That is rare, but it happens.

If you are facing this decision, we support you in modernising PHP software that has grown over time — from the first seam to deleting the old code.

Common misconceptions

Until the very end, perhaps. But the first benefit arrives after the first stage, not on the last day of a large project — and every stage can be checked on its own.

Quite the opposite: new features are built straight into the new part. That is one of the reasons for taking the gradual route.

They record what is, so that changes become visible. Whether a result gets corrected is a separate, deliberate decision.

Further sources

About the author

Fabian Lücker is managing partner of PHP Schmiede KG in Rheine and has worked in software development since 2007. He is responsible for development and design, and writes here about decisions that come up in real projects.

Should your application become more modern without standing still?

Describe which areas cause the most effort today. We will suggest a first stage that can be checked on its own.