Microservices vs the modular monolith, plus gateways, discovery & service mesh
When splitting into services is worth it, database-per-service, API gateways, service discovery, inter-service auth, the strangler-fig migration, and why your Modulith is the right starting point.
The honest trade-off
| Modular monolith (you) | Microservices | |
|---|---|---|
| Deploy | One artifact | Many independent deploys |
| Data | One DB, ACID across modules | Database per service; sagas, eventual consistency |
| Calls | In-process (nanoseconds, no failures) | Network (milliseconds, partial failures) |
| Scaling | Whole app | Per service |
| Teams | Works for 1–30 engineers | Shines at many teams needing autonomy |
| Ops | One thing to monitor | Tracing, mesh, gateways, many pipelines |
| Debugging | A stack trace | Distributed tracing across 6 services |
Microservices solve organisational scaling problems more than technical ones. Start with a modular monolith, and extract a service only when there’s a clear reason: a different scaling profile, a different release cadence, a different team, or a different tech stack.
Spring Modulith modules (ledger, reporting, identity, ...)SperoTek is already microservice-ready: each module has a public api/, communicates through events, and has its own tables. Extracting reporting (CPU-heavy exports) later would mean moving the module, putting Kafka or RabbitMQ behind its events, and giving it a read replica or its own read model.
The supporting cast
- API gateway (Spring Cloud Gateway, Kong, AWS API Gateway, Envoy): one entry point handling routing, authentication (JWT verification), rate limiting, TLS and request aggregation.
- BFF (Backend for Frontend): one gateway per client type (web, mobile).
- Service discovery (Eureka, Consul, Kubernetes DNS): find instances dynamically.
- Config server (Spring Cloud Config, Consul KV).
- Inter-service auth: mTLS (a service mesh does this automatically), or OAuth client credentials with short-lived JWTs, verified via JWKS (RS256, not shared HS256 secrets).
- Service mesh (Istio, Linkerd): sidecar proxies providing mTLS, retries, timeouts and traffic shifting without code changes.
- Distributed tracing (OpenTelemetry): essential once you have more than one service.
Communication styles
| Style | Example | Coupling |
|---|---|---|
| Sync REST/gRPC | Order calls Payment | Temporal coupling: Payment down means Order fails |
| Async events | OrderPlaced → Payment listens |
Loose; eventual consistency |
Prefer async for cross-service workflows and sync for queries that need an immediate answer. Avoid chatty synchronous chains (A→B→C→D), which multiply latency and failure rates.
Migration: strangler fig
Put a gateway in front of the monolith. Route /api/reports/** to the new service while everything else still goes to the monolith, and move routes over one by one until the old code is gone.
Anti-patterns
- Distributed monolith: services that must deploy together, or share one database.
- Nanoservices: one service per entity.
- Shared libraries with business logic coupling every service.