Saltar al contenido ForoHackers

Replacing a legacy system without a big bang: the strangler pattern

Mantenimiento y código heredadoRefactorizaciónArquitectura de software
#1161 · legacy_cobol_whisperer · · Denunciar

Every "rewrite from scratch" proposal I have seen has the same shape: eighteen months of work, a cutover weekend, and a list of behaviours nobody knew the old system had. The old system carried years of corner cases in code nobody remembers writing.

The pattern I keep recommending is the strangler approach, named after the vine that slowly replaces its host tree:

  1. Put a thin layer in front of the old system (a proxy, a router, an API gateway). All traffic goes through it, and at first it just passes everything on.
  2. Pick one slice of functionality, small enough to finish in weeks. Build it in the new system.
  3. Route that slice to the new code. Keep the old path available as a fallback for a while.
  4. Compare: run both and diff the results (shadow mode) before you flip the switch. The differences are the unknown behaviours.
  5. Retire the old slice and move to the next.

What makes it work: the system is always in a shippable state, each step can be undone, and you learn the real behaviour gradually instead of all at once.

What goes wrong: the shared database. If old and new both write the same tables, you need a clear rule about who owns what, otherwise the "strangling" turns into a long argument about which system is right.

And remember that the goal is not a new system. The goal is to switch off the old one. If the old one is still running two years later "just in case", you built a second system and kept the first.

#1955 · LaAbuelaDelCOBOL · · Denunciar

Muy de acuerdo con lo de la base de datos compartida. Yo he visto "migraciones por fases" que duraron tanto que las dos mitades acabaron dependiendo la una de la otra. Hay que ponerle fecha de apagado desde el principio, o el sistema viejo se queda para siempre.

#1956 · race_condition_rita · · Denunciar

Shadow mode deserves its own post. The failure model matters: if the new path is called synchronously, a hang in the new code now hangs the old flow. Fire and forget, with a timeout and a log of the diffs, or you have created a new outage to measure the old one.

#1957 · pls_no_more_yaml · · Denunciar

And please keep the routing rules in something reviewable. I have inherited a strangler whose routing table was 900 lines of YAML nobody dared edit. The vine ate the gardener.

Inicia sesión o únete para responder.