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

📚 Interview question

What is context mapping in Domain-Driven Design? Explain the main relationship patterns (partnership, shared kernel, customer-supplier, conformist, anti-corruption layer, open host service and published language, separate ways) and how you choose between them for a real integration.

Covers DDD context maps, the upstream/downstream relationship and each context-mapping pattern, with how team power, model quality and change rate drive the choice.

Senior Theory Advanced anti-corruption-layer architecture bounded-context context-mapping domain-driven-design integration

🎯 Key points

  • Context map = diagram of bounded contexts and the team and model relationships between them
  • Upstream (U) influences downstream (D); the patterns describe who adapts to whom
  • Partnership and shared kernel: tight cooperation; shared kernel only if both teams accept joint approval of every change
  • Customer-supplier: downstream needs are in the upstream's planning; conformist: downstream adopts the upstream model as-is
  • Anti-corruption layer: downstream translates the upstream model to protect its own (legacy, third party, poor model)
  • Open host service + published language: upstream offers a stable, documented protocol (versioned API, event schema) for many consumers
  • Choice depends on team power, upstream model quality, number of consumers and how core the downstream is; separate ways when integration costs more than it delivers
  • The map is a living artefact: keep it in the repo and update it after reorganisations, vendor changes and new integrations

⏱ 30-second answer

A context map shows the bounded contexts and how their teams and models relate. Each relationship has an upstream (whose model influences others) and a downstream. The patterns describe who adapts: partnership (teams succeed or fail together), shared kernel (a small model both own), customer-supplier (upstream plans for downstream needs), conformist (downstream simply adopts the upstream model), anti-corruption layer (downstream translates to protect its model), open host service with a published language (upstream offers a stable, versioned protocol for many consumers) and separate ways (do not integrate).

I choose by power (can I influence the upstream?), upstream model quality, how core my context is and how many consumers exist. The trade-off is translation cost versus model purity: an ACL costs code, conforming costs your model.

🗣 Full answer (senior)

How I would answer this in an interview

"A context map is the picture of how bounded contexts relate, and it is as much about teams and politics as about code. Every relationship has an upstream, whose decisions affect others, and a downstream that is affected. The patterns are really answers to 'who adapts to whom, and how much do they cooperate?'

At the cooperative end there is partnership, where two teams plan together and release together, and shared kernel, a small piece of model, say a Money type and a few ids, that both own and change only by agreement. Customer-supplier is the common healthy case: the upstream team treats the downstream as a customer, includes their needs in planning, and they agree contract tests. When the upstream will not or cannot change, like a SaaS provider or a team in another division, you either conform, adopting their model as-is, which is fine if their model is good and your context isn't core, or you build an anti-corruption layer that translates their model into yours. And when an upstream has many consumers, it should offer an open host service with a published language: a versioned API or event schema, documented, that nobody gets special treatment on. Finally, separate ways: sometimes the right integration is none.

For example, at [company] our [claims] context depended on a [legacy policy system] whose model had a single POLICY_STATUS code with [27] values. Claims was our core domain, the upstream would not change, and its model was poor, so I argued for an anti-corruption layer over conforming. We translated the codes into our own CoverStatus value object in one adapter, and when the legacy system was replaced [two years] later we rewrote only that adapter, [about 600 lines], and none of the claims domain. The mistake I see is teams conforming by accident: they deserialise the vendor's DTOs straight into their domain and the vendor's model spreads everywhere."


The patterns

Pattern Who adapts Cooperation Use when
Partnership Both High, joint planning Two teams whose goals succeed or fail together
Shared kernel Both, by agreement High A tiny, stable model both need (ids, Money)
Customer-supplier Upstream accommodates Medium, negotiated Same organisation, upstream willing to prioritise downstream
Conformist Downstream adopts upstream model Low Upstream model is good enough and you cannot influence it
Anti-corruption layer Downstream translates Low Upstream model is poor, legacy or third party, and your context is core
Open host service + published language Consumers use a stable protocol One to many Upstream serves many consumers
Separate ways Nobody None Integration costs more than it delivers

Choosing a relationship

Factor Leans towards
You can't influence the upstream, model is decent Conformist
You can't influence the upstream, model is poor, your context is core Anti-corruption layer
Same organisation, aligned priorities Customer-supplier with consumer-driven contract tests
Many consumers of one upstream Open host service + published language
Two teams constantly blocking each other on a shared model Split the kernel, move to customer-supplier

Production example

Mapping [nine] contexts for an [insurer] showed that [four] downstream teams were each translating the same legacy policy feed differently. We asked the policy team to publish a versioned PolicyChanged event schema (open host service and published language), and the four bespoke integrations collapsed into one, cutting integration defects from [about 10 a quarter to 2].

🔍 What the interviewer is checking

Checks that the candidate understands context mapping as a team and model relationship tool and can choose a pattern for a real integration.

Green flags

  • Explains upstream/downstream as influence, not call direction
  • Can describe every pattern and its cost
  • Ties the choice to power, model quality and how core the context is
  • Gives a concrete ACL or open host service example

Red flags

  • Only knows "anti-corruption layer"
  • Recommends a large shared kernel of entities
  • Ignores the organisational side entirely

📚 Learn in depth

1. Upstream and downstream

   [Upstream context]  ──── model / data flows ────►  [Downstream context]
          U                                                D
   changes here affect downstream; not the other way round

The direction is about influence, not about which way HTTP calls go. A downstream service can call an upstream API, or receive its events.

2. A context map

+-------------+  Partnership  +-------------+
|   Pricing   |◄─────────────►| Underwriting|
+------+------+               +------+------+
       | U                           | U  OHS/PL (PolicyChanged v2)
       | Customer-supplier           +-----------------+------------------+
       v D                           v D               v D                v D
+-------------+               +-------------+  +-------------+  +-------------+
|   Quoting   |               |   Claims    |  |   Billing   |  |  Reporting  |
+-------------+               +------+------+  +-------------+  +-------------+
                                     | D  ACL
                                     v
                              +-------------+  U (legacy, won't change)
                              | Legacy PAS  |
                              +-------------+

Writing U/D and the pattern on each line makes the politics explicit.

3. Shared kernel risks

A shared kernel is a shared NuGet package or project. It must be tiny and change rarely, with both teams approving every change and a shared test suite. If it grows, it becomes a distributed monolith: every change needs both teams.

4. Open host service and published language

  • Open host service: a protocol designed for many consumers (REST API with OpenAPI, gRPC, or events), not bespoke endpoints per consumer.
  • Published language: the documented, versioned schema (an OpenAPI document, JSON Schema, Protobuf, CloudEvents envelope, or an industry standard such as HL7 FHIR in health or ISO 20022 in payments).
  • Together they turn N bespoke integrations into one stable contract with versioning rules.

5. Anti-corruption layer anatomy

Downstream domain ◄── Translator ◄── Adapter ◄── Facade/Client ◄── Upstream API
  (own model)        (model map)   (protocol)   (HTTP, SOAP, files)

The ACL is the only code that knows the upstream's model.

6. Organisational patterns

Context maps reveal team topology issues: a downstream team that conforms to five upstreams has no autonomy; a shared kernel between teams in different reporting lines will stall. Use the map in planning conversations.

Try it yourself

  1. Draw a context map for your current system, marking U/D and a pattern on each relationship.
  2. Find one relationship where you are conformist by accident (vendor DTOs in your domain). Estimate the cost of an ACL.
  3. For an upstream you own, list its consumers. Would an open host service with a versioned schema simplify things?
  4. Add a consumer-driven contract test (Pact) for one customer-supplier relationship.

💻 Code

Three relationship styles in code: conformist, ACL and a published-language contract.

// Conformist: downstream uses the upstream's model directly. Cheap; fine for a supporting context.
namespace Reporting.Application;

public sealed record UpstreamPolicyDto(string PolicyNo, string Status, decimal Premium); // their shape

public sealed class PolicyReport(HttpClient http)
{
    public Task<UpstreamPolicyDto[]?> GetAsync(CancellationToken ct) =>
        http.GetFromJsonAsync<UpstreamPolicyDto[]>("/policies", ct);
}
// Anti-corruption layer: the core Claims context keeps its own model.
namespace Claims.Domain;

public enum CoverStatus { InForce, Lapsed, Cancelled }
public sealed record Cover(string PolicyNumber, CoverStatus Status, DateOnly From, DateOnly To);

public interface ICoverLookup // port defined by the downstream domain
{
    Task<Cover?> FindAsync(string policyNumber, DateOnly onDate, CancellationToken ct);
}
namespace Claims.Infrastructure.LegacyPas;

using Claims.Domain;

internal sealed record PasPolicy(string POL_NO, string POL_STAT_CD, string EFF_DT, string EXP_DT);

internal sealed class LegacyPasCoverLookup(HttpClient http) : ICoverLookup
{
    public async Task<Cover?> FindAsync(string policyNumber, DateOnly onDate, CancellationToken ct)
    {
        var p = await http.GetFromJsonAsync<PasPolicy>($"/pas/policy/{policyNumber}", ct);
        return p is null ? null : Translate(p);
    }

    // The only place that knows the legacy codes.
    private static Cover Translate(PasPolicy p) => new(
        p.POL_NO,
        p.POL_STAT_CD switch
        {
            "A" or "AR" or "AE" => CoverStatus.InForce,
            "L" or "LG" => CoverStatus.Lapsed,
            _ => CoverStatus.Cancelled
        },
        DateOnly.ParseExact(p.EFF_DT, "yyyyMMdd"),
        DateOnly.ParseExact(p.EXP_DT, "yyyyMMdd"));
}
// Open host service + published language: a versioned contract package for all consumers.
namespace Underwriting.Contracts.V2;

public sealed record PolicyChanged(
    string PolicyNumber,
    string CoverStatus,       // documented enum: InForce | Lapsed | Cancelled
    DateOnly EffectiveFrom,
    DateOnly EffectiveTo,
    int SchemaVersion = 2);

⚠ Common mistakes

  • Mistake: Conforming by accident (vendor DTOs used as domain objects). Why it is wrong: the upstream's model and naming spread through your core, and every upstream change ripples through. Instead: decide deliberately: conform only for supporting contexts with decent upstream models; otherwise add an ACL.
  • Mistake: Big shared kernels (a "Common" library of entities). Why it is wrong: every change needs every team; you get a distributed monolith. Instead: keep a shared kernel tiny (ids, Money) or replace it with published contracts.
  • Mistake: Choosing a shared kernel without checking how the teams actually work. Why it is wrong: it only works if both teams review every change, share tests and release in step; with different priorities or reporting lines it becomes a bottleneck and a source of breaking changes. Instead: assess the collaboration first, and prefer customer-supplier with versioned contracts when joint ownership is unrealistic.
  • Mistake: Bespoke endpoints for each consumer. Why it is wrong: the upstream's surface grows without limit and versioning becomes impossible. Instead: an open host service with a published, versioned language.
  • Mistake: Treating upstream/downstream as call direction. Why it is wrong: it misreads who has influence and who must adapt. Instead: mark U/D by whose model changes affect whom.
  • Mistake: Assuming customer-supplier when the upstream has other priorities. Why it is wrong: your needs never reach their backlog and you are actually conformist. Instead: name the real relationship and plan an ACL if needed.
  • Mistake: Integrating everything. Why it is wrong: some integrations cost more than manual processes. Instead: consider separate ways for low-value links.
  • Mistake: Drawing the map once for a slide deck. Why it is wrong: relationships change with reorganisations and vendor changes. Instead: keep it in the repo (C4 or Context Mapper DSL) and review it quarterly.

🏛 Senior insight: trade-offs

Context maps are a tool for honest conversations about power. Most integration pain comes from a mismatch between the assumed relationship ("they'll accommodate us") and the real one ("we're conformist"). Naming the pattern lets you plan: budget an ACL, negotiate a customer-supplier agreement with contract tests, or push for an open host service.

Relationships also change when the organisation does. A partnership becomes customer-supplier when one team moves to another division; a supplier that was accommodating becomes effectively conformist when its priorities shift; a vendor swap turns a conformist link into an ACL. I review the map at least quarterly and after every reorganisation or vendor decision, and treat a changed relationship as a trigger to revisit the integration design.

Pattern When it fits Cost When not to
Conformist Supporting context, good upstream model Your model mirrors theirs Core domain or poor upstream model
Anti-corruption layer Core context, legacy or vendor upstream Translator code and tests Upstream model is already a good fit
Open host service + published language Upstream with 3+ consumers Versioning discipline, docs One consumer that you also own
Shared kernel Two tightly aligned teams, tiny model Joint change process Teams in different lines of reporting

I measure a map's health by integration defect rates per relationship and how many cross-team changes each relationship forces per quarter.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate refers to the bounded contexts on the map. Why: Checks they can find and justify the contexts themselves.
    How to 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.

  2. When: Candidate mentions published language or event schemas. Why: Checks contract design and versioning for integration events.
    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 describes the anti-corruption layer as adapters. Why: Checks the Adapter pattern underneath an ACL.
    How to answer

    Adapter converts the interface of an existing class into the interface your code expects, without changing either side. It's a translator.

    • An object adapter wraps the adaptee by composition. This is the normal C# form.
    • A class adapter inherits the adaptee and implements the target. C# allows only one base class, so it's rare.

    For a payment SDK, I define IPaymentGateway in my domain's terms. A StripePaymentGateway adapter then turns it into SDK calls, translating types and units (decimal AUD to cents), statuses and vendor exceptions into domain results. That keeps vendor types out of the codebase, lets tests use a fake, and confines a provider change to one class.

    The trade-off is an extra layer. Keep it thin: an adapter translates, and business rules don't belong in it.

🛠 Real-world problems: how you handle them

Four teams translating the same legacy policy feed differently
Situation
An [insurer] had a legacy policy administration system feeding Claims, Billing, Reporting and a broker portal; each team had built its own integration over [several years].
Signals
Claims and Billing disagreed about whether a policy was in force on a date; [about 10] integration defects a quarter; reconciliation reports flagged [hundreds] of mismatched statuses monthly.
Investigation
Drew the context map with the four teams, marking U/D and the actual pattern; compared the four status translations line by line; traced mismatched records through Application Insights and the integration logs.
Resolution
Short term, aligned the four translations on one agreed table. Long term, the policy team published a versioned `PolicyChanged` event (open host service and published language); Claims kept a thin ACL over it because it is core, the others conformed to the new contract.
Prevention
Schema registry and contract tests for the published event, a versioning policy in an ADR, and the context map kept in the repo and reviewed quarterly.

How to tell it (STAR)

**S:** At [company], four teams each translated the same legacy policy feed, and Claims and Billing disagreed on cover status [hundreds] of times a month. **T:** I was asked to [reduce the integration defects]. **A:** I facilitated a context-mapping session, which showed everyone was conformist to a poor model in their own way. I proposed that the policy team publish a versioned event as an open host service, wrote the ADR with them, and kept an ACL only for our core Claims context. **R:** Integration defects fell from [about 10 a quarter to 2], and the next legacy change touched one adapter instead of four integrations.

↩ Usually asked after

More in Domain-Driven Design

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me