Monolith vs microservices (and the modular monolith in between): how to choose

Microservices are not an upgrade from a monolith. They are a trade. Learn what each style really is, what each one costs, and why team size matters more than traffic when you choose.

Three buildings side by side. On the left, one big single block labelled Monolith. In the middle, the same block divided by thick inner walls into four rooms, User, Product, Order and Payment, labelled Modular monolith. On the right, four separate small houses joined by thin wires, each with its own little database barrel, labelled Microservices. A signpost underneath asks "How big is your team?".
Fig. 1 — One building, one building with walls, or a village of small houses. The right one depends on who lives there.

A team of twenty developers decides to split their app into microservices so they can “move faster.”

Six months later, they add a simple feature: let users save favourite products. In the old app, that was one developer, one pull request, one deploy, about two days.

Now it touches the User service (to store favourites), the Product service (to show a heart icon), the API gateway (a new endpoint) and the frontend. That is four pull requests in four repositories, deploys that must go out in the right order, old clients that must keep working, and a shared test environment that someone else is using. It takes six days.

They didn’t build anything wrong. They chose an architecture built for a different team.

The first big decision in any system is its shape: one deployable application, or many small services talking over a network? This guide explains the three main styles, what each one really costs, and how to choose.

Why this decision matters so much

How you split your code is not just a technical choice. It decides:

  • How fast your team ships, and how much they block each other.
  • How hard it is to onboard a new developer.
  • How your system fails, and how far one bug spreads.
  • Your cloud bill.
  • Your debugging experience at 3 AM.

And it is expensive to undo. Most startups that jump to microservices too early regret it. Most large companies that stay in one giant codebase too long regret that too. Timing is everything.

The three styles

Three panels. Monolith: one box holding User, Product, Order and Payment code, with arrows between them labelled function call, and one database below. Modular monolith: one box with thick walls between four modules, each with a small door labelled api, arrows only going through the doors, still one deploy and one database with separate schemas. Microservices: four separate boxes, each with its own database, connected by dashed network arrows labelled HTTP or messaging.
The real difference is not the number of boxes. It is whether parts talk by function call or over the network.

Monolith: one application, one deploy

A monolith is a single application that contains everything: users, products, orders, payments. One codebase, usually one database, one thing to deploy (a JAR file, a container, a binary).

When the order code needs a user, it just calls a method:

// Java · OrderService.java (monolith)
public Order createOrder(OrderRequest request) {
    User user = userService.getUser(request.userId());          // a method call, microseconds
    Product product = productService.getProduct(request.productId());
    Payment payment = paymentService.charge(request);
    return orderRepository.save(new Order(user, product, payment));
}

Everything runs in the same process. No network, no serialising data to JSON and back, and one database transaction can cover the whole thing: if the payment fails, nothing is saved. Simple.

“Monolith” sounds like an insult, but it isn’t. Stack Overflow served a huge part of the developer world from a small number of servers running one application. Basecamp is proudly a monolith. Shopify’s core is still one.

Modular monolith: one deploy, strong walls inside

A modular monolith is still one application with one deploy, but the code is split into modules with strict boundaries. Each module (users, orders, payments) has a small public API, and everything else inside it is hidden.

// Java · user module, public API (package com.shop.user)
public interface UserApi {
    UserSummary getUser(String userId);   // returns a small DTO, never the internal User entity
}

// Java · user module, internals (package com.shop.user.internal)
@Service
class UserService implements UserApi { /* hidden from other modules */ }

The order module may only talk to UserApi. It cannot reach into the user module’s tables or classes. So you get clean boundaries and teams that can own a module, but you keep the speed, easy debugging and single transactions of a monolith. And if one module really needs to become its own service one day, its seams are already cut.

Microservices: many small apps over a network

Microservices split the system into separate applications. Each one runs in its own process, owns its own database, is deployed on its own schedule, and can even use a different language. They talk over the network, with HTTP, gRPC or messages.

// Java · OrderService.java (microservices)
public Order createOrder(OrderRequest request) {
    User user = userClient.getUser(request.userId());            // network call, milliseconds, can fail
    Product product = productClient.getProduct(request.productId()); // network call, can fail
    Payment payment = paymentClient.charge(request);               // network call: did it charge or not?
    return orderRepository.save(new Order(user, product, payment));
}

It looks almost the same as the monolith. It is not. Every one of those lines is now a network call. Each can be slow, fail, or fail halfway. There is no single transaction across them any more. If the payment call times out, you don’t even know whether the customer was charged.

That one change, from function call to network call, is where almost all the cost of microservices comes from.

The trade-offs, side by side

Monolith Modular monolith Microservices
Speed, small team Fastest Fast Slow
Speed, large team Slow (people collide) Medium Fast (teams work alone)
Deploying Simple Simple Complex: many pipelines, orchestration
One bug takes down… Everything Everything Usually one service
Debugging One stack trace One stack trace Tracing across services
Speed of each call Microseconds Microseconds Milliseconds
Data consistency Easy: one transaction Easy: one transaction Hard: eventual consistency
Technology choice One stack One stack Any stack per service
Scaling Scale everything together Scale everything together Scale only the busy part

The honest summary:

  • Monoliths are faster to build at the start.
  • Microservices are faster to change later, but only if you have enough people to use that independence.
  • A modular monolith gives you most of the benefits for a fraction of the pain.
“Microservices don’t remove complexity. They move it from your code into your network.”

How to choose: start with your team

Here is the surprising part. The best predictor of the right style is usually not traffic. It’s team size and how complex the domain is.

Three rising steps. Step 1, under 10 developers, MVP or startup: monolith, because speed of building matters most. Step 2, 10 to 50 developers and a growing domain: modular monolith, because you need clear boundaries without a network. Step 3, 50 or more developers with clear separate domains: microservices, because independent teams outweigh the coordination cost. A side note lists other good reasons for microservices: very different scaling needs, different technology, regulatory isolation, fault isolation.
These numbers are rough guides, not laws. The question is always: is coordination hurting more than the network would?

Choose a monolith when:

  • you have fewer than about 10 developers, or you are building an MVP;
  • the domain is well understood;
  • one bigger server, or a few copies of the app behind a load balancer, handles the load;
  • a tight deadline matters more than anything.

Choose a modular monolith when:

  • you have roughly 10 to 50 developers and the domain is getting complex;
  • teams need clear ownership, but not separate deploys;
  • you need transactions that span several areas (orders and payments, say);
  • you want to keep the option of splitting later, without paying for it now.

Choose microservices when:

  • you have 50+ developers in teams that keep blocking each other’s releases;
  • parts of the system need very different scaling (a feed read 100 times more than it is written, or notifications that spike);
  • parts need different technology (a machine learning service in Python, the rest in Java);
  • rules require physical separation (for example, payment card data);
  • one part failing must not take down the rest.

Netflix runs hundreds of microservices because it has thousands of engineers, a huge, varied domain, and teams that must ship without waiting on each other. And the opposite move happens too: Segment publicly moved from more than a hundred microservices back to a monolith, and an Amazon Prime Video team merged a distributed monitoring system into one application and cut its cost sharply. Neither is a failure. They each matched the shape to the problem.

Keep the modular monolith honest

A modular monolith has one weakness: nothing physically stops a developer from reaching into another module’s internals on a busy Friday. Do that a few hundred times and you are back to a big ball of mud.

The fix is to make the boundaries fail the build, not just a code review. In Spring, Spring Modulith checks this for you:

// Java · ModularityTests.java
class ModularityTests {
    @Test
    void modulesOnlyTalkThroughTheirApis() {
        ApplicationModules.of(ShopApplication.class).verify();  // fails if any module touches another's internals
    }
}

Tools like ArchUnit do the same job in any Java project. The lesson from the book behind this notebook is a short one: architecture is not just design, it’s enforcement.

Three ways microservices go wrong

Splitting into services is easy. Getting the benefits is not. These three mistakes give you all of the cost and none of the reward.

1. The distributed monolith

Your services are separate on paper, but every request needs all of them. Loading one profile page calls the user, posts, friends, stats and preferences services, one after another.

A profile page request fans out in a chain to five services: User, Posts, Friends, Stats and Preferences. Each service is labelled 99.9% available and about 10 ms. A total box underneath: in a monolith, about 5 ms and one thing to fail. As a chain of services: at least 50 ms, and 0.999 to the power 5 is 99.5% available, about 3.6 hours of failures a month instead of 43 minutes.
Five services in a chain are slower and fail more often than any one of them.

Each call adds network time. Worse, the failures multiply: five services that are each up 99.9% of the time give a page that works only about 99.5% of the time. That’s around 3.6 hours a month of broken pages instead of 43 minutes. And you can no longer read one stack trace to find the bug.

The fix: draw service boundaries so most requests stay inside one service. Where a page truly needs several, make the calls in parallel with fallbacks (often in a backend for frontend that shapes data for one screen), or keep a local copy of the data the page needs.

2. The shared database

You split the code into services, but they all still read and write the same database. Now the order service queries the user table directly.

You can’t change the user table without breaking orders. You can’t scale the databases separately. You can’t deploy on your own. This is the worst of both worlds: microservice complexity with monolith coupling.

Left, marked as a trap: User, Order and Payment services all pointing at one shared database, with a warning that changing one table breaks three services. Right, the fix: each service has its own database. The User service publishes a UserRenamed event, and the Order service listens and updates its own small copy holding just the user id and name.
Each service owns its data. Others get a copy through events, not a key to the front door.

The fix: each service owns its data. If orders need the customer’s name, the order service keeps its own small copy and updates it when the user service publishes a UserRenamed event. The cost is that the copy can be a second or two out of date (eventual consistency). The gain is real independence.

3. Cascading failures

The payment service gets slow: 30 seconds per call because of a database problem. The order service waits on it, and soon all its threads are stuck waiting. Then the service that calls orders gets stuck too. One slow service has taken down the whole system.

The fix: never wait forever. Put a timeout on every network call, use a circuit breaker to stop calling a service that keeps failing, and have a fallback: for example, save the order as pending and take the payment a few minutes later. The next article goes deeper into why this happens.

Puzzle: the monolith that scales

Stack Overflow is mostly reads (people looking at answers), has a fairly simple domain (questions, answers, votes), and a small engineering team. Caching and a few powerful servers handle the load. Splitting it up would add network calls and buy them nothing.

Netflix has a huge, varied domain: streaming, video encoding, recommendations, billing, many devices and countries. It has thousands of engineers, and parts that need different technology. The billing team must be able to ship without waiting for the recommendations team.

The lesson: scale is not the main reason for microservices. Team size and domain complexity are. A monolith can scale out too: just run more copies of it.

A sensible path for most teams

If you are starting something new, this path rarely goes wrong:

  1. Start as a modular monolith. One deploy, but folders that match your business areas (user, product, order, payment), each with a public API and hidden internals.
  2. Enforce the boundaries with tests that fail the build.
  3. Watch for real signals: teams blocking each other’s releases, one module needing very different scaling, or a part that must be isolated for safety or rules.
  4. Extract one module at a time when a signal appears, starting with the one that hurts most. Because the seams are already clean, it is a move, not a rewrite.

Key takeaways

  1. The real difference is function calls vs network calls. That is where the cost of microservices comes from.
  2. Choose by team size and domain complexity first, traffic second.
  3. A modular monolith is the sweet spot for most teams: clear boundaries without the network.
  4. Boundaries need enforcement. If the build doesn’t fail, the walls will fall.
  5. Avoid the traps: chatty services, shared databases and calls without timeouts give you all the cost and none of the benefit.
  6. Your architecture should match your team. Change it when the team or the pain changes, not when the fashion does.

Once your system is spread over more than one machine, the rules of the game change. Next: distributed systems basics, and what really changes when you add a network.

Comments

LEAVE A COMMENT
No sign-up. Comments appear after a quick review.