Catalog My learning Blog
System Design Roadmap: 100-Day Course for Engineers · Phase 6 · Lesson 52 · 4 min read

Microservice Decomposition with DDD Bounded Contexts

On this page
  1. "Product" means three different things
  2. What is a bounded context?
  3. The mistake: splitting by technical layer
  4. How to find bounded contexts
  5. Context maps and anti-corruption layers
  6. Worked example: bounded contexts for e-commerce
  7. Check yourself

"Product" means three different things

Ask three teams what a product is. Catalog says: a title, description, images and category. Inventory says: a SKU with a quantity in each warehouse. Orders says: a line item with the price the customer paid. Same word, three models. A single shared Product class that tries to satisfy all three grows dozens of fields, and every team is afraid to change it.

That's the clue domain-driven design (DDD) uses to find service boundaries.

What is a bounded context?

DDD models software around the business domain and the language experts use. A bounded context is a boundary inside which one model and one vocabulary are consistent. Inside Catalog, "product" means the catalog version. Inside Inventory, it means the stock version. Each context owns its model and its data, and translates at the edges.

Microservice boundaries should usually follow bounded contexts. Each service owns one context's model, data and rules.

That doesn't mean every context must be its own service. Several contexts can live as modules inside one modular monolith (Day 51), each with its own model and tables. The contexts are the design decision; how many deployables you run is a separate one.

Catalog, Inventory and Ordering each have their own model of a product, connected by a context map with a translation layer at the boundary.
Catalog, Inventory and Ordering each have their own model of a product, connected by a context map with a translation layer at the boundary.

The mistake: splitting by technical layer

A common first attempt splits by layer: a "UI service", a "business logic service", a "data service". Every feature then changes all three, and they must deploy together. Or it splits by table: a "customers service" and an "orders service" that call each other for every operation. Both create chatty, tightly coupled services. Split by business capability instead: things that change together, owned by one team.

How to find bounded contexts

  • Listen for words that change meaning between departments: product, customer, order, account.
  • Look for different rules: pricing rules and stock rules evolve separately, for different reasons.
  • Follow the data that changes together: an order and its lines are always written in one transaction, so they belong in one context.
  • Event storming: a workshop where domain experts and engineers lay out business events (OrderPlaced, StockReserved) on a timeline; clusters of events and the people who care about them suggest contexts.

Context maps and anti-corruption layers

Once you have contexts, a context map describes how they relate:

RelationshipMeaning
Customer/supplierOne context depends on another and can ask for changes
ConformistThe downstream simply adopts the upstream's model
Anti-corruption layerThe downstream translates the upstream's model into its own, so outside concepts don't leak in
Published languageContexts communicate through a shared, documented format, such as event schemas

An anti-corruption layer is especially useful next to a legacy system or third-party API: a small adapter converts their concepts into yours, so your model stays clean.

A shared kernel is the relationship to be careful with: two contexts share part of a model, often as a library. In .NET this shows up as a Company.Domain.Models NuGet package with the one true Product class, referenced by six services. Every change to it forces six services to upgrade together, which is the coupling bounded contexts were meant to remove. Share small, stable things, such as a Money type, and let each context define its own Product.

Worked example: bounded contexts for e-commerce

ContextOwnsKey events
CatalogDescriptions, images, categoriesProductPublished
PricingPrices, promotionsPriceChanged
InventoryStock per warehouse, reservationsStockReserved, StockReleased
OrderingOrders, lines with paid pricesOrderPlaced
PaymentsCharges, refundsPaymentCaptured
ShippingShipments, trackingShipmentDispatched

Ordering stores a snapshot of name and price on each line instead of joining to Catalog and Pricing at read time. Each context can change its own model without asking the others, as long as its events stay compatible.

Check yourself

Contexts group the data and rules that change together for one business purpose. Table-based services end up calling each other constantly and changing together.

A shared model across contexts couples them. Let each service own its own model and communicate through APIs or events, sharing only small stable types.

Translating another system's model, often a legacy or external one, into your context's own model, so foreign concepts don't leak into your code.

Look for places where the same word means different things, like "product" in catalog, inventory and shipping, and for groups of concepts that change together. Event storming workshops with domain experts are a common way to surface them.

Every feature then needs changes in every layer, so teams can't deliver independently and every call crosses a network. Split by business capability so a feature usually lives inside one service.