Bounded context per service
Lesson 3 of 81 in Microservices Interview Mastery. Free to read, no account needed.
What a bounded context is
A bounded context is a boundary inside which one domain model and its terms have a single, consistent meaning. Outside that boundary, the same words may mean something different, and that is fine.
This tells you where a microservice should stop. QuickBite's order-service owns the ordering context, the place where a customer's request for food becomes an order. Knowing that edge up front keeps each service's model small and clear.
Ubiquitous language
The ubiquitous language is the shared vocabulary a team uses inside one bounded context. Each term has one precise meaning, so developers and business people use the same words for the same things.
In the ordering context, these terms have fixed meanings for order 42, placed by customer 7 at restaurant 3 for ₹450:
| Term | Meaning in ordering | Example |
|---|---|---|
| Order | A customer's request for food | orderId 42, ₹450 |
| PENDING | Placed, not yet accepted | Order 42 just after checkout |
| CONFIRMED | Restaurant accepted it | Order 42 after restaurant 3 says yes |
| CANCELLED | Will not be fulfilled | Order 42 after rejection |
Finding the boundary
Boundaries often show up where the same word changes meaning. Look at what the word Order means in each part of QuickBite for order 42:
| Context | What Order means | What it cares about |
|---|---|---|
| Ordering | What the customer asked for, and its status | orderId 42, items, PENDING or CONFIRMED |
| Payment | An amount to collect | orderId 42, ₹450 |
| Restaurant | A ticket to prepare | orderId 42, restaurantId 3 |
| Delivery | A pickup and drop-off job | orderId 42, a rider assigned |
Each change in meaning marks a likely edge between contexts.
One owner per context
Each microservice owns exactly one bounded context, along with its model and its data. A context is never split across services, because two services that both decide the same fact will eventually disagree about it.
Imagine two services that both set the status of order 42. One sets it to CONFIRMED while the other still shows PENDING. Keeping the order context in order-service means it alone decides whether order 42 is CONFIRMED or CANCELLED, so there is only one answer to give.
| Setup | Who sets status of order 42 | Result |
|---|---|---|
| Split | Two services | Two answers that can differ |
| One owner | order-service only | One answer everyone trusts |
Holding IDs, not copies
When one context refers to something owned by another, it holds only that thing's identifier. Payment-service needs to know which order it is charging, so it stores orderId 42 and the ₹450 it collected. It does not keep a copy of the whole order with its items, address and status.
A copied status goes stale. If order 42 is cancelled in ordering, a copy inside payment still says CONFIRMED. Holding only the ID means payment always asks the owner for the current status.
| payment-service holds | payment-service does not hold |
|---|---|
| orderId 42, ₹450 collected | Items, delivery address, a copy of status |
Translating at the boundary
Translation at the boundary means that when one context needs another context's data, it converts that data into its own terms instead of adopting the foreign model. Delivery-service needs to know where to pick up order 42, so it reads restaurant 3's details.
It does not take the restaurant's whole model, with its menu, opening hours and pricing. It builds its own pickup record with only the fields it needs, using its own words for them.
| Restaurant context says | Delivery context keeps as |
|---|---|
| Restaurant name for restaurantId 3 | Pickup name |
| Address line of restaurant 3 | Pickup address |
| Menu and opening hours | Not taken |
Lessons in How a Microservices System Fits Together
- Tracing one quickbite order across services
- Monolith vs microservices trade-offs
- Bounded context per service
- Synchronous rest vs asynchronous events
- Api gateway as the single entry point
81 lessons across 9 topics. See the full course