← All articlesArchitecture and quality

Modernising a legacy system: rewrite from scratch or rebuild step by step

An old system that is hard to develop confronts a company with one question: rewrite it from scratch or rebuild it step by step? I usually recommend the second path, and clients usually choose it too. It is not always possible, though. Here is how I make that decision and how to keep the system running normally while it changes.

Why usually step by step

A step-by-step rebuild has one huge advantage: the system keeps working the whole time, and results are visible after every stage. There is no big switchover day when everything has to work at once. The risk is spread over many small steps, each of which can be rolled back.

When step by step is not possible

Some monolithic systems are so unstructured that it is extremely hard to take anything out of them while keeping the rest working. Every module is tied to every other, and a change in one place breaks something somewhere else entirely. In that situation, building a new system alongside the old one can be cheaper and safer than trying to untangle it.

How to keep the system running during the rebuild

  1. Start with tests of current behaviour. Before changing anything, we capture in tests how the system works today, including the places where it behaves oddly. That is our safety net.
  2. One entry point to the system. User and integration traffic passes through a layer that decides whether a given function is handled by the old or the new code. This lets us move functions one at a time, and users see no difference.
  3. Start with the area that blocks development most. The first extracted piece should bring real benefit, not just be the easiest to move.
  4. Switches instead of a big-bang release. We first enable the new version of a function for some users. If something does not work, we go back to the old version with one switch.
  5. Data in both places. During the transition, data is synchronised between the old and the new system so both have an up-to-date picture.
  6. Monitoring from day one. We compare how the new and old versions behave before the old code is switched off.

The same principle applies when building a new system alongside the old one: we move users and functions over in stages and switch off the old system only once nothing uses it any more.

Let’s talk about your project

Tell us briefly what you want to build or fix.