Abekus — AI learning and job matching platform logo

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:

TermMeaning in orderingExample
OrderA customer's request for foodorderId 42, ₹450
PENDINGPlaced, not yet acceptedOrder 42 just after checkout
CONFIRMEDRestaurant accepted itOrder 42 after restaurant 3 says yes
CANCELLEDWill not be fulfilledOrder 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:

ContextWhat Order meansWhat it cares about
OrderingWhat the customer asked for, and its statusorderId 42, items, PENDING or CONFIRMED
PaymentAn amount to collectorderId 42, ₹450
RestaurantA ticket to prepareorderId 42, restaurantId 3
DeliveryA pickup and drop-off joborderId 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.

SetupWho sets status of order 42Result
SplitTwo servicesTwo answers that can differ
One ownerorder-service onlyOne 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 holdspayment-service does not hold
orderId 42, ₹450 collectedItems, 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 saysDelivery context keeps as
Restaurant name for restaurantId 3Pickup name
Address line of restaurant 3Pickup address
Menu and opening hoursNot taken

Lessons in How a Microservices System Fits Together

  1. Tracing one quickbite order across services
  2. Monolith vs microservices trade-offs
  3. Bounded context per service
  4. Synchronous rest vs asynchronous events
  5. Api gateway as the single entry point

81 lessons across 9 topics. See the full course