Microservices solve problems of team organization and scaling, but they add a network, distributed data, and operational overhead. Split a monolith when it is clear which problem this solves and which first step can be verified without stopping the system.
First decide whether to split at all.
Moving from a monolith to microservices pays off when the coupling of the system itself is the obstacle, not the quality of individual code. Signs that usually justify the decision:
- Teams block each other: a change in one module requires coordination and a release of the whole application.
- Parts of the system carry different load: to handle a peak in one function, the whole application has to be scaled.
- A failure in one function, such as imports or report generation, takes down the whole product.
- Builds, tests, and deploys take so long that changes pile up and ship in large batches.
Weak reasons are “everyone does it”, slow requests (these are usually fixed inside the monolith; see the slow API guide) and tangled code. Code that is tangled inside a monolith becomes tangled over the network after a split.
01 / OPTION
Clean up the monolith
If the problem is speed or code quality, start with profiling, tests, and refactoring. It is cheaper and reversible.
02 / OPTION
Modular monolith
Modules with explicit boundaries and their own data inside one application. Prepares future services without network complexity.
03 / OPTION
Extract services
When a module needs its own release cycle, separate scaling, or failure isolation. Extract one at a time, starting with the most independent.
A question to check
Which specific problem will the first extracted service solve, and how will you know it is solved?
A modular monolith is often the first step.
A modular monolith is one application and one deployment, but inside it are modules with explicit boundaries. Each module owns its tables, and the others call it only through its interface: no direct queries to another module’s data and no imports of its internal classes.
This structure solves part of the problem without a network: code is easier to evolve, and boundaries are tested in practice. A wrong boundary is cheap to move within one repository. When a module really needs its own deployment, it becomes a service with little rework: the interface exists and the data is already separated.
Enforce the boundaries with build rules so that a module cannot import another module’s internals. Go has internal directories for this; in PHP, use a dependency analyzer such as Deptrac.
Find the service boundaries.
A service boundary follows a business capability, not a technical layer. “Orders” or “Payments” services last, while “Database”, “Validation”, or “Utilities” services constantly call each other synchronously. In DDD these boundaries are called bounded contexts.
- Build a dependency map: which modules call each other and which tables they read and write. Tightly coupled parts should stay together.
- Check the change history: files that always change in the same commits belong within one boundary.
- Assign an owner to every table: one module writes to it; the others read through its API or receive events.
- Check against teams: a boundary that nobody owns will erode over time.
Practical worksheet
A service candidate card
A discussion template, not client project data. Fill it in for each module you want to extract.
Capability and owner
What does the module do in business terms? Which team owns it and its releases?
Data
Which tables does the module write, and which does it only read? Who else writes to them?
Coupling
Whom does the module call synchronously, and who calls it? What can move to events?
Reason to extract
Separate releases, scaling, or failure isolation — which one, and how will it be measured?
Extract one service at a time.
Rewriting the whole monolith and switching over in one day is the riskiest option: while the new system is being written, the old one keeps changing, and the result can only be verified at the end. The Strangler Fig approach is more reliable: routing (a proxy or an API gateway) is placed in front of the monolith, and workflows move to new services one by one until the monolith is no longer needed.
01 /
Pick the first service
A good candidate is loosely coupled to the rest of the code, owns its data, and delivers visible value: notifications, search, imports, a separate calculation. Leave the core business logic for later.
02 /
Separate it inside the monolith
First hide the function behind an interface inside the monolith and remove direct access to its tables. This tests the boundary before a network is involved.
03 /
Run it alongside
The new service receives a copy of traffic or runs behind a switch, and its responses are compared with the old implementation.
04 /
Switch over and delete the old code
Traffic moves gradually, with a rollback path. After the switch, the old implementation is deleted from the monolith; otherwise people will keep changing it.
New services do not have to use the monolith’s language. They are often written in Go: a single binary, a small memory footprint, and convenient handling of concurrent requests and queues. But decide on a language change separately from the split: two big changes at once make errors harder to trace.
The shared database is the hardest part.
Code is easier to split than data. If a new service keeps reading and writing the same tables as the monolith, the result is a distributed monolith: services still cannot be released independently, and a schema change breaks everyone at once.
- Data ownership. Each table has one owner. The others get data through its API or keep their own copy of the fields they need.
- Synchronization. Copies are updated by events. To avoid losing an event, write it in the same transaction as the data change (the transactional outbox pattern) or read changes from the database log (CDC, for example Debezium).
- Transactions. There is no single transaction across several services. Multi-step operations (order → payment → reservation) are built as sagas: a chain of steps with compensating actions on failure. Long-running processes suit workflow engines such as Temporal.
- Reports and search. Queries that used to join tables of different modules move to a separate read store built from events.
- Data migration. Data moves in stages: the service first reads the old tables, then writes to its own with sync back, and only then becomes the sole owner. See the data migration service for details.
Sign of a good boundary
The service can be released, restarted, or rolled back without touching the monolith or other services.
What breaks after the split.
A function call inside a process never gets lost in the network. After the split, the same call can hang, return an error, or run twice. Plan for these cases up front:
- Timeouts, retries, and protection from cascading failures: a hung service must not block every caller.
- Idempotency: a repeated request or event must not create a second order or a second charge.
- Chains of synchronous calls: if a user response needs five services in a row, latencies and failure probabilities add up.
- Observability: without end-to-end tracing (for example, OpenTelemetry) and a shared request ID, finding a failure means searching the logs of a dozen services.
- API versions: services release independently, so contract changes must be backward compatible.
- Operations: each service has its own deployment, monitoring, alerts, and access. Without automation this quickly eats the team’s time.
If the infrastructure is not ready for this, extract one or two services and get deployment and observability right on them before splitting everything.
What to bring to the first conversation.
You do not need a finished plan. Describe what gets in the way now — releases, load, failures, or delivery speed — how the system is built, and what constraints apply to switching over. A module diagram, a list of integrations, and a database description help choose the first service faster.
- Which problem should disappear after the split, and how will it be measured?
- Which modules, data, and integrations exist today, and who owns them?
- What downtime is acceptable during the switch, and how are changes deployed today?