Pull up a chair. I want to start with a small puzzle, because it explains more than any definition will.

Imagine a company that sells insurance online. Ask the sales team what a “customer” is, and they will say: anyone who has bought a policy. Ask the claims team, and a customer is anyone who has filed a claim, which might include a person who is not the policyholder at all. Ask finance, and a customer is whoever pays the premium, which could be an employer. Ask the marketing team, and a customer is anybody on the mailing list, including people who have never paid a rupee.

Four teams, one word, four meanings. Now someone on the engineering side says, “Let’s build one Customer table that everybody uses.” You can probably already see where this goes.

The giant shared model

The one-model approach feels sensible because duplication is something every developer is trained to dislike. So the Customer class grows. It gets a policy list, a claims list, a billing address, a marketing consent flag, a lead source, a risk score. Every team adds fields. Nobody can remove any, because nobody is sure who still reads them.

Within a year, a change that marketing wants (say, splitting “name” into first and last) breaks the claims screens. A release needs three teams to agree. Testing takes long because a small change touches everything. This is the real cost of a single model: not ugliness, but coupling between groups of people who should be able to move independently.

Domain-Driven Design, the approach Eric Evans described in his 2003 book of that name, offers a different answer. Instead of forcing one model on the whole company, draw boundaries. Inside each boundary, a word means exactly one thing. That boundary is a bounded context.

What a context actually is

A bounded context is not a folder or a microservice, though it often ends up being implemented as one. It is a linguistic and conceptual boundary. Inside the “Claims” context, a Claimant has a date of loss, a list of documents and a status. Inside “Policy Administration”, a Policyholder has coverage, a sum insured and a renewal date. They may refer to the same human being, but the software models only what each context cares about.

Evans pairs this with the idea of a ubiquitous language: inside a context, developers, analysts and business people use the same vocabulary, and the code uses it too. If the claims adjuster says “reopen the claim”, there should be an operation called reopen on a claim, not a method called setStatus that someone has to know to call with a magic value. When the language in meetings and the language in code drift apart, misunderstandings are almost guaranteed.

The word “ubiquitous” can mislead you. It means ubiquitous within one context, not across the company. The whole point is that you stop pretending there is one company-wide dictionary.

How contexts talk to each other

Contexts are not islands. A claim refers to a policy; billing needs to know about new policies. DDD gives you vocabulary for these relationships, in what it calls a context map. A few patterns are worth knowing:

  • Shared kernel: two contexts deliberately share a small piece of model and agree to change it together. Useful, but it re-creates the coupling you were escaping, so keep it tiny.
  • Customer and supplier: one context depends on another, and the upstream team agrees to take the downstream team’s needs into account.
  • Conformist: you simply accept the upstream model as it is, because you have no influence over it. Common when you consume a government or bank API.
  • Anti-corruption layer: you put a translation layer between your clean model and someone else’s messy one, so their vocabulary does not leak into yours.

The anti-corruption layer deserves a moment. Suppose your new claims system must read from a twenty-year-old policy mainframe where a policy’s state is a two-letter code. Rather than let those codes spread through your new code, one small adapter translates them into your own concepts at the edge. When the mainframe is eventually retired, only the adapter changes.

Aggregates, briefly

Inside a context, DDD suggests grouping objects into aggregates: a cluster that must stay consistent together, with one entry point called the aggregate root. A claim, with its line items and its documents, might be one aggregate. The rule is that outside code talks only to the root, and a single transaction should normally change only one aggregate.

This is not an academic nicety. It gives you a principled answer to “how big should my transaction be?” and, later, to “where could I split this into a separate service?”. Anything that needs to be updated atomically belongs inside one aggregate. Anything that can be eventually consistent can sit in another aggregate, or another context, and be updated through an event or a message.

Finding the boundaries

This is the hard part, and no tool does it for you. A few signals help:

  • The same word is used with different meanings by different groups (our “customer” example).
  • Different groups need to change things at different speeds. Marketing experiments weekly; regulatory reporting changes once a year.
  • Different rules apply. Claims have strict audit and legal requirements; a promotional banner does not.
  • There is a natural owner. If you cannot name one team accountable for a concept, the boundary is probably wrong.

A workshop technique called Event Storming, created by Alberto Brandolini, is popular here. People put sticky notes of business events (“Policy Issued”, “Claim Filed”, “Premium Received”) on a long wall in time order, and the clusters of events and the points where vocabulary changes tend to reveal the contexts. It is cheap, and it puts business people in the room, which is the real value.

Leave a Reply

Trending