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
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.
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.
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.
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:
- 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. - Enforce the boundaries with tests that fail the build.
- 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.
- 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
- The real difference is function calls vs network calls. That is where the cost of microservices comes from.
- Choose by team size and domain complexity first, traffic second.
- A modular monolith is the sweet spot for most teams: clear boundaries without the network.
- Boundaries need enforcement. If the build doesn’t fail, the walls will fall.
- Avoid the traps: chatty services, shared databases and calls without timeouts give you all the cost and none of the benefit.
- 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