Skip to content

Bounded Contexts Before the Service Split

Before I split services, I clarify domain boundaries. A bounded context is a language boundary and a possible, but not mandatory, service split.

≈ 11 min readSoftwareArchitecture

Bounded Contexts Before the Service Split

If you fix the number of services before the domain boundaries are settled, you do not remove coupling – you distribute it over the network. The split then separates code, but not responsibilities: a change to a single term still runs through three systems, only now with HTTP in between and three teams that have to coordinate.

The boundary that is missing beforehand is not a technical one. It runs where a word stops meaning the same thing.

The architecture emerges at the language boundaries and at the translations between them.

Domain boundaries before technical splits

  • Subdomain · describes a domain problem space
  • Bounded context · gives terms and rules an unambiguous scope
  • Model · implements the language within this boundary
  • Context map · names dependencies and influence between contexts
  • Anti-Corruption Layer · translates a foreign model into your own language
  • Service · can run a boundary, but does not automatically define it

This keeps boxes from becoming an end in themselves. What matters is where meaning changes and who is responsible for that translation.

Why the order decides the outcome#

The question monolith migrations usually start with is: “How many microservices do we break the monolith into?” It is already the wrong question. The number is a result, not a target. What needs clarifying is where the domain boundaries lie – and whether you can name a separate, internally consistent language for each boundary. How many services that turns into becomes clear afterwards.

The reason is economic. A service split is cheap to draw and expensive to correct once teams, deployments and databases depend on it. A domain boundary, on the other hand, can be moved on the whiteboard as long as it is still a model and not infrastructure. That is why I invest the first week of such a project in language and not yet in infrastructure and deployment diagrams. The business result is measurable: shorter change cycles, because a change stays within one context; less friction between teams, because nobody trips over shared tables; higher quality, because the model reflects the domain instead of an accidental technical structure.

The bounded context is a language boundary#

Eric Evans coined the term in 2003 in Domain-Driven Design, and Martin Fowler summed it up in his bliki: a bounded context is the area in which exactly one model and exactly one ubiquitous language apply. Within this boundary, every word means exactly one thing. Across the boundary, the same word may mean something else – that is where the real gain lies.

An example from retail: the word “Product.” In sales, a Product is a thing with a price, a description and availability. In the warehouse, the same Product is an SKU with stock, a storage location and a reorder point. In accounting, it is a line item with a tax rate and a revenue account. Three contexts, three legitimate meanings. The classic mistake is to try to build a single canonical Product object out of this that does justice to all three. The result is a class with forty fields, of which each context ignores ten – and every change affects all three teams.

Fowler names not technology but “human culture” – language and organization – as the dominant factor in drawing these boundaries. This is where Conway’s Law comes in: context boundaries and team boundaries influence each other. If I draw a clean boundary but two teams have to work on it together, I am drawing it in the wrong place.

In practice, I test a suspected boundary with two questions. First: can I say a sentence in this context that a domain expert from the neighboring context no longer understands unambiguously without translation? If so, these are two languages and therefore two contexts. Second: is there a rule that applies exactly here and not next door – for example “a Product without stock is still visible in sales, but does not exist in the warehouse”? Such rule breaks are the most reliable boundary markers I know. They come up in conversations with domain experts, not in the class diagram, and that is exactly why I only find them if I listen first instead of modeling.

Sort subdomains, implement bounded contexts#

Before I draw boundaries, I sort the problem space. Strategic DDD separates problem space and solution space. The subdomains live in the problem space, and I categorize them into three classes:

The core domain is what a company does better than its competitors – that is where the best team and most of the modeling work belong. Supporting subdomains are necessary, but not a differentiator; solid standard work is enough here. Generic subdomains are solved problems such as authentication, accounting or notifications; I buy or standardize them instead of building them myself.

This classification is a business decision, not a technical one. It answers the question of where effort pays off. Bounded contexts are then the answer in the solution space: ideally, one subdomain corresponds to exactly one bounded context. In reality, they rarely match – a system that grew historically often cuts across. But the core/supporting/generic classification tells me at which boundary I need precision and where pragmatism is enough.

The edges are the architecture, not the boxes#

Isolated models are not a system yet. The system emerges from the relationships between the contexts, and naming these relationships is the core of the work – context mapping. Without a context map, you get exactly what Evans calls a “distributed Big Ball of Mud”: many services that all depend on each other, without anyone controlling the translation.

I draw a context map as boxes with edges. The boxes are the contexts, each with its own language. The edges are what is interesting: who is upstream (determines the model), who is downstream (has to adapt)? Who translates, who publishes?

graph LR
  subgraph U["Upstream"]
    INV["Inventory<br/>Product = SKU + stock"]
  end
  subgraph D["Downstream"]
    SAL["Sales<br/>Product = price + description"]
    BIL["Billing<br/>Product = tax + revenue account"]
  end
  INV -->|"OHS / PL"| SAL
  SAL -->|"ACL"| BIL
  INV -.->|"SK shared kernel"| SAL

The labels carry the statement. An Open Host Service with a Published Language (OHS/PL) on the upstream side means: Inventory offers a stable, documented interface that many can connect to. An Anti-Corruption Layer (ACL) on the downstream side means: Billing actively protects its model from foreign terms. A Shared Kernel (SK) means: two contexts deliberately share a small common model – and with it, coupling.

The decisive point: the later service split is laid on top of this context map. First it exists, then I decide which context becomes one service, which becomes two, and which stay deployed together. The bounded context is the model boundary, the service the deployment unit. Vladik Khononov put it aptly in 2018: bounded contexts are not microservices. A service can be part of a context, and a context can span several services.

The pattern that saves the most friction: the Anti-Corruption Layer#

Of all context mapping patterns, the Anti-Corruption Layer is the one whose absence I most often see paid for dearly. As soon as a cleanly modeled context borders on a legacy or third-party system, it needs a translation layer. Without it, the foreign model – often a bad one – seeps into my core. What starts as “we’ll adapt briefly” (Conformist) silently becomes the permanent solution.

Concretely: my Sales context knows a clean Product. The Inventory system speaks in LegacyInventoryResponse with sku and price_cents. I never let these foreign DTOs into my domain model. An adapter translates in exactly one place:

// Downstream context: Sales
interface CatalogPort {
    Product findById(ProductId id);
}

// ACL: isolates the upstream "Inventory" model.
// Only this class knows the foreign DTOs; the domain never does.
class InventoryAntiCorruptionLayer implements CatalogPort {

    private final LegacyInventoryClient legacyClient;

    @Override
    public Product findById(ProductId id) {
        LegacyInventoryResponse raw = legacyClient.get(id.value());
        return new Product(
            new ProductId(raw.sku),
            Money.of(raw.price_cents) // translate cents into the domain type
        );
    }
}

The gain is not cosmetic. When the Inventory team changes its format, exactly one class changes. My core stays stable, my tests stay green, and the translation is documented instead of scattered across the code. That is the difference between a boundary that holds and one that leaks.

The flip side applies to the Shared Kernel: I only use it when two teams work in a real partnership and deliberately want the coupling. A shared model means shared change – every adjustment forces both teams to coordinate. Misused as the default, the Shared Kernel becomes a brake. When in doubt, I give each context its own model and connect them through a Published Language.

Between Conformist and ACL there is a cost trade-off, and it should be spelled out. Conformist means: we take over the foreign model one to one and save ourselves the translation. That is legitimate when the upstream is stable and its model fits your own – for example with a generic subdomain that is only integrated anyway. But as soon as your own core is affected or the upstream has a weak model, the translation layer you saved becomes a deferred debt. The ACL costs its setup once and pays back with every foreign change. I do this calculation explicitly instead of leaving the decision to the chance of the first integration sprint. In practice, I write it down as a short decision: which foreign model are we coupling to, how stable is it, what would a change cost us? Once you have answered this question deliberately, you no longer make it by accident under time pressure.

Recording boundaries declaratively#

So that the context map does not rot as a photo of the whiteboard, I record it in a versionable form. With Context Mapper and its DSL, I write the relationships as text that sits in the repository next to the code and is versioned with every change:

ContextMap ShopMap {
    contains Sales, Inventory, Billing

    Inventory -> Sales : Customer-Supplier {
        implementationTechnology = "REST"
        downstreamRights = INFLUENCER
        exposedAggregates = Product
    }

    Sales -> Billing : Conformist {
        implementationTechnology = "Messaging"
    }
}

This is not an end in itself. The value lies in the fact that the relationship – Customer-Supplier, who is upstream, which aggregate is exposed – is documented in a verifiable way. A new developer can read in one place how the contexts fit together instead of reconstructing it from call chains. I have discussions about boundaries on the diff of this file, not on the next wiped-clean whiteboard.

How I proceed in practice#

My process is deliberately unspectacular and needs no toolchain. I get the domain experts and one or two developers into a room and let them tell the business flow – for larger domains, I use Event Storming as a discovery technique to get the events onto the wall. While doing so, I listen for breaks in language: as soon as the same word means two different things, I have probably found a context boundary. Then I name the contexts, classify them into core, supporting and generic, and draw the edges with their patterns. I immediately mirror every suspected boundary back to the domain experts: I retell the flow in their language and watch where they correct me. These corrections are worth their weight in gold, because they show me the places where my model and the domain as actually practiced still diverge. Only after that – and often only weeks later – do we talk about services, repositories and deployment.

To technology-driven teams, this approach feels slow at first. It is the opposite. The weeks I invest in language up front I save three times over later, because I no longer have to correct boundaries through a production system. Simple and elegant here means: few, well-founded boundaries instead of many accidental ones.

Conclusion#

The common thread is an order. First the language: where does which model apply, where does a term break? That is the bounded context. Then the relationships: who is upstream, who translates, where do I protect my core with an Anti-Corruption Layer, where do I couple deliberately through a Shared Kernel? That is the context map. And only at the very end the deployment unit: which context becomes a microservice?

If you stick to this order, you can align services with domain boundaries instead of cutting them along technical layers. If you reverse it and count services before you understand the language, you risk a distributed Big Ball of Mud with more network in between. First comes the model boundary, then the decision about operations. Not every bounded context has to become its own service.

Further reading#

Revised and translated from German with the help of AI.