Moving to Microservices

A new system should not start as microservices. Martin Fowler made this argument in 2015 and called it “monolith first”. At the start, we do not know yet whether the product will succeed, so we want to build it quickly, and we do not want to pay the costs of microservices yet. We also do not know yet where the right boundaries are. If a boundary is inside one application, moving it is a change to the code. If a boundary is between two microservices, moving it means changing contracts, moving data from one service’s database to another’s, and getting two teams to agree.

So we start with one application, or with a few coarse services, as we did for Shopend. We move to microservices when many teams work on one system and they get in each other’s way every time they release.

The strangler fig pattern

The obvious way to move is to write the new system next to the old one and switch over on one day. This is risky. While the new system is being built, the old one keeps running and keeps changing, so the new one has to catch up with those changes. And on the day of the switch, every problem in the new system shows up at once.

The other way is to move one piece at a time:

  1. Put a gateway in front of the old system, so that every request goes through it.
  2. Build one capability as a new service.
  3. Change the gateway, so that the requests for that capability go to the new service. Every other request still goes to the old system.
  4. Repeat with the next capability.

The old system handles fewer requests after each step. When the gateway sends no requests to it, we turn it off. This is called the strangler fig pattern. Martin Fowler named it after the strangler figs he saw in the rain forests of Queensland, Australia, in 2001. A strangler fig is a vine that grows around a tree. Over time the vine can stand on its own, and the tree inside it may die.

We have already taken one step of this pattern. We moved the registrar’s API out of the registrar’s application into a service of its own, and the gateway sent the API’s requests to it while the application kept running.