Monolith vs Microservices: Choosing an Architecture for Your Team
What each architecture gives you and what it costs, including distributed tracing, sagas and compensating actions, and why most products should begin as a well-structured monolith.
A monolith is an application built and deployed as a single unit. A microservices architecture splits the application into small services, each owning one business capability, deployed independently and communicating over the network.
Neither is better in general. Microservices solve problems of scale, mostly organisational scale, and they introduce the problems of distributed systems. A team of five developers adopting microservices takes on those costs without having the problems they solve. The correct answer is 'it depends', followed by what it depends on.
The monolith
In a monolith, all the modules, such as users, catalogue, orders and payments, live in one codebase, run in one process, and usually share one database. A call from one module to another is an ordinary function call.
- Simple to develop: one repository, one build, the whole application runs on a laptop.
- Simple to deploy and operate: one artifact, one pipeline, one set of logs.
- Simple to debug: a single stack trace shows the entire path of a request.
- Strong consistency is easy: an operation that touches several modules is one database transaction.
- Fast: in-process calls have no network latency and cannot partially fail.
Where the monolith strains
The limits of a monolith appear as the codebase and the organisation grow.
- Many teams change the same codebase and must coordinate every release. One team's unfinished work can block another team's deployment.
- Build, test and deployment times grow, so releases become less frequent and riskier.
- Scaling is all or nothing. If only the image-processing module needs more capacity, the entire application must still be replicated.
- A fault in one module, such as a memory leak, can bring down the whole process.
- The whole application is tied to one language, framework and runtime version.
- Without discipline, module boundaries erode and everything depends on everything else.
Microservices
In a microservices architecture each service implements one business capability, owns its own data store, and exposes an API. Other services use that API and never read its database directly. Each service is built, deployed and scaled on its own, typically by one small team.
- Independent deployment: a team releases its service without waiting for anyone else.
- Independent scaling: capacity is added only where the load is.
- Fault isolation: when the recommendation service fails, checkout can continue.
- Team autonomy: clear ownership, and freedom to choose suitable technology per service.
- Smaller codebases that are easier to understand individually.
MONOLITH
Client --> Load balancer --> [ Users | Catalogue | Orders | Payments ] --> one database
one codebase, one deployable, in-process calls
MICROSERVICES
Client --> API gateway --+--> User service --> users DB
+--> Catalogue service --> catalogue DB
+--> Order service --> orders DB
+--> Payment service --> payments DB
|
Message broker (events between services)
+ service discovery, config, tracing, metrics, CI/CD per serviceThe costs of microservices
Splitting an application turns function calls into network calls, and that changes everything about how it behaves. The network is slow compared to memory, and it fails: requests time out, arrive twice or not at all. Every call between services needs timeouts, retries with backoff, and circuit breakers to stop a failing dependency from dragging down its callers.
The operational surface multiplies. Each service needs its own pipeline, deployment configuration, monitoring, alerting and on-call ownership. The platform must provide service discovery, an API gateway, configuration and secret management, and usually container orchestration. Testing a feature that spans several services is harder, and versioned APIs must remain backward compatible because services are deployed at different times.
Debugging: distributed tracing
In a monolith, a failed request leaves one stack trace. In microservices, a single user action may pass through eight services, and each has its own logs on its own machines. Finding where a request slowed down or failed by reading logs separately is impractical.
Distributed tracing addresses this. The first service to receive a request assigns it a trace ID, which is passed along in the headers of every downstream call. Each service records the time it spent as a span tagged with that trace ID. A tracing system collects the spans and reconstructs the full path of the request as a timeline, showing which service was called by which, how long each took, and where an error occurred. Including the trace ID in every log line ties logs to traces.
Data consistency: the saga pattern
In a monolith, placing an order can create the order, reserve stock and record the payment in one database transaction: all succeed or all are rolled back. With a separate database per service, no single transaction can span them, and distributed transactions using two-phase commit are slow and reduce availability.
The saga pattern replaces one large transaction with a sequence of local transactions, one in each service. Each step commits on its own and then triggers the next step. If a step fails, the saga runs compensating actions that undo the steps already completed. A compensating action is a new operation that semantically reverses an earlier one: a refund reverses a charge, a release reverses a stock reservation.
Sagas can be coordinated in two ways. In choreography, each service reacts to events published by the others, with no central controller. In orchestration, a dedicated orchestrator tells each service what to do and tracks the state of the saga. A saga gives eventual consistency, not isolation: for a short time the system is in an intermediate state, and the design must tolerate that.
Step Service Action Compensating action
---------------------------------------------------------------------
1 Order create order (PENDING) cancel order
2 Inventory reserve stock release stock
3 Payment charge customer refund customer
4 Order mark order CONFIRMED -
Happy path : 1 -> 2 -> 3 -> 4
Payment fails at step 3:
run compensation for 2 (release stock),
then for 1 (cancel order). The system ends in a consistent state.What the decision depends on
- Team size: with one or two teams, coordination in a monolith is cheap. With dozens of teams, independent deployment becomes valuable.
- Domain understanding: service boundaries are expensive to change. Until the domain is well understood, boundaries drawn early are likely to be wrong.
- Scaling profile: if components have very different load or resource needs, separating them pays off.
- Operational maturity: automated deployment, monitoring and on-call practices must exist before running many services.
- Stage of the product: early on, speed of change matters most, and a monolith changes fastest.
Monolith first
The widely recommended path is to start with a modular monolith: one deployable, but with strict internal module boundaries, where each module has its own tables and other modules use it only through a defined interface. This keeps development simple while preserving the ability to split later.
When a specific pain appears, for example one module that needs to scale separately or a team that is blocked by shared releases, extract that module into a service. Repeating this gradually, with a routing layer directing traffic to the new service, is often called the strangler pattern. Services are then created in response to real needs with boundaries that have already proven themselves.
A warning sign of a poor split is the distributed monolith: services that must be deployed together, that share a database, or that call each other synchronously in long chains. It carries the costs of both architectures and the benefits of neither.
Interview summary
- It depends on team size, domain clarity, scaling needs and operational maturity.
- Monolith: simple to build, deploy and debug, with easy transactions; strains with many teams.
- Microservices: independent deployment and scaling, fault isolation; cost is distributed-system complexity.
- New requirements: distributed tracing for debugging, sagas with compensating actions for consistency.
- Default: start with a modular monolith and extract services when a concrete need appears.
Summary
A monolith optimises for simplicity and microservices optimise for independence. Microservices allow many teams to deploy and scale separately, at the price of network failures, operational overhead, distributed tracing and sagas in place of transactions. For a small team the monolith is the better starting point, kept modular so that services can be extracted when the need is real.
Puneet Tiwari
Full Stack Developer
