Cloud & Data Centers

Microservices vs. Monoliths

What each architecture costs and buys, with practical signs for when to split an application.

Key takeaways

  • A monolith is simpler to build, test, deploy and debug, and it can still be well structured inside.
  • Microservices let teams release and scale parts separately, in exchange for network failures, data consistency problems and more tooling.
  • Service boundaries should follow business capabilities and team ownership, not technical layers.
  • A modular monolith is a strong middle path that keeps splitting possible later.
  • Split gradually and only where you can name the problem the split solves.

A monolith is an application built and deployed as one unit. Microservices split it into several small programs that run separately and talk over a network. Neither is better in general. For a small team or a young product, a well-organized monolith is usually the sensible choice, and microservices start to pay off when many teams need to release independently or when parts of a system have very different needs.

The decision matters because it shapes how you ship code, how failures spread and how much operational work you sign up for. Here's what each approach really involves.

What a monolith is

In a monolith, the web pages, business rules and data access live in one codebase and run as one process, or as identical copies of that process behind a load balancer. When the order module needs the customer module, it calls a function. That call takes a tiny fraction of a millisecond and can't be lost in transit.

There's usually one database. A single transaction can update the order and the inventory together, and either both changes happen or neither does.

"Monolith" often gets used as an insult, but the word describes deployment, not quality. A monolith can have clear modules with strict interfaces. It can also be a tangle where everything depends on everything, which is the version people complain about.

What microservices are

A microservice is a small, independently deployable program that owns one business capability, such as payments, search or notifications. It has its own interface, usually an HTTP or RPC API or a stream of events, and ideally its own data store that other services don't reach into directly.

That last rule is what makes services independent. If two services share database tables, a change to a column can break both, and they must be released together. The result is sometimes called a distributed monolith: all the network trouble with none of the freedom.

Monolith and microservices at a glance
Monolith One codebase and deployment Function calls between modules Shared database and transactions Scale by running more copies Microservices Many small deployments Network calls and events Each service owns its data Scale each service separately VS Monolith One codebase and deployment Function calls between modules Shared database and transactions Scale by running more copies Microservices Many small deployments Network calls and events Each service owns its data Scale each service separately

The same feature, built both ways

Say you add gift cards to an online store. In a monolith, you write a new module, add a table, and have checkout call a function that deducts the balance inside the same transaction that creates the order. If anything fails, the whole transaction rolls back. You test it on your laptop and ship it in one release.

With services, a gift card service owns the balances. Checkout asks it to reserve an amount, creates the order, then confirms the reservation. You have to decide what happens if the confirmation never arrives, how long a reservation lasts, and how to avoid charging twice when a request is retried. The gift card team can now change its internals and release on its own schedule, but you've written noticeably more code to get there.

The real benefits of splitting

Independent releases. A team can fix its service and ship it without waiting for everyone else's changes to be ready. For a large organization, this is often the main reason.

Targeted scaling. If image processing needs many processors and the account pages need very little, you can size them separately.

Fault isolation, if designed for. A crash in a recommendation service need not stop checkout. This only happens when callers handle its absence gracefully.

Technology freedom. A service can use the language or database that suits it. In practice, most organizations limit the variety, since every extra stack needs people who can maintain it.

The costs people underestimate

A function call becomes a network request. It can be slow, fail, time out, or succeed while the reply gets lost, leaving the caller unsure what happened. Every caller needs timeouts, limited retries with backoff and a plan for when the answer never comes.

Long chains multiply risk. As a made-up example, if a page needs five services in sequence and each succeeds 99.9 percent of the time independently, the whole chain succeeds about 99.5 percent of the time.

Example: success rate when each call succeeds 99.9% of the time
1 service in the chain 99.9% 5 services in a chain 99.5% 10 services in a chain 99% 30 services in a chain 97% 1 service in the chain 99.9% 5 services in a chain 99.5% 10 services in a chain 99% 30 services in a chain 97%

Assumes independent failures, no retries and no fallbacks. Hypothetical example: the numbers are made up to show the method, not a quote or an average.

Data consistency gets harder too. You can't wrap changes in three databases in one ordinary transaction. A common alternative, the saga, runs a series of local steps and defines a compensating action, such as a refund, if a later step fails. Between steps, different parts of the system may disagree briefly, and your product has to tolerate that.

Then there's the platform: deployment pipelines for every service, service discovery, secrets, access control between services, centralized logs and distributed tracing. Many teams run services in containers orchestrated by Kubernetes, which is a system to learn in its own right.

Operating what you split

Each service needs an owner who answers when it breaks. It needs health checks, dashboards, alerts, a deployment path and a way to roll back. Security work multiplies too, since every service has its own dependencies to patch and its own permissions to grant. Services should authenticate to one another instead of trusting anything on the internal network.

Count the people before you count the services. A team of five looking after thirty services spends much of its week on upkeep: upgrading libraries thirty times, rotating thirty sets of credentials and remembering how each one behaves. Shared templates and platform tooling reduce the burden, and someone has to build and maintain those too.

Cloud costs can rise as well. Every service usually runs at least two copies for resilience, whether it's busy or not, and traffic between them may cross availability zones that bill for transfer.

How services talk

Synchronous calls suit questions that need an answer now. REST over HTTP is widespread, and binary protocols such as gRPC are common between internal services.

Asynchronous messaging suits announcements and slow work. A service publishes an event and others react in their own time. This reduces the chance that one slow service stalls the rest, though it makes the flow harder to follow. See message queues and event-driven systems.

Outside clients rarely call each service directly. An API gateway gives them one front door that handles routing, authentication and rate limits.

The modular monolith

You can get much of the design discipline without the network. In a modular monolith, each module owns its code and its tables, exposes a narrow interface, and is forbidden from reaching into others. Automated checks can enforce those rules.

It deploys as one unit, so testing and debugging stay straightforward. If one module later needs to become a service, its boundary already exists. For many products this is enough for years.

Should you split out a service?
Do teams regularly block each other's releases? YES Splitting along team ownership may help 1 NO Does one part need very different scaling or hardware? YES Extract that part first 2 NO Must one part be isolated for safety or compliance? YES Give it a separate service and data store 3 NO Improve the monolith Tighten module boundaries, tests and deployment before adding a network. Do teams regularly block each other's releases? 1 IF YES Splitting along team ownership may help NO Does one part need very different scaling or hardware? 2 IF YES Extract that part first NO Must one part be isolated for safety or compliance? 3 IF YES Give it a separate service and data store NO Improve the monolith Tighten module boundaries, tests and deployment before adding a network.

Drawing the boundaries

Good boundaries follow what the business does: ordering, billing, catalog, shipping. Each can change mostly on its own. Poor boundaries follow technical layers, such as a "database service" that every feature has to pass through, which means every change touches several services.

A useful test is to list recent changes and ask which parts had to be edited together. Things that always change together belong together. If a proposed service would need constant chatter with another to do anything, they're probably one service.

Boundaries are hard to get right early, when you're still learning what the product is. Moving code between modules is cheap. Moving it between services, with separate data and live traffic, is not.

Moving from one to the other

Rewriting everything at once is risky. The usual alternative is often called the strangler fig pattern:

  1. Put a routing layer in front of the monolith.
  2. Pick one capability with a clear boundary and a real reason to move.
  3. Build it as a service and migrate its data.
  4. Route that capability's traffic to the new service, gradually, with a way back.
  5. Delete the old code, then decide whether another step is worth it.

Before the first split, make sure you can deploy automatically, see logs from everything in one place and trace a request across processes. Continuous integration and delivery and good monitoring are prerequisites, since problems that were a stack trace become a hunt across machines.

Going the other direction is legitimate too. Teams that split too finely sometimes merge services back and find the system easier to run.

Testing and local development

With one program, a developer can usually run the whole thing on a laptop and test a feature end to end. With dozens of services, that may be impractical. Teams then rely on stand-ins for other services and on contract tests, which check that a provider still returns what its consumers expect.

Versioning becomes part of daily work. During any release, old and new versions of a service run side by side, so changes to interfaces need to be backward compatible: add fields before you require them, and remove them only after nobody reads them.

Signs your current design needs attention

A few symptoms are worth tracking whichever side you're on. Releases that wait days for unrelated changes suggest coupling or weak tests. A single slow report that drags down checkout suggests that workloads need separating, even if that only means a background worker or a read replica of the database.

In a service system, watch for features that always require coordinated releases, long chains of calls to render one screen, and incidents where nobody can say which team owns the failure. Those point to boundaries drawn in the wrong places.

Fix the specific symptom first. Moving a heavy job onto a queue, adding module rules or speeding up the test suite often delivers the relief people hoped a rewrite would bring.

Common questions

Do microservices make an application faster?

Not by themselves. Network calls add delay. Splitting can help throughput when it lets a bottleneck scale on its own.

How small should a microservice be?

Size by ownership and purpose. One team should be able to understand and operate it. Counting lines of code is a poor guide.

Are serverless functions microservices?

They can be a way to run them. Serverless hosting removes some server management, but the design questions about boundaries, data and failure stay the same.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Cloud & Data Centers →

Latest news on this topic