microservice.guru
← All posts

The Distributed Monolith: Symptoms and the Way Out

· Architecture · Microservices · Coupling · Deployment

By Alain Cyr, Founder, Koesion

microservice.guru — The distributed monolith. A grid of services, every one linked to its neighbours, shipped as one release.

You can usually tell from the release calendar. Fourteen services, and every second Thursday all fourteen go out together, in a fixed order, following a spreadsheet that one person maintains and everybody fears.

That is a monolith. It just has a network in the middle.

What the name means

A distributed monolith is a system that is deployed as many services but cannot be changed, released or broken one service at a time. You pay the whole price of distribution, with the latency, the partial failures and the fourteen pipelines, and you get none of the independence that was supposed to come with it.

On paper, six independent services. In practice, the same six tied together by a shared library, a shared schema and chains of calls

The architecture diagram on the wall is the left half. Production is the right half.

Nobody sets out to build one. It grows out of small, sensible shortcuts, and that is why it helps to have symptoms you can count instead of an opinion to defend.

Six symptoms

Lockstep releases. A feature needs services A, B and C deployed, in that order, the same evening. Look at your last ten releases and count how many shipped exactly one service.

Shotgun changes. Adding one field to a claim means a pull request in four repositories. Take the last ten features and count the repos each one touched. Three or more, routinely, and your boundaries are in the wrong place.

A shared schema. Two services read or write the same tables. I covered this one in Database per Service, and it is nearly always present when the others are.

A shared domain library. Somewhere there is a common-model package with a Policy class that every service imports. Bump its version and everyone has to rebuild and redeploy. It looked like reuse. In practice it is a compile-time dependency between teams.

Long synchronous chains. One user request passes through six services, each waiting on the next. The arithmetic is unkind.

Six services in a synchronous chain, each available 99.9% of the time, give 99.4% for the request: about 4 hours 19 minutes of failure a month instead of 43 minutes

Each team hits its target. The user gets six times the downtime.

Nothing runs alone. To test one service on a laptop you need eleven others running, so nobody does, and everything waits for a slot in the shared integration environment.

Scorecard of the six symptoms, each with something to measure and the threshold at which to worry

An afternoon of work, and it replaces a month of debate about whether you “really” have microservices.

How it got this way

Nearly always, the services were cut along nouns or technical layers: a User Service, an Order Service, a Notification Service. A business change then crosses all of them by construction. The longer version is in How to Find Your Microservice Boundaries.

The rest is ordinary deadline pressure. The join was faster than the API call, the shared class was faster than agreeing on a contract, and the synchronous call was faster than thinking about what happens when the answer comes late.

The way out

There is an order to this, and it starts with measuring rather than refactoring.

Five steps: measure which services change together, merge those that always do, shrink shared libraries, give each table one owner, cut synchronous chains

Step 2 is the one people resist, and the one that pays back fastest.

Measure co-change. Your version control history already knows which services change in the same week for the same ticket. Pull that out. Pairs that change together nine times out of ten are your real modules, whatever the repo layout says.

Merge what always moves together. If two services have never once been deployed separately, they are one service that costs twice as much to run. Merging them is not a retreat. I would rather operate six services that deploy alone than fourteen that cannot.

Shrink the shared library. Logging, tracing, an auth client: fine. A shared Policy class: no. Each service keeps its own, smaller idea of a policy, containing the fields it uses. This feels like duplication, and it is the cheap kind.

Give each table one owner. One writer first, then no foreign readers.

Cut the chains. Wherever the caller does not need the answer to continue, publish an event or keep a local copy. Where it does, keep the call and put a timeout on it.

Do these in order. Teams that start at the bottom, by introducing a message broker, tend to end up with the same coupling and a new piece of infrastructure to operate.

The test of a microservice is not its size. It is whether you can deploy it on a Tuesday afternoon without telling anyone.

Where to go next

References