When to Consider Microservices
Microservices aren't always the answer. Consider migrating when: deployment cycles are slow, teams are stepping on each other's toes, or scaling specific features requires scaling everything.
Microservices solve organizational and scaling problems at the cost of operational complexity: more deployments, network calls that can fail, distributed data and harder debugging. If your main problem is messy code, a well-structured monolith is usually the cheaper fix.
First, Consider a Modular Monolith
Before splitting into services, split the monolith into modules with clear boundaries: each module owns its tables, exposes a small internal API, and other modules may not reach into its internals. This gives you most of the design benefits of microservices without the network. It also makes a later extraction far easier, because the seams already exist.
| Signal | Suggests |
|---|---|
| One team, one release cadence | Modular monolith |
| Several teams blocked by each other's releases | Extract services along team boundaries |
| One feature needs very different scaling or technology | Extract that feature as a service |
| No automated tests or CI/CD yet | Fix delivery first; microservices will amplify the problem |
The Strangler Fig Pattern
This pattern lets you gradually replace parts of a monolith without a big-bang rewrite.
A routing layer, usually the API gateway, sits in front of the monolith. As each capability is rebuilt as a service, its routes are switched to the new service while everything else still goes to the monolith. The monolith shrinks step by step, and every step can be rolled back by switching the route back.
Phase 1: Assessment
Domain analysis, dependency mapping, and data flow analysis. Identify the most independent modules that can be extracted first.
Use domain-driven design to find bounded contexts: areas such as billing, catalog or notifications where the language and rules are self-contained. Map which modules call each other and which tables each one reads and writes. The modules with the fewest dependencies are your first candidates.
Phase 2: Foundation
Set up the infrastructure: API Gateway, Service Mesh, Observability stack, and CI/CD pipelines for independent deployments.
A service mesh is optional at the start; many teams add it only once they run enough services to need uniform retries, mutual TLS and traffic policies. Centralized logging, metrics and distributed tracing, on the other hand, are not optional.
Phase 3: First Service Extraction
Start with the most independent module. Often authentication, notifications, or file processing.
Run the new service in parallel before switching traffic: compare its responses with the monolith's (shadow traffic), then move a small percentage of real traffic, then all of it. Keep the old code path until the new service has run stably in production.
Phase 4: Event-Driven Communication
Replace synchronous calls between services with event-driven messaging for better resilience.
const order = await orderService.createOrder(data);
await eventBus.emit("order.created", { orderId: order.id, items: order.items });
The code above has a subtle problem: if the database write succeeds and the event publish fails, other services never hear about the order. The transactional outbox pattern solves this by writing the event to an outbox table in the same database transaction as the order, and publishing it from there in a separate process.
Data: The Hardest Part
- Each service owns its data. Other services get it through the owner's API or events, never by querying its tables.
- Accept eventual consistency. A customer's address updated in one service may take a moment to appear in another. Design screens and processes with that in mind.
- Use sagas for multi-step workflows. Instead of one distributed transaction, a sequence of local transactions with compensating actions (for example, release the stock reservation if payment fails).
- Migrate data in steps. Copy, then sync both ways or dual-write for a period, verify, and only then switch ownership.
Testing and Reliability
- Contract tests (for example, consumer-driven contracts) catch breaking API changes before deployment, without needing every service running.
- Timeouts, retries with backoff and circuit breakers on every network call, so one slow service does not take down the rest.
- Idempotent consumers, because message queues can deliver the same event more than once.
- Distributed tracing with OpenTelemetry, so a single request can be followed across services.
Tools We Use
| Tool | Purpose |
|---|---|
| Docker | Containerization |
| Kubernetes | Orchestration |
| Kong | API Gateway |
| RabbitMQ | Message Queue |
| Istio | Service Mesh |
Mistakes to Avoid
- Don't create too many services too fast: start with 2-3
- Don't share databases between services
- Don't ignore observability. You need distributed tracing from day one
- Don't split along technical layers (a "database service", a "UI service"); split along business capabilities
- Don't chain many synchronous calls in one request; every hop adds latency and a failure point
Migration Checklist
- Problem clearly defined: delivery speed, team autonomy or scaling
- Bounded contexts and dependencies mapped
- CI/CD, logging, metrics and tracing in place before the first extraction
- Routing layer ready to switch traffic gradually and roll back
- Data ownership and migration plan agreed for each service
- Outbox, idempotency and contract tests in place for messaging
Conclusion
A successful migration is incremental and reversible: one capability at a time, each one proven in production before the next. Planning a move away from a monolith? Read about our custom software development work or talk to our team.