What Is a Bounded Context?

Bounded contexts explained: why one model cannot serve a whole business, how to find context boundaries, how contexts relate on a context map (shared kernel, customer–supplier, anti-corruption layer and more), and how contexts map to modules, services and teams.

On this page

Simple definition#

A bounded context is an explicit boundary within which a particular domain model applies, and within which every term in the ubiquitous language has exactly one meaning.

Outside the boundary, the same word may mean something else, and that is acceptable. The boundary makes the difference explicit instead of leaving it hidden in one overloaded class.

The problem: one word, several meanings#

In the retailer from DDD Fundamentals, the word “product” is used by every team:

TeamWhat “product” means to themAttributes they care about
CatalogueSomething we sell, as shown to customersName, description, images, category
InventoryA stock-keeping unit in a warehouseSKU, quantity on hand, bin location, reorder point
OrderingA line on a customer’s orderProduct ID, price at the time of purchase, quantity
ShippingA physical item to pack and sendWeight, dimensions, hazardous-goods flag

A single shared Product class grows to serve all four. Each team’s changes risk breaking the others. Subtle conflicts appear: when the catalogue price changes, should existing orders change? (No — but a shared model makes that bug easy to write.)

The same happens with “customer” (a shopper, a billing account, a delivery recipient), “order” and “account”.

Why it matters#

  • Clarity. Inside a context, terms are precise, and the model can be rich without compromise.
  • Autonomy. A team can change its model without coordinating with every other team, as long as it honours its published contracts.
  • Boundaries for architecture. Bounded contexts are the most reliable starting point for module boundaries in a modular monolith and for service boundaries in microservices.
  • Integration made explicit. Because models differ, integration requires deliberate translation, which is visible and testable.

Core concept#

A context is a boundary around a model#

The same real-world thing, modelled differently in each context
flowchart TB
    subgraph Catalogue["Catalogue context"]
        C["CatalogueItem<br/>name · description · images"]
    end
    subgraph Inventory["Inventory context"]
        I["StockItem<br/>sku · onHand · reorderPoint"]
    end
    subgraph Ordering["Ordering context"]
        O["OrderLine<br/>productId · unitPrice · quantity"]
    end
    subgraph Shipping["Shipping context"]
        S["ParcelItem<br/>weight · dimensions"]
    end
    ID(("Product ID<br/>shared identifier"))
    ID -.-> C
    ID -.-> I
    ID -.-> O
    ID -.-> S

The contexts share an identifier, not a model. Each context stores the attributes it needs, in the shape it needs them.

Subdomain versus bounded context#

These two concepts are often confused:

SubdomainBounded context
Belongs toThe problem space — how the business is dividedThe solution space — how the software is divided
Discovered or designed?Discovered by analysing the businessDesigned by the team
Example“Inventory management”The inventory module or service and its model

Ideally there is one bounded context per subdomain, but not always. A legacy system may span several subdomains in one context, and a large subdomain may be split into several contexts.

Finding boundaries#

Heuristics that help:

  1. Language changes. When domain experts use the same word differently, or different words for the same thing, a boundary is near.
  2. Different experts. The people who know the rules for pricing are not the people who know warehouse operations.
  3. Different rates of change. Promotions change weekly; tax rules change yearly.
  4. Different consistency needs. Order placement needs immediate consistency for its own invariants; stock levels across warehouses can be eventually consistent.
  5. Business capabilities. “Take orders”, “manage stock”, “ship parcels” are natural units.

Event Storming — a workshop technique created by Alberto Brandolini — is a popular way to discover these boundaries with domain experts.

Context mapping#

A context map shows the bounded contexts and the relationships between them. Relationships describe both technical integration and team dynamics: who depends on whom, and who must adapt.

Upstream contexts influence downstream contexts. If the upstream changes its model or API, the downstream is affected — not the reverse.

Context map for the retailer
flowchart LR
    Catalogue["Catalogue"]
    Ordering["Ordering<br/>(core)"]
    Inventory["Inventory"]
    Payments["Payments provider<br/>(external)"]
    Shipping["Shipping"]
    Carrier["Carrier API<br/>(external)"]

    Catalogue -- "U → D · Open Host Service /<br/>Published Language" --> Ordering
    Ordering -- "U → D · Customer–Supplier<br/>(OrderPlaced events)" --> Inventory
    Payments -- "U → D · Anti-Corruption Layer<br/>(in Ordering)" --> Ordering
    Ordering -- "U → D · Customer–Supplier<br/>(OrderPaid events)" --> Shipping
    Carrier -- "U → D · Anti-Corruption Layer" --> Shipping

The relationship patterns#

PatternMeaningWhen to use it
PartnershipTwo teams succeed or fail together and coordinate closelyTightly linked contexts owned by cooperating teams
Shared KernelTwo contexts share a small, explicitly agreed part of the model (and its code)Small, stable concepts such as Money, with joint ownership. Keep it tiny.
Customer–SupplierThe upstream (supplier) plans its work around the downstream’s (customer’s) needsInternal teams where the downstream has a voice in the upstream’s priorities
ConformistThe downstream adopts the upstream model as-isThe upstream will not change for you, and its model is good enough
Anti-Corruption Layer (ACL)The downstream builds a translation layer to protect its modelThe upstream model is awkward, legacy or external
Open Host Service (OHS)The upstream offers a well-defined protocol for any consumerMany downstream consumers
Published LanguageA documented shared exchange format, such as an event schema or a standardOften combined with OHS
Separate WaysNo integration; the contexts solve their needs independentlyIntegration costs more than duplication

The Anti-Corruption Layer#

The ACL is the most frequently used defensive pattern. It translates an upstream model into the downstream’s own language, so that foreign concepts never leak in. In code, it is built from Adapters, facades and translators.

// Ordering's port, in Ordering's language.
public interface PaymentPort {
    PaymentOutcome charge(OrderId orderId, Money amount);
}

// The ACL: translates the provider's model (minor units, status codes,
// vendor exceptions) into Ordering's model. Nothing vendor-specific escapes.
final class ProviderPaymentAdapter implements PaymentPort {
    public PaymentOutcome charge(OrderId orderId, Money amount) {
        ProviderChargeResponse r = client.createCharge(
                orderId.toString(), toMinorUnits(amount), amount.currency().getCurrencyCode());
        return switch (r.status()) {
            case "succeeded" -> new PaymentOutcome.Approved(r.id());
            case "card_declined", "insufficient_funds" -> new PaymentOutcome.Declined(r.status());
            default -> throw new PaymentProviderException("Unexpected status " + r.status());
        };
    }
}

Bounded contexts, modules, services and teams#

A bounded context is a model boundary. How it is deployed is a separate decision:

ImplementationDescriptionTrade-off
Package or module in a monolithEach context is a module with enforced boundariesSimple operations and local transactions; requires discipline to keep boundaries
Separate serviceEach context is deployed independentlyIndependent deployment and scaling; network and consistency costs
Several contexts in one serviceA service hosts a few small, related contextsPragmatic for small teams

Conway’s Law applies: contexts work best when each is owned by one team. A context owned by three teams tends to fragment; a team owning ten contexts tends to blur their boundaries.

Integration between contexts#

StyleExampleCoupling
Synchronous API (REST, gRPC)Ordering asks Catalogue for the current priceRuntime coupling: Ordering fails if Catalogue is down
Asynchronous eventsOrdering publishes OrderPlaced; Inventory reserves stockTemporal decoupling; eventual consistency
Data replicationOrdering keeps a local copy of prices, updated by PriceChanged eventsFast local reads; copies may be briefly stale

Events crossing a context boundary are integration events: part of the published contract, versioned and stable. They are distinct from domain events used inside a context, which can change freely with the model.

Common mistakes#

  • Boundaries along technical layers. “The database context” and “the UI context” are not bounded contexts. Boundaries follow the domain.
  • Contexts that are too small. One context per entity (“the Address context”) produces chatty integration and distributed transactions.
  • A Shared Kernel that keeps growing. Every addition couples two teams more tightly. Keep it to small, stable value types.
  • Ignoring the context map. Undocumented relationships make it unclear who must adapt when an upstream changes.
  • Leaking upstream models. Using a provider’s DTOs directly in your domain makes you a Conformist by accident.

Interview questions and answers#

What is a bounded context? An explicit boundary within which a domain model is consistent and each term in the ubiquitous language has one meaning. Different contexts may model the same real-world concept differently.

How is a bounded context different from a subdomain? A subdomain is part of the business problem and is discovered. A bounded context is part of the software solution and is designed. Ideally they align one to one.

Is a bounded context the same as a microservice? No. A bounded context is a model boundary. It can be implemented as a module in a monolith, as one service, or occasionally as several services. A microservice should not span several contexts.

What is an Anti-Corruption Layer? A translation layer that a downstream context builds to protect its model from an upstream model it cannot or should not adopt — such as a legacy system or an external API. It is typically built from adapters and translators.

How do you find bounded context boundaries? Listen for changes in language, look at which experts own which rules, and consider rates of change, consistency requirements and business capabilities. Workshops such as Event Storming help.

Summary#

  • A bounded context is a model boundary within which language is unambiguous.
  • Different contexts may model the same concept differently; they share identifiers, not models.
  • Context maps document upstream/downstream relationships and integration patterns.
  • The Anti-Corruption Layer protects a model from foreign ones.
  • Contexts guide module and service boundaries, but a context is not automatically a microservice.

References#

  • Eric Evans. Domain-Driven Design. Addison-Wesley, 2003. Part IV, “Strategic Design”.
  • Martin Fowler. “BoundedContext”, 2014.
  • Vaughn Vernon. Domain-Driven Design Distilled. Addison-Wesley, 2016.
  • Alberto Brandolini. Introducing EventStorming. Leanpub.
  • DDD Crew: Context Mapping — reference cards for the relationship patterns.