Digital Transformation

Modernising a legacy application in stages

Full rewrites are tempting because old code is painful. They are also risky: the business keeps changing while the new system chases a moving target, and years of undocumented behaviour have to be rediscovered. Replacing a system in stages, with the old one still running, is usually the safer route.

By BuildQore · · 3 min read

The strangler fig approach

The pattern takes its name from a vine that slowly grows around a tree. A routing layer sits in front of the legacy application. New or rebuilt features are served by a new service, and everything else continues to reach the old system. Each slice moves when it is ready, and users never face a single big switch.

01 of 05

Map

List what the system does, who depends on it, and which parts cause the most trouble.

Each slice follows the same cycle, so risk stays small and progress stays visible.

Choosing the first slice

Do not begin with the most critical module, and do not begin with something so trivial that it teaches you nothing. Look for an area with clear boundaries, real business value and few dependencies. A reporting screen or a self-contained settings area is often a good choice. The first slice proves the routing, deployment and monitoring path that every later slice will use.

Routing traffic

The routing layer can be simple. In this nginx example, one path is served by the new application and everything else still reaches the legacy one. Rolling back means removing a single block and reloading the configuration.

nginx.conf
upstream legacy { server legacy.internal:8080; }
upstream modern { server modern.internal:3000; }

server {
    listen 80;

    # Migrated: invoices now live in the new service
    location /invoices/ {
        proxy_pass http://modern;
    }

    # Everything else still reaches the legacy application
    location / {
        proxy_pass http://legacy;
    }
}

Data is the hard part

Moving screens is straightforward compared with moving data. For a while, both systems may need the same records. Pick one owner for each piece of data at every stage, and let the other system read through an API or a synchronised copy. Writing to two databases from application code looks simple, but it fails in awkward ways when one write succeeds and the other does not.

  • Give each table or entity a single owner during migration.
  • Add reconciliation reports that compare old and new records.
  • Rehearse data migrations on a recent, anonymised copy of production data.
  • Keep the old data readable until the business confirms it is no longer needed.

When a rewrite is reasonable

Staged replacement is not always right. A small application with few integrations, or one built on a platform that is no longer supportable, may be cheaper to replace outright. The honest test is to ask how long the old system must keep running during the change, and what happens if the project takes twice as long as planned. If the answer is uncomfortable, go in stages.

Keep reading

All articles

Get new articles by email.

Occasional notes on building and testing software. No filler.

Used only for these updates. See the privacy policy.

Want this done on your project?

Tell us what you are building or fixing, and we will talk through how we could help.