Bounded Context in Domain-Driven Design

The age old question, what is a "Bounded Context" in Domain-Driven Design?

- A bounded context is where terms have clear and unambiguous meaning and rules associated with it.

Where do you draw the border of a bounded context?

- The moment a term starts to have more than meaning.

Example Term - Order

Imagine you have a magic word "Order" that means different things in different playrooms of your big online store.

1. Sales Context (The Shopping Room)

  • What it means: In this room, "Order" is when a customer picks their favorite toy, puts it in their cart, and pays for it.
  • Why it's special: Here, "Order" captures everything about buying something—like which toy was chosen, the price, and the customer’s details.

2. Fulfillment Context (The Shipping Room)

  • What it means: In another room, "Order" becomes a list that helps workers pack the toy, choose a box, and send it out the door.
  • Why it's special: This room cares more about how to get the toy from the store to the customer's home, including things like shipping addresses and delivery dates.

3. Customer Service Context (The Help Room)

  • What it means: In this room, "Order" helps when someone needs a little extra help—like fixing a mistake in the address or returning a toy.
  • Why it's special: The details here are used to help the customer and answer questions, rather than to sell or ship the toy.

4. Billing/Payment Context (The Money Room)

  • What it means: In another playroom, "Order" is more about checking that the money paid is right and that all the receipts and invoices are in order.
  • Why it's special: This context focuses on making sure every cent is accounted for and the financial records are correct.

How Do We Decide Where to Draw the Boundaries?

We create these separate rooms—or bounded contexts—when we notice that the same word "Order" has different rules and details in different parts of our business. By drawing these boundaries, each team (like Sales, Shipping, Customer Service, and Billing) can work in their own room without mixing up their special rules.

Each room uses "Order" in a way that makes sense for that part of the business. This keeps everything neat and helps everyone understand exactly what they need to do, just like keeping different LEGO sets in separate boxes makes it easier to build a spaceship and a castle without getting the pieces mixed up.

As usual, it's about splitting responsibilities to make complex systems simpler and easier manage

Adnan Mujkanovic

Adnan Mujkanovic

Full Stack Overflow Developer / YAML Indentation Specialist / Yak Shaving Expert
Gotham City