📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is a bounded context in Domain-Driven Design? How do you find bounded contexts, why does the same word such as "Customer" mean different things in different parts of the business, and how do bounded contexts map to modules, services and teams?

Covers what a bounded context is, heuristics for finding context boundaries, polysemous terms like Customer, and how contexts map to modules, microservices, databases and teams.

Mid-Level Theory Intermediate architecture bounded-context conways-law domain-driven-design modular-monolith ubiquitous-language

🎯 Key points

  • Bounded context = explicit boundary for a model tailored to one part of the business; inside it one ubiquitous language is consistent, and models in different contexts evolve independently
  • Same word, different meaning: Customer in Sales (lead, credit), Billing (payer, invoices), Support (contact, tickets)
  • Discover boundaries with event storming (pivotal events, term disputes), language mapping (glossary), workflow handoffs and team ownership
  • Other signals: different experts own the rules, data changes at different rates or needs different consistency
  • Subdomain = problem space, bounded context = solution space; aim for 1:1 but legacy and complex systems often do not align
  • Each context owns its data; others hold only the identity and learn changes from published events or APIs, never by reading its tables
  • One context per module (modular monolith) or one or more services; one owning team per context (Conway's law)
  • Wrong boundaries create architectural debt across teams: chatty calls, coordinated releases; start coarse and split when the language diverges

⏱ 30-second answer

A bounded context is an explicit boundary around a model tailored to one part of the business, inside which one ubiquitous language is consistent and which can evolve independently of others. Outside it, the same word can mean something else: Customer in Sales is a lead with a credit check, in Billing it is a payer with invoices, in Support it is a contact with tickets. One shared Customer for all three gives a bloated, coupled model.

You discover boundaries with event storming (where experts argue over a term, or a pivotal event like "Order Placed"), a glossary, workflow handoffs and who owns which rules. Each context owns its data; others keep only the identity (CustomerId) and learn about changes through published events or an API, never by reading its tables. A context maps to a module or to one or more services, owned by one team (Conway's law). The trade-off: some duplicated data in exchange for models that change independently.

🗣 Full answer (senior)

How I would answer this in an interview

"A bounded context is the boundary inside which a model means one thing. Inside the Billing context, Customer means the party who pays: they have a billing address, payment terms and invoices. Inside Sales, Customer is someone we're trying to sell to: lead source, credit check, account manager. Inside Support, it's a contact with tickets and an SLA. Those are three different models that happen to share a name and an id. If you force them into one Customer class, every team's change risks breaking the others, and the class collects 80 nullable columns.

To find contexts I listen for where the language changes. In an event storming session you see it when experts argue about what a word means: that's usually a boundary. Other signals are different experts owning the rules, a handoff in the workflow such as 'once the order is placed, fulfilment takes over', and data that changes at very different rates or for different reasons. I also look at the subdomains: ideally each bounded context covers one subdomain, though in legacy systems one big context often covers several, which is exactly the problem.

Once I have boundaries, each context owns its model and its data. Other contexts reference its things by id and learn about changes through events or a published API, never by reading its tables. In a .NET modular monolith that's one module per context, with its own DbContext and schema; in a distributed system it's one or more services per context, but never a service spanning two contexts. And I align them with teams, because of Conway's law: a context owned by two teams quickly becomes two contexts badly glued together. The mistake I see is drawing boundaries by technical layer or by entity, a 'Customer service', instead of by language and capability."


One word, three models

Context "Customer" means Key data Owner
Sales Prospect or account we sell to Lead source, credit check, account manager Sales team
Billing The party who pays Billing address, payment terms, invoices, ABN Finance team
Support A person who raises tickets Contact details, SLA tier, ticket history Support team

Heuristics for finding boundaries

Signal Example
Language changes "Policy" in underwriting (a quote being priced) vs in claims (cover in force on a date)
Different experts Pricing actuaries vs claims assessors
Workflow handoff Order placed → fulfilment → delivery
Different change rates Product catalogue edited daily vs tax rules edited yearly
Different consistency needs Payments must be strict; recommendations can be stale

Mapping to the solution

Option When it fits Watch out for
Module per context in a modular monolith Small to medium teams, early in the product Enforce boundaries with architecture tests and separate schemas
Service per context Independent scaling, deployment or team autonomy needed Distributed systems tax
Several services in one context One context with very different runtime needs (API vs batch) They share a model, so one team owns all of them

Production example

At [a retailer], one shared Customer table with [~90 columns] was edited by four teams, and every schema change needed a cross-team release. Splitting into Sales, Billing and Support contexts, each with its own customer projection keyed by CustomerId and synchronised by events, reduced coordinated releases from [every sprint] to [roughly once a quarter].

🔍 What the interviewer is checking

Checks that the candidate can define bounded contexts, find them in a real business, and connect them to modules, data ownership and teams.

Green flags

  • Uses a concrete "same word, different meaning" example
  • Gives practical heuristics (language, experts, handoffs, change rates)
  • States data ownership: share ids and events, not tables
  • Links contexts to teams via Conway's law and suggests modules before services

Red flags

  • Equates a bounded context with a microservice or a database table
  • Proposes one canonical enterprise model
  • Draws boundaries by technical layer

📚 Learn in depth

1. Model, language and boundary

A model is a simplification built for a purpose. Because purposes differ, one model cannot serve every part of a business well. The boundary makes explicit where a model applies, so a word can be precise inside it.

+---------- Sales ----------+   +--------- Billing ---------+   +-------- Support --------+
| Customer                  |   | Customer (Payer)          |   | Customer (Contact)      |
|  - LeadSource             |   |  - BillingAddress         |   |  - Email, Phone         |
|  - CreditStatus           |   |  - PaymentTerms           |   |  - SlaTier              |
|  - AccountManager         |   |  - Invoices[]             |   |  - Tickets[]            |
+-------------+-------------+   +-------------+-------------+   +------------+------------+
              │   CustomerId + CustomerRegistered event                        │
              +-----------------------------+-----------------------------------+

The shared thing is the identity (CustomerId), not the model.

2. Subdomain vs bounded context

Subdomain Bounded context
Space Problem (how the business is organised) Solution (how the software is organised)
Found by Talking about the business Designing models and boundaries
Ideal Aligned 1:1 with a bounded context Covers one subdomain

3. Finding contexts in practice

  1. Event storming: lay out domain events on a timeline; clusters and pivotal events ("Order Placed") suggest boundaries.
  2. Language mapping: write the glossary; where a term needs two definitions, you have two contexts.
  3. Team and org chart: who owns which rules? (Conway's law cuts both ways.)
  4. Change analysis: which parts change together in git history? Code that always changes together belongs together.

4. Data ownership

Each context is the single writer of its data. Others get data by:

  • Events (CustomerRegistered, BillingAddressChanged) and keeping a local copy of what they need.
  • A published API or open host service.
  • Never by reading or writing the other context's tables.

5. .NET implementation in a modular monolith

src/
  Modules/
    Sales/        Sales.Domain, Sales.Application, Sales.Infrastructure (SalesDbContext, schema 'sales')
    Billing/      Billing.*      (BillingDbContext, schema 'billing')
    Support/      Support.*      (SupportDbContext, schema 'support')
  Host/           ASP.NET Core composition root

Each module exposes a small public contract project (commands, queries, integration events); everything else is internal. Architecture tests stop Billing referencing Sales.Infrastructure.

6. Evolving boundaries

Boundaries are discovered, not decided once. Start with fewer, larger contexts while learning; split when the language diverges or two teams keep colliding. Merging is cheap inside a monolith and expensive across services, which is one reason to start with modules.

Try it yourself

  1. Pick a busy entity in your system (Customer, Product) and list which teams use which columns. Group them.
  2. Write a glossary entry for one term and ask two departments to define it; record the differences.
  3. Run git log --name-only over six months and see which folders change together.
  4. Add a separate DbContext with HasDefaultSchema("billing") for one module and an architecture test enforcing that no other module references it.

💻 Code

Two contexts, two Customer models, linked only by id and an integration event.

// Sales context: its own model of Customer.
namespace Sales.Domain;

public readonly record struct CustomerId(Guid Value);

public sealed class Customer
{
    private Customer() { }
    public Customer(CustomerId id, string name, string leadSource) => (Id, Name, LeadSource) = (id, name, leadSource);

    public CustomerId Id { get; private set; }
    public string Name { get; private set; } = "";
    public string LeadSource { get; private set; } = "";
    public bool CreditApproved { get; private set; }

    public void ApproveCredit() => CreditApproved = true;
}
// Billing context: a different Customer (the payer), with only what billing needs.
namespace Billing.Domain;

public sealed class Payer
{
    private Payer() { }
    public Payer(Guid customerId, string legalName, string? abn) => (CustomerId, LegalName, Abn) = (customerId, legalName, abn);

    public Guid CustomerId { get; private set; }     // shared identity, not a shared model
    public string LegalName { get; private set; } = "";
    public string? Abn { get; private set; }
    public int PaymentTermsDays { get; private set; } = 14;
}
// Published language: the integration event Sales publishes and Billing consumes.
namespace Sales.Contracts;

public sealed record CustomerRegisteredV1(Guid CustomerId, string LegalName, string? Abn, DateTimeOffset OccurredAt);

// Billing handler: translates the event into Billing's own model.
namespace Billing.Application;

public sealed class CustomerRegisteredHandler(BillingDbContext db)
{
    public async Task HandleAsync(Sales.Contracts.CustomerRegisteredV1 e, CancellationToken ct)
    {
        if (await db.Payers.AnyAsync(p => p.CustomerId == e.CustomerId, ct)) return; // idempotent
        db.Payers.Add(new Billing.Domain.Payer(e.CustomerId, e.LegalName, e.Abn));
        await db.SaveChangesAsync(ct);
    }
}

⚠ Common mistakes

  • Mistake: One enterprise-wide Customer model. Why it is wrong: it serves no context well, grows dozens of nullable fields, couples every team's releases, and blurs who owns which data, so two teams overwrite each other's fields and integrity rules conflict. Instead: one model per bounded context, linked by id, with one owner per piece of data.
  • Mistake: Drawing contexts by entity ("Customer service", "Product service"). Why it is wrong: every business process then spans several services, and they end up chatty and coupled. Instead: draw them by capability and language (Sales, Billing, Fulfilment).
  • Mistake: Contexts reading each other's tables. Why it is wrong: schema changes break other contexts silently and ownership disappears. Instead: events or a published API; one writer per table.
  • Mistake: Assuming subdomains and bounded contexts always line up. Why it is wrong: legacy systems often have one context spanning several subdomains, or a subdomain split across contexts, and ignoring that hides the real problem. Instead: map both, aim for 1:1, and treat mismatches as refactoring targets.
  • Mistake: Splitting a context across teams. Why it is wrong: the shared model needs constant negotiation and drifts. Instead: one owning team per context.
  • Mistake: Deciding boundaries once at the start and never revisiting. Why it is wrong: understanding grows and the language diverges. Instead: start coarse, watch for language splits and team collisions, and refactor boundaries, cheaply, inside a modular monolith.
  • Mistake: Treating each context as a microservice by default. Why it is wrong: you pay the distributed systems tax before you know the boundaries are right. Instead: modules first, extract services when there is a reason.

🏛 Senior insight: trade-offs

Bounded contexts are the most valuable idea in DDD because they decide team structure, data ownership and, later, deployment boundaries. Getting them wrong across services is expensive; getting them wrong inside a monolith is a refactor. That asymmetry is why I discover boundaries in a modular monolith first.

The cost of a wrong boundary is architectural debt that spreads across teams: a request that needs five synchronous calls, a 'simple' change that needs three teams to release together, and shared tables nobody dares change. That debt shows up in DORA metrics (lead time and change failure rate) before anyone names it, so I watch those alongside the application map.

Mapping When it fits Cost When not to
Context = module Most new systems, one to four teams Discipline, architecture tests Very different scaling or compliance needs
Context = service Independent teams, scaling, release cadence Network, eventual consistency, ops Boundaries still moving
Shared kernel between contexts Two closely cooperating teams, tiny stable model Coordination on every change Teams in different reporting lines

I measure boundary quality by how often a change needs coordinated releases across contexts and how many cross-context calls a single request makes (Application Insights application map).

🔗 Follow-ups the interviewer may ask

  1. When: Candidate maps bounded contexts to modules in a modular monolith. Why: Checks they can implement and enforce module boundaries in one deployable.
    How to answer

    A modular monolith is one deployable split into modules aligned to business capabilities — Orders, Billing, Catalogue — each with hard boundaries.

    • Each module owns its data: its own schema and DbContext, no cross-module joins or foreign keys.
    • Modules talk only through a public contract (an interface and DTOs) or integration events; everything else is internal.
    • Boundaries are enforced: separate projects, internal types, architecture tests, even per-schema database permissions.

    You get microservice-style boundaries with monolith-style operations: one pipeline, in-process calls, easy refactoring. The trade-off: one runtime, one release and one scaling unit, and it only works if the boundaries are enforced — otherwise it decays into a big ball of mud.

  2. When: Candidate mentions integration events between contexts. Why: Checks contract design and versioning between contexts.
    How to answer

    An integration event is a public API owned by the publisher. Within a version I only make backward-compatible changes: add optional (nullable or defaulted) fields. I never add a required field mid-version (messages already in queues won't have it), and never rename, remove or retype. Consumers are tolerant readers: they ignore unknown fields and default missing optional ones. A breaking change becomes a new event type (orders.order-placed.v2), published alongside v1 until consumers move, then deprecated with a date.

    I wrap events in a CloudEvents envelope (id, source, type, time, dataschema). Each publisher ships its own contracts package or JSON Schema; one shared events library for every service forces lockstep upgrades.

    The trade-off: discipline and some duplication in exchange for independent deployments.

  3. When: Candidate mentions subdomains or the ubiquitous language. Why: Checks the strategic design basics behind bounded contexts.
    How to answer

    Domain-Driven Design is an approach where the software model mirrors the business domain and is built in close collaboration with domain experts. It has two halves. Strategic design splits a large problem into subdomains (core, supporting, generic) and bounded contexts, each with its own model, and maps how they relate. Tactical design gives building blocks for the model inside one context: entities, value objects, aggregates, domain events, repositories and domain services. The glue is the ubiquitous language: the same words in meetings, code, tests and the UI.

    DDD is worth it for a complex, changing core domain that gives the business its edge. For CRUD screens or generic problems (auth, invoicing PDFs) the tactical patterns are ceremony: use strategic thinking everywhere, tactical patterns only where the rules are hard.

🛠 Real-world problems: how you handle them

A shared Customer table blocking four teams
Situation
A [retail] platform had one `Customer` table with [~90 columns] used by Sales, Billing, Support and Marketing, all in one database. [Four] teams, fortnightly releases.
Signals
Every sprint had at least one coordinated release for a customer schema change; a Support change to email validation broke Billing's invoice delivery in production, causing [~2,000] invoices to bounce.
Investigation
Mapped which columns each team read and wrote using Query Store and code search, ran a two-hour language workshop where each team defined 'customer', and looked at git history for files that changed together.
Resolution
Immediately reverted the validation change. Then defined Sales, Billing and Support contexts, gave each its own customer model and schema, published `CustomerRegistered` and `ContactDetailsChanged` events from the owning context, and migrated one context at a time with a backfill.
Prevention
Architecture tests and database permissions stop modules reading other schemas; a glossary per context in the repo; an ADR listing the context map and owners.

How to tell it (STAR)

**S:** At [company], four teams shared one [90-column] Customer table, and a Support change once bounced [2,000] invoices. **T:** I was asked to [propose how to stop teams breaking each other]. **A:** I ran a workshop where each team defined 'customer', showed the column usage I had mapped from Query Store, and proposed three bounded contexts with their own models linked by `CustomerId` and events. I wrote the ADR, got buy-in from the [team leads], and led the migration of Billing first. **R:** Coordinated releases dropped from [every sprint] to [about once a quarter], with no repeat of the invoice incident.

↩ Usually asked after

More in Domain-Driven Design

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me