Microservices vs Monolith: Which Architecture Should You Choose?
A practical comparison of monolithic and microservices architecture: how each works, pros and cons, communication patterns, data ownership, the modular monolith, migration with the strangler fig pattern and how to decide.
Every backend system has to answer an early question: do we build one application, or many small services? A monolith packages all features into a single deployable unit. Microservices split the system into independent services that talk over the network. Both are valid; the right choice depends on your team, your scale and how well you understand your domain.
The two architectures#
Monolith#
One codebase, one build, one deployment, usually one database. Users, orders, payments and notifications are modules inside the same process and call each other as normal functions.
// Inside a monolith: a plain method call, in the same transaction
@Transactional
public Order placeOrder(Long userId, Cart cart) {
User user = userService.get(userId);
Order order = orderRepository.save(new Order(user, cart));
paymentService.charge(user, order.total());
inventoryService.reserve(cart.items());
return order;
}Microservices#
Each business capability is its own service, with its own codebase, deployment pipeline and database. Services communicate through APIs or messages.
Client → API Gateway → User Service (users DB)
→ Order Service (orders DB)
→ Payment Service (payments DB)
→ Inventory Service (inventory DB)Side-by-side comparison#
| Monolith | Microservices | |
|---|---|---|
| Deployment | Whole app at once | Each service independently |
| Scaling | Scale the whole app | Scale only the busy services |
| Data | Shared database, ACID transactions | Database per service, eventual consistency |
| Communication | In-process function calls (fast, reliable) | Network calls (slower, can fail) |
| Tech stack | One language/framework | Each service can choose |
| Testing & debugging | Simple, one process | Needs contract tests and distributed tracing |
| Team ownership | Shared codebase | Teams own services end-to-end |
| Operational overhead | Low | High: service discovery, monitoring, CI/CD per service |
| Failure impact | A crash can take down everything | Failures can be isolated (with good design) |
Why teams choose a monolith#
- Speed early on: one repo, one deploy, easy refactoring across modules.
- Simple data consistency: a single database transaction covers the whole operation. See ACID transactions.
- Easy debugging: one stack trace, one log stream, one profiler.
- Cheaper to run: fewer servers, less infrastructure.
- Performance: no network latency between modules.
Shopify, Stack Overflow and Basecamp have run very large businesses on well-structured monoliths.
Why teams choose microservices#
- Independent deployments: the payments team can ship ten times a day without coordinating with search.
- Targeted scaling: scale the video encoder to 200 instances while the profile service runs on 3.
- Fault isolation: a bug in recommendations shouldn't break checkout.
- Team autonomy: clear ownership boundaries for large organisations (Conway's law).
- Technology freedom: use Python for ML, Go for high-throughput APIs, Java for core business logic.
The hidden costs of microservices#
If your services share a database, must be deployed together, or call each other in long synchronous chains, you have all the costs of microservices with none of the benefits. This is the most common microservices failure.
- Network failures: every call can time out. You need timeouts, retries with backoff, and circuit breakers.
- Distributed data: no cross-service transactions. You need sagas, outbox patterns and idempotent consumers.
- Observability: a single request spans many services, so you need centralised logs, metrics and distributed tracing (OpenTelemetry).
- Infrastructure: containers, Kubernetes, service discovery, API gateways, per-service pipelines.
- Versioning: API changes must stay backward compatible.
How microservices communicate#
| Style | Examples | Use for |
|---|---|---|
| Synchronous request/response | REST, gRPC | Queries that need an immediate answer |
| Asynchronous events | Kafka, RabbitMQ, SQS | Notifying other services that something happened |
Order Service ──"OrderPlaced" event──▶ Kafka ──▶ Payment Service
├──▶ Inventory Service
└──▶ Email ServiceEvents decouple services: the order service doesn't need to know who reacts to an order. Learn more in message queues: Kafka vs RabbitMQ.
Handling a multi-service transaction: the saga pattern#
1. Order Service: create order (PENDING) → emits OrderCreated
2. Payment Service: charge card → emits PaymentCompleted (or PaymentFailed)
3. Inventory Service: reserve stock → emits StockReserved (or OutOfStock)
4. Order Service: mark CONFIRMED
On failure, run compensating actions in reverse:
OutOfStock → refund payment → cancel orderThe middle ground: a modular monolith#
A modular monolith is a single deployable application with strict internal boundaries: each module owns its tables, exposes a clear interface, and other modules can't reach into its internals.
src/
orders/ api/ internal/ (owns orders_* tables)
payments/ api/ internal/ (owns payments_* tables)
inventory/ api/ internal/
shared/ (only truly shared utilities)You get the simplicity of one deployment today, and if a module later needs to scale or be owned by a separate team, it's already shaped like a service and can be extracted.
Tools like ArchUnit (Java), Spring Modulith, or import-linting rules (eslint-plugin-boundaries, import-linter for Python) fail the build when one module reaches into another's internals.
Migrating: the strangler fig pattern#
Never rewrite a working monolith from scratch. Instead, grow new services around it, like a strangler fig vine:
- Put a routing layer (API gateway or proxy) in front of the monolith.
- Pick one well-bounded capability, such as notifications.
- Build it as a new service and route its traffic there.
- Migrate its data and remove the old code from the monolith.
- Repeat for the next capability, one slice at a time.
How to decide#
| Choose a (modular) monolith if… | Consider microservices if… |
|---|---|
| You're a startup or small team (under ~20 engineers) | Many teams are blocked by each other's releases |
| The domain and boundaries are still changing | Boundaries are stable and well understood |
| Load is moderate and fairly uniform | Parts of the system need very different scaling |
| You lack DevOps and observability maturity | You already have CI/CD, containers, tracing and on-call |
Scaling is often the deciding factor; read vertical vs horizontal scaling and the CAP theorem next. For a hands-on start, see the Spring Boot REST API guide.
Key takeaways#
- A monolith is one deployable unit; microservices are independently deployable services with their own data.
- Monoliths are simpler, faster to build and easier to keep consistent; microservices offer independent deploys, targeted scaling and team autonomy.
- Microservices bring network failures, distributed data and heavy operational costs.
- A modular monolith gives clean boundaries without the distributed-system tax.
- Start simple, and extract services gradually with the strangler fig pattern when real pain appears.