Skip to content

Microservices: when they pay off and when they slow your team down

B2Bnetwork team · · 6 min

Technology and trends

In brief

Microservices pay off when several teams need to release changes independently and parts of the system have different scaling, availability or security requirements. They slow a team down when there are more services than teams, services share a database, or every change requires a joint release of several of them. Before you extract the first service, you need automated deployment, monitoring and contract tests. Without them you pay the cost of a distributed system and get none of its benefits.

What microservices are and what they really cost

Microservices are an architecture style in which a system is made of small services deployed independently. Each service owns one business area, keeps its own data and talks to others through APIs or events. Microsoft's Azure Architecture Center describes the style in terms of autonomy: a service can be built, deployed and scaled without touching the rest.

That autonomy has a price that is easy to miss while drawing the diagram:

  • network instead of in-process calls: latency, timeouts, retries and partial failures;
  • data consistency: a transaction spanning several services becomes a saga with compensation paths;
  • operations: every service has its own pipeline, versions, alerts, secrets and on-call rotation;
  • troubleshooting: a single customer complaint means following a request through several services, so without distributed tracing nobody knows where the time went;
  • testing: API compatibility between services has to be checked separately, because no compiler enforces it.

We compare this with the alternative, a single application split into modules, in the article on the modular monolith. Here we focus on the decision: when the cost pays for itself.

When microservices pay off

The best signal is organizational, not technical. Microservices mainly solve the problem of several teams blocking each other on a shared release.

SignalWhat it showsDoes it justify microservices
Several teams wait for a shared release windowcoordination cost grows with every teamyes, this is the main reason
One area needs many times more instances than the restdifferent load profilesyes, for that area
The payments module must run in a separate network zone with a separate auditdifferent security requirementsyes, for that module
Calculations need a different language or runtimedifferent technologiesyes, as a separate service
One team, even loadno problem to solveno
“The code is unreadable”no boundaries in the codeno, start with modules

Look at the last row. Tangled code cut into services stays tangled, except that the calls now go over the network. Boundaries need to be sorted out first, ideally along business areas as in Domain-Driven Design.

When they slow you down: the distributed monolith

A distributed monolith is a system that is deployed like microservices but changes like a monolith. You can recognize it by a few symptoms:

  1. Joint releases. A change in the order service requires deploying the payment and shipping services at the same time, because a shared data model changed.
  2. A shared database. Several services read and write the same tables. Changing a column blocks everyone.
  3. Chains of synchronous calls. A user request passes through five services in sequence. If one fails, everything stops, and the response time is the sum of all of them.
  4. More services than people. A team of five maintains twenty services and spends most of its time on library upgrades, pipelines and configuration.
  5. A test environment nobody can stand up. To check one change, you have to run every service at once.

Each of these symptoms means you are paying for the network and operations without getting independence. The cure is sometimes to merge services that always change together into one larger service. That is a correction of the split to match the real team structure, not a step backward.

What has to exist before the first service

Extracting a service only makes sense once the team can deploy and observe it safely. The minimum list:

  • an automated pipeline from commit to production, with the ability to roll back a version without manual work;
  • observability: logs with a request ID, metrics and distributed traces;
  • API contract tests, so a change in one service does not silently break its consumers;
  • API versioning rules and a policy for deprecating old versions;
  • network failure handling: timeouts, retries with exponential backoff, circuit breakers;
  • an owner for every service, responsible for it after deployment too.

In larger companies these pieces come from a shared platform, which we cover in the article on platform engineering. Without one, every team builds them from scratch, and that eats up the gain from independence.

Moving gradually: the strangler fig pattern

Rewriting the whole system into microservices at once is a high-risk project with a long period without new features. The safer route is the strangler fig pattern described in the Azure Architecture Center: you put a routing layer in front of the old system and move one function at a time to a new service. The old code handles the rest until nothing is left in it.

An order that works in practice:

  1. Pick an area with clear boundaries and a real reason to extract it, for example product search with a different load profile.
  2. Separate its data: a separate schema first, then a separate database.
  3. Expose an API and switch one consumer to it.
  4. Verify it in production with part of the traffic, then switch the rest.
  5. Remove the old code, and only then pick the next area.

Every step needs reliable regression testing. A program in which API and contract test automation accompanied the extraction of online banking services is described in the API and contract testing in a microservices program case study.

Questions and answers

How many services is too many?

No single number fits every system. A good measure is the ratio of services to teams: if one team maintains many services that always change together, the split is too fine. A second measure is how much time the team spends maintaining infrastructure instead of building features. When that time grows with every new service, it is time to merge some of them.

Are microservices faster than a monolith?

Usually not for a single request, because a network call takes longer than an in-process call. What microservices let you do is scale only the area under load and isolate failures. Overall system performance depends on how many synchronous calls a single user request goes through and how caching and queues are designed.

Does every service need its own database?

Every service should own its data, and other services should not reach into it directly. That can be a separate schema on a shared server or a separate database. Shared tables read by several services are the most common cause of a distributed monolith, because changing the data structure then forces a joint release.

Where do we start if we already have a distributed monolith?

With a map: which services are always deployed together, which share tables and which call each other in a chain. Consider merging the services that change together. Assign shared tables to a single owner and expose them through an API. Where possible, replace chains of synchronous calls with events or a queue.

What it looks like in a project

Considering a new technology for your system? Talk to an engineer.

Let's talk

Read more: Technology and trends