← Building blocks

Split a monolith by domain

Scaling & loadsenior

Teams block each other in one codebase and one deploy; one hot path cannot scale independently.

Say it like this

I split along business boundaries only where a team or a hot path needs to deploy and scale on its own, each service owning its data and talking over APIs or events, and I start from a modular monolith so the seams are proven before they become network calls.

Basic solution

Split along business boundaries into services that own their data and communicate over APIs or events.

gRPCRESTservice mesh (Istio, Linkerd)

Services own their data; events cross boundaries

The trip service keeps rider, trip and payment in one database because they commit together. Location and notifications are separate because they scale and fail differently. Facts cross boundaries as events, not shared tables.

How it works

  1. Identify bounded contexts: clusters of data and behaviour that change together and are owned by one team, such as notifications, payments or matching. A context is a good candidate for a service when a feature usually lands entirely inside it.
  2. Give each context its own service with its own datastore. No other service reads that database directly; it goes through the owning service's API or consumes the events that service publishes.
  3. Define the contracts between services. Synchronous APIs (REST or gRPC) serve queries and commands that need an answer now. Events serve facts other services react to later, such as trip.completed.
  4. Route traffic through a gateway for external clients, and through service discovery or a mesh between services, so callers find instances by name rather than address. Put a timeout, a retry policy and a circuit breaker on every call, because every call is now a network request that can fail.
  5. Deploy each service independently with its own pipeline, dashboards and on-call rota. Version the contracts so that deploying one service never forces another team to deploy at the same time.
  6. Handle workflows that span services with sagas (a sequence of local transactions with compensating actions) or an outbox (events written in the same transaction as the data), never with a transaction that spans two databases.

What you are really buying

  • Independent deployability and independent scaling. If neither is a current pain, the split adds network failures and operational cost without a benefit.

Worked example

Ride platform: what to split and what to keep together

  • A monolith serving 50K trips per hour with one team of eight engineers ships fine as one deploy. At four teams and 200 engineers, every deploy waits on every other team and a bug in pricing can take down matching.
  • Split 1: location ingestion, 5M driver updates per minute, is a different shape from everything else (write-heavy stream, no transactions). As its own service it scales to 40 instances while the rest stays at 6.
  • Split 2: notifications, called by every other service and dependent on flaky third-party providers. Isolating it behind a queue means a Twilio outage cannot slow trip creation.
  • Kept together: rider, trip and payment records stay in one service with one Postgres, because a trip and its payment change in one transaction; splitting them would turn one COMMIT into a saga with compensations.
  • The cost: 12 services means 12 pipelines, 12 dashboards, a gateway, a mesh and tracing. A cross-service request now has 3 to 5 hops; at 20 ms each, p99 of trip creation rose from 80 ms to 150 ms until the hot path was reduced to two hops.
  • Rule used: a service per team boundary and per distinct scaling shape, never per table or per noun.

Variants and when each wins

Modular monolith

  • One deployable with strict module boundaries enforced in code, each module owning its own tables. It wins as the starting point, and often the ending point, because it gives clear ownership with no network calls between modules.

Microservices with synchronous APIs

  • Services call each other over REST or gRPC and wait for the answer. It wins when the request path genuinely needs an immediate reply; the cost is that every call is a failure point and a latency hop that needs timeouts, retries and circuit breakers.

Event-driven services

  • Services publish facts to a log and react to each other's events. It wins for loose coupling and a natural audit trail; the costs are eventual consistency and flows that are harder to trace end to end.

Service per team with a shared platform

  • Each team owns its services end to end, while a platform team owns the gateway, mesh, observability and deploy tooling. It wins because it is the organisational shape that makes the technical one sustainable.

Recommendation: modular monolith until a team or a scaling shape genuinely needs independence, then extract that one piece; use events between contexts and synchronous calls only on the request path that needs an immediate answer.

Failure modes

Distributed monolith

  • Every change touches four services and all four must deploy together. The boundaries were drawn by technical layer or by noun (a user service, an order service) rather than by business context, so one feature spans them all. Merge the services that always change together, and redraw boundaries around teams and workflows.

Shared database

  • A schema change in one service breaks another service that nobody expected to be affected. Two services read and write the same database, so a table is a hidden contract between them. Give each service its own data, and let others get at it only through the owning service's API or events, migrating one table at a time.

Chained synchronous calls

  • A page's p99 is the sum of five services' latencies and its availability is the product of their five availabilities. The request path runs through a deep chain of synchronous calls. Flatten the chain to one or two hops, precompute what you can from events, cache aggressively, and propagate a deadline so a slow hop fails fast instead of holding everything.

No ownership of cross-cutting concerns

  • Every service has its own half-working authentication and logging. Nobody owns the shared pieces, so each team rebuilt them badly. Put authentication, tracing, metrics and deploy tooling in a gateway and a platform team that provide them once for everyone.

Cross-service transaction

  • An order is marked paid but never shipped after a crash between the payment service and the shipping service. The two writes happened in two databases with nothing coordinating them. Use an outbox so events are written atomically with the data, sagas with compensating actions for multi-step workflows, and idempotent handlers so a retried step does no harm.

Interviewer follow-ups

Answer out loud before you open each one.

How do you decide where to draw a service boundary?

Around data and behaviour that change together and are owned by one team, so a feature usually lands in one service. Test a candidate boundary by asking whether the two sides need a transaction between them; if they do, they belong together.

How do services share data without sharing a database?

The owning service publishes events when its data changes, and consumers keep their own read model shaped for their needs. For an answer needed right now, call the owner API with a timeout and a cached fallback. Never read another service tables directly.

What is the minimum platform you need before splitting?

A gateway, service discovery, centralised logs with correlation ids, distributed tracing, per-service dashboards and a deploy pipeline that any team can run. Without these, every split multiplies the time to debug an incident.

When would you merge services back?

When two services always deploy together, when a workflow between them needs compensations that keep failing, or when the hop between them dominates latency. Merging is cheaper than living with a distributed monolith.

Connections

Pairs with
One front door for many services · Coordinate a multi-service transaction · Publish events reliably with the write · Follow one request across services · Stop calling a failing dependency · Find services and config at runtime
Pulls against
Commit across two stores · Default to a relational database

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon API GatewayAPI gatewayAPI Gateway, ApigeeAPI ManagementKong, Tyk
Amazon EC2 Auto ScalingTrip service, Location service, Notification serviceCompute Engine managed instance groupsVirtual Machine Scale SetsKubernetes Deployment with a HorizontalPodAutoscaler, Nomad
Amazon AuroraTrip DBAlloyDB for PostgreSQL, Cloud SQLAzure Database for PostgreSQL or MySQLPostgreSQL, MySQL, CockroachDB
Amazon ElastiCacheGeo indexMemorystoreAzure Managed RedisRedis, Valkey, Memcached
Amazon MSK (Kafka)Event logManaged Service for Apache KafkaEvent Hubs (Kafka API)Confluent Cloud, Redpanda