We once had a customer-service that every other team had to change. Orders needed a new field on the customer, marketing needed consent flags, support needed notes, billing needed a tax ID. Every change meant a cross-team ticket, a coordinated deploy and a schema migration on a table four services read directly. The service was a boundary in name only: it followed a noun, not a responsibility.
This guide is the method we use now to draw service boundaries. It does not start from entities or from the org chart. It starts from two questions: who is allowed to write this data, and how often does the logic around it change? We walk through a worked example, a scoring table you can reuse, and the symptoms that tell you a boundary is in the wrong place. For the bigger picture of splitting a monolith, see our strangler-fig migration guide (post 271).
What a bounded context actually is
In domain-driven design, a bounded context is the area inside which a model and its words have one meaning. "Customer" in sales means a lead with a pipeline stage. "Customer" in billing means a legal entity with a tax ID and payment terms. "Customer" in support means a person with tickets and a satisfaction score. They share an identifier, but they are different models with different rules.
The mistake is to merge them into one Customer table and one service because the word is the same. The better move is to let each context own its own model and share only the identifier and the events that matter.
A bounded context is not automatically a microservice. One service can host several small contexts, and one large context can be split for scaling reasons. But a service boundary that cuts across a context, or merges several, is where most coupling pain comes from.
The two questions that draw the line
1. Who owns the writes?
For every important piece of data, name exactly one place that is allowed to change it. Readers can be many. Writers must be one.
Data | Single writer | Readers |
|---|---|---|
Order lines, order status | Ordering | Fulfilment, billing, analytics |
Invoice, payment status | Billing | Ordering (status only), support |
Shipment, tracking number | Fulfilment | Ordering, notifications |
Marketing consent | Preferences | Marketing, notifications |
If you cannot name a single writer, you have either found a shared kernel (rare, keep it tiny) or a boundary that is drawn wrong.
2. How often does the logic change, and for whose reasons?
Things that change together for the same business reason belong together. Pricing rules that marketing edits weekly should not sit in the same deployable as tax calculation that finance changes once a year after legal review. Different change rates and different decision makers are a strong signal for separate contexts.
We score candidate splits on four axes, each 0-2:
Axis | 0 | 1 | 2 |
|---|---|---|---|
Write ownership | Many writers | Two writers, clear lead | One writer |
Change cadence | Changes in lockstep with neighbour | Sometimes together | Independent |
Transaction need | Needs atomic write with neighbour | Can use saga or outbox | No cross-boundary atomicity |
Team alignment | Shared by several teams | Shared by two | One team owns it |
A split that scores 7-8 is a strong candidate. Below 5, keep it in the same service for now and revisit.
Worked example: a small e-commerce platform
The starting point was a monolith with these modules: catalog, cart, orders, payments, invoices, shipping, customers, notifications, promotions.
First attempt (by nouns)
The first draft split was one service per module. Within weeks the team hit three problems:
ordersandcartchanged together in every checkout feature and both wrote theorder_drafttable.paymentsandinvoicesneeded to be atomic: an invoice must exist before a capture is recorded.customersbecame the shared god table described in the intro.
Second attempt (by ownership and change)
We listed every table, its writers and the last 20 merged pull requests that touched it.
table writers PRs (90d) co-changed with
order_draft cart, orders 31 orders, promotions
orders orders 44 order_draft
payments payments 12 invoices
invoices invoices, payments 9 payments
shipments shipping 17 -
customer_profile customers, orders, support 26 everything
consent customers, marketing 8 notifications
promotions promotions 38 order_draft
The co-change column (from git history) told the real story. The resulting contexts:
Context | Owns | Merged from |
|---|---|---|
Checkout | cart, order drafts, placed orders, applied promotions | cart, orders, part of promotions |
Promotions | campaign rules, coupon codes | promotions (rules only) |
Billing | payments, invoices, refunds | payments, invoices |
Fulfilment | shipments, carriers, tracking | shipping |
Identity | login, profile basics (name, email) | part of customers |
Preferences | consent, notification channels | part of customers |
Notifications | templates, sending, delivery log | notifications |
customers disappeared as a service. Each context kept the slice of "customer" it needed, keyed by customer_id, and Identity publishes CustomerRenamed and CustomerEmailChanged events for the few contexts that copy those fields.
Code that reflects the boundary
Each context gets its own schema and its own module, and other contexts only talk to it through a published API or events:
services/
checkout/
api/ # HTTP + events this context publishes
domain/ # Order, Cart, AppliedPromotion
db/migrations/ # only checkout schema
billing/
api/
domain/ # Invoice, Payment, Refund
db/migrations/
contracts/
events/
checkout.order_placed.v1.json
billing.invoice_paid.v1.json
The contract folder is shared and versioned. Domain folders are not shared: Billing's Invoice class never appears in Checkout's code.
Signs a boundary is wrong
Watch for these after a split. Two or more at once means it is time to redraw.
Lockstep deploys. Service A cannot ship a feature without service B shipping first, every time.
Chatty synchronous calls. One user request makes five calls back and forth between the same two services.
Shared tables. Two services write the same table "just for now".
Distributed transactions everywhere. Most flows need a saga between the same pair of services.
One team, many repos. A single team owns three services that always change together.
Anaemic services. A service that only does CRUD for another service's business logic.
The fix is usually to merge, not to add more infrastructure. Merging two services that always change together is cheaper than building a saga between them.
Shared data without shared tables
When one context needs another's data, pick one of these patterns instead of a cross-service join:
Pattern | When to use | Cost |
|---|---|---|
Call the owner's API at read time | Data must be fresh, low volume | Latency, runtime coupling |
Local read model from events | High read volume, eventual consistency OK | Event handling, backfill |
Carry data in the event payload | Consumer needs a snapshot at event time | Bigger events, schema care |
Reference by ID only | Consumer just links or displays | Extra lookup at display time |
Never give another service a database user on your schema. The moment a second service reads your tables, your schema becomes a public API you cannot change.
Common mistakes
Mistake | Why it hurts | Do this instead |
|---|---|---|
One service per entity | Business flows span many services, every feature is distributed | Group by behaviour and write ownership |
Following the current org chart | Teams reorganise, boundaries should not | Align teams to contexts, not the reverse |
Splitting before the domain is understood | Wrong lines are expensive to move | Start as a modular monolith, extract later |
Shared "common" library with domain models | Hidden coupling through code | Share contracts (schemas), not classes |
Ignoring transaction needs | Sagas everywhere, inconsistent data | Keep atomic data in one context |
A lightweight process for your team
List tables and their writers from code (grep for inserts and updates per module).
Pull co-change data from git: which folders appear in the same merged pull requests.
Score candidate contexts with the four-axis table.
Draft context names and write a one-line purpose for each. If the line needs "and", it may be two contexts.
Run an event-storming or whiteboard session with domain experts to check the words.
Enforce the boundary in code before splitting deployables: module boundaries, lint rules, separate schemas.
Only then extract the first service, picking the one with the highest score and least inbound coupling.
A simple co-change query over git history looks like this:
git log --since=90.days --name-only --pretty=format:'--%H' \
| awk '/^--/{if(n)print s; s=""; n=0; next} NF{split($0,p,"/"); s=s" "p[1]"/"p[2]; n++} END{print s}' \
| tr ' ' '\n' | sort | uniq -c | sort -rn | head -20
It is crude, but it surfaces the pairs of folders that keep landing in the same commits, which is exactly the coupling you want to see before drawing lines.
Key takeaways
A bounded context is where a model and its language mean one thing; the same word can be several models.
Draw boundaries by single write ownership and independent change rate, not by nouns.
Keep data that needs atomic writes inside one context; sagas are for genuinely separate steps.
Share identifiers, events and contracts, never tables or domain classes.
Lockstep deploys and chatty calls between the same two services mean the boundary is wrong; merging is a valid fix.
Enforce boundaries in a modular monolith first, then extract services.
References
Martin Fowler, Bounded Context: https://martinfowler.com/bliki/BoundedContext.html
Martin Fowler, Microservice Prerequisites: https://martinfowler.com/bliki/MicroservicePrerequisites.html
Microsoft Learn, Identify microservice boundaries: https://learn.microsoft.com/en-us/azure/architecture/microservices/model/microservice-boundaries
Microsoft Learn, Using domain analysis to model microservices: https://learn.microsoft.com/en-us/azure/architecture/microservices/model/domain-analysis
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.