Service boundaries
Read first: Deploys and chaos, Networking for request paths
Put a network hop only where a team, a scale shape, or a compliance rule forces it. A modular monolith keeps those lines inside one deployable, which is the default that still has a single transaction. Six checkout services that must ship together are a distributed monolith, and a synchronous chain through them multiplies latency and failure.
A boundary is the place you agree to pay a network hop. Inside it, a call is a function call, and one database transaction can still cover the whole change. Across it, you have a timeout, a partial failure, and a deploy that can move while its caller stays still. Draw the boundary where one of those costs is already being paid for a reason you can name. A diagram that looks like a product is not a reason.
Core concepts
Three shapes cover almost every argument you will have about this.
A modular monolith is one deployable with hard internal boundaries. Modules talk through explicit interfaces. They do not reach into each other’s tables. You can still wrap a checkout in one transaction, and a stack trace crosses the modules without a trace collector. The constraint is social and structural: the build fails, or review fails, when one module imports another’s private types. The reward is that you keep the option to split later, along a line you already enforced.
Microservices are separate deployables. Each one owns its data and its release. You split when a force makes the single deployable the expensive choice. The forces that count are a team, a scale shape, or a compliance boundary. A team force is real when two groups would otherwise block each other’s releases, and the interface between them is stable enough that they will not still ship on the same day. A scale-shape force is real when two parts of the product want different stores, different replication, or different hardware. Search that can lag writes by seconds is a different shape from an order write that must be durable before you show success. A compliance force is real when a class of data, such as a card number, may live in one place and must not leak into the logs and backups of everything else.
A distributed monolith is many services that must deploy together and fail together. You paid for network calls, partial failure, and a fleet of pipelines. You did not get independent change. The test is practical. If a change to the order total requires a lockstep release of every service in the picture, those services are one system that happens to have several binaries. If a bad deploy of the smallest one takes checkout down, they fail together too.
Synchronous chains are how a distributed monolith hurts a user. If A calls B and B calls C on the path the user is waiting for, the user waits for all three. Latencies add. Availabilities multiply downward. With an independent success probability of p on each hop, a chain of n hops succeeds with probability p^n, which is less than p as soon as n is more than one and p is less than one. The latency numbers page is where the per-hop budget comes from. This page is where the hops get introduced on purpose.
The chain also destroys the tool you had for correctness. A single-database transaction rolls the whole checkout back when inventory reservation fails. Once inventory and payment are different services, there is no global rollback. You either stay in one database, or you accept a saga: a sequence of local transactions with a compensating action for each. Compensations fail too. That is a real design. It is a bad trade when you still had one database and split it for the picture.
Calls across a boundary need a deadline, a definition of what a retry means, and a client that can shed load. Those mechanisms live on retries and circuit breakers and on load shedding. A boundary without them is a thread leak waiting for the first slow dependency. Idempotency is the partner of any retry you add on the far side of the hop. Payment either uses a natural idempotent write or stores a client key. A retried chain that charges twice is the boundary bug users remember.
A worked example
Take a checkout that used to be one module: cart, price, tax, inventory reservation, payment, and receipt. One deployable, one database, one transaction. The team splits it into six services because six areas appear on a slide. The request path stays synchronous. Cart calls price, price calls tax, tax calls inventory, inventory calls payment, payment calls receipt. They still share the order schema. A change to how a discount is stored is a migration plus six releases in a fixed order. Roll tax back and leave price forward, and the total is wrong in a way no single service’s tests catch.
That is the distributed monolith. Name it that way in the review.
Now put numbers on the damage. These are assumptions, except Dean’s datacenter round trip, which is his 2012 teaching figure of 0.5 ms, and the length of a day.
one day 86,400 seconds
interview shortcut about 100,000 seconds
30-day month 30 * 86,400 = 2,592,000 seconds
assumed availability of one service 99.9 percent, failures independent
six services on the path 0.999^6 = 0.994015
unavailability of the chain 1 - 0.994015 = 0.005985
convert to time, steady traffic assumed 0.005985 * 2,592,000 = 15,513 seconds
about 259 minutes in that month
one service, same conversion 0.001 * 2,592,000 = 2,592 seconds
43.2 minutes
The independence assumption is the optimistic one. It is still enough to see the shape. One service at 99.9 percent, converted naively from request success into time the way an error budget is, is about 43 minutes in 30 days. Six independent services on the user path are about 259 minutes. You did not make checkout six times cooler. You made the failure budget about six times larger, and you added every network failure the monolith could not have.
The shortcut check: a day is about 10^5 seconds, so a 30-day month is about 3 × 10^6 seconds if you are rough, or 2.6 × 10^6 if you want the closer figure. 0.6 percent of 2.6 × 10^6 is about 1.6 × 10^4 seconds, the same 4 hours. If your interview arithmetic cannot land near 259 minutes, redo it before you defend the split.
Latency is the other multiplier, and it is honest only if you say how the code calls. Dean’s same-datacenter round trip is 0.5 ms. A planning band for cross-zone traffic in one region is around a millisecond. Use 0.5 ms here and say you assumed same-datacenter placement.
lines in the cart, assumption 20
serial downstream calls per line 5
datacenter round trip 0.5 ms
network floor, serial 20 * 5 * 0.5 ms = 50 ms
handler plus database at p99, assumption 8 ms per call
serial work 20 * 5 * 8 ms = 800 ms
user-visible wait, before retries about 850 ms
same checkout as one transaction one database round trip
Eight hundred milliseconds is the bug. The network floor of 50 ms would have been forgivable on a single checkout. The per-line fanout is not. Parallelizing the five calls per line changes the wait from the sum toward the slowest call, and it creates a fanout of 100 in-flight requests whose tail you own. Batching the lines into one call per downstream service, or keeping them in one process, removes the 100. Measure the real p99 before you treat 8 ms as anything but the assumption that made the product look slow.
A second case, where the split is earned. Card data moves into its own service. Everything else stores a token. The network around that service is tighter, the deploy permission is a smaller group, and the logs of the storefront cannot contain a card number because they never received one. That is a compliance boundary. It costs a hop on the payment path. You pay it because the alternative is card data in every backup of the monolith.
A third case. Product search moves out because its scale shape does not match checkout. The index can be rebuilt, it can lag the write by seconds, and its read hardware should not scale in lockstep with payment. Checkout does not call search on the path that charges a card. The storefront calls search directly. You did not insert another hop into the synchronous chain. You removed a workload that did not belong in the transaction.
flowchart LR
user[User]
cart[Cart service]
price[Price service]
tax[Tax service]
stock[Inventory service]
pay[Payment service]
receipt[Receipt service]
user --> cart --> price --> tax --> stock --> pay --> receipt
The picture is the incident. Any box can reject the request, and the user learns about it only as a failed checkout. A modular monolith draws one box for that path and a second box only for the card-data service.
Tradeoffs
| Choice | What you gain | What you spend |
|---|---|---|
| Modular monolith, hard module boundaries | One transaction, one deploy, in-process calls | One scaling shape, and discipline you must enforce in review |
| Split on a team, scale, or compliance boundary | An independent release or a tighter data scope | A hop, a timeout, partial failure, and distributed tracing |
| Distributed monolith | A diagram of services | Coupled releases, coupled failure, and none of the independence |
| Synchronous chain on the user path | Easy control flow to read | Latencies add, availabilities multiply down |
| One database transaction while you still have one database | All-or-nothing checkout | You cannot pretend the services are autonomous |
| Saga after a real split | Each service keeps its own commit | Compensations can fail, and the user can observe the middle |
The row people skip is the last pair. Transactions are the right tool when the writes still share a database. A saga is how you recover when they do not. Starting with the saga because you already drew six boxes is backwards. Draw the boxes only after you accept the compensation story, or keep one box.
Deploys and chaos change meaning at a boundary. A canary of tax, judged on tax’s own process health, says nothing about checkout if price and inventory must understand the same discount field. The user-facing SLI has to be the thing the canary watches. A deploy strategy for a distributed monolith is a choreography across repositories. That choreography is the signal you extracted too early.
Pitfalls
- Splitting because the diagram looks modern. The symptom is a lockstep release across repositories for a one-line behavior change.
- Sharing one database among the new services. The symptom is a migration lock that stalls every service, and a restore story that cannot bring one service back alone.
- A synchronous chain on the user path. The symptom is a checkout latency that tracks the slowest downstream p99, and an error budget that blows up while every individual dashboard stays near its target.
- Per-item fanout after the split. The symptom is connection pools exhausted at a traffic level the monolith handled, because one cart became dozens of calls.
- Retrying the chain without an idempotency key. The symptom is double charges and double reservations after a timeout that the client interpreted as “maybe.”
- Adopting a saga while the data is still in one database. The symptom is compensating code for a rollback the database would have done for you.
- Canarying one service against its own CPU. The symptom is a green canary and a red checkout, because the contract between services changed and no local health check calls the whole path.
- Treating an in-process module boundary as optional. The symptom is a monolith you cannot split later, because every module reads every table and there is no line to cut.
In the interview
Start with the user path and one sentence about what is inside the transaction. “Checkout is one deployable and one database transaction. I would split card data out because it has a compliance boundary, and I would keep price, tax, and inventory together until their release cadence or their scale shape diverges.” That is a boundary argument. A slide of twelve boxes is not.
Put a number on the chain if you do split. Six services at an assumed 99.9 percent, independent, land near 99.4 percent, on the order of four hours in a 30-day month if you convert the product into time and say you assumed steady traffic. If you cannot do that arithmetic, you do not have a reason to split.
Skip the org chart and the platform team. The follow-up is almost always “payment succeeded and the next call failed, what does the user see?” Your answer is either “that cannot happen, it is one transaction” or “payment is idempotent, the receipt is retried from an outbox, and here is the compensation if we have to unwind the charge.” Pick the one that matches the boundary you actually drew.
Check yourself
Six services each succeed 99.9 percent of the time, and failures are independent. What is the chain's success probability, and about how many minutes is that in a 30-day month if you convert it naively?
0.999 to the sixth is 0.994015, so about 0.5985 percent of calls fail. A 30-day month is 30 times 86,400, which is 2,592,000 seconds. Times 0.005985 that is about 15,513 seconds, about 259 minutes. One service at 99.9 percent is 43.2 minutes under the same conversion. Say that the conversion assumes steady traffic, and that shared databases make the real failures correlated, so this product is the optimistic case.
Checkout is six services that share the order schema and must release together when the discount field changes. What kind of system is that?
A distributed monolith. The binaries are separate, so you pay network hops and partial failure. The release and the schema are not separate, so you did not get independent change. The fix is to put the discount rule back inside one deployable, or to give one service ownership of that field and a versioned contract the others can deploy against on their own schedule.
A cart of 20 lines calls five downstream services serially per line. Each call costs a 0.5 ms datacenter round trip plus 8 ms of work. What does the user wait, and what did you assume?
Network is 20 times 5 times 0.5 ms, which is 50 ms. Work is 20 times 5 times 8 ms, which is 800 ms. The user waits about 850 ms before any retry. You assumed serial calls, same-datacenter round trips at Dean’s 0.5 ms, and an 8 ms p99 that is an assumption rather than a measurement. Batching or staying in one process removes the product of lines and hops.
Name a split that earns its hop, and a split that does not.
Card data in its own service earns the hop when the rest of the system stores only a token and cannot log the card number. Product search earns a split when it is a different scale shape and checkout does not call it on the pay path. A split of price, tax, and inventory that still shares a schema and deploys as a set does not earn the hop. The test is whether team, scale shape, or compliance forced it.
Payment commits and the receipt call then fails. The data is still in one database. What should you have done instead of a compensating saga?
Keep the checkout in one database transaction so a failed receipt rolls the payment back with it. A saga is the tool you adopt after a real boundary removes the shared transaction. Compensations are extra code, and they can fail, for a rollback the database already knew how to do.
Based on: Designing Data-Intensive Applications, Kleppmann and Riccomini; Marc Brooker and the AWS Builders' Library; Google SRE book.