Shared Kernel

A shared kernel in Domain-Driven Design is a small part of a domain model and its code that two teams own jointly, such as health states two models share.

Status
Published, version 1.0.1
Last reviewed
17 Nov 2026, by Dr Darrin Baines
Report a problem
Tell us if something is wrong or out of date

Concept Architecture

Shared Kernel in Health Economic Modelling

In Domain-Driven Design (DDD), a shared kernel is a small, explicitly bounded part of a domain model that the teams of two bounded contexts own jointly instead of translating between two separate models, and the name also marks that relationship between the two contexts. The shared part carries its code with it, and it should not be changed without consultation with the other team. In health economic work the nearest case is two models of one disease built side by side, such as a cost-effectiveness model and a budget impact model that ought to use identical health states and identical rules for moving a cohort between them. The wiki's Domain Layer would record the pattern on its context maps as a dependency that is close by design and costly to maintain.

Origin of the term and who uses it

Shared Kernel is a software design term and is new to health economics. Eric Evans named it in his 2003 book on Domain-Driven Design, whose contents list places it in chapter 14 on maintaining model integrity, after bounded context, continuous integration and context map. His free reference booklet of 2015 states the pattern on a page of its own under context mapping for strategic design.

Vaughn Vernon's two books keep the term. Implementing Domain-Driven Design (2013) indexes it under bounded context relationships, and Domain-Driven Design Distilled (2016) lists it among the kinds of mappings in its chapter on context mapping. Context Mapper, a modelling framework with its own language for drawing DDD context maps, treats a shared kernel as a symmetric relationship between two bounded contexts, so it does not matter which context is written on which side. The wiki label matches the term these sources use. None of the health economics sources read for this page, including the DARTH coding framework and the TECH-VER checklist, uses the expression.

What Evans asks the two teams to share

Evans starts from the cost of splitting work. When keeping one large context continuously integrated costs too much, perhaps because a single team has become too big and unwieldy, separate bounded contexts and teams are formed. Uncoordinated teams on closely related applications can then race ahead for a while and produce work that does not fit together. Even partner teams can end up spending a great deal on translation layers and retrofitting, duplicating effort and losing the benefits of a common ubiquitous language.

His remedy sets four conditions.

  1. The teams designate, with an explicit boundary, a subset of the domain model that they agree to share, and keep that kernel small.
  2. The boundary takes in the subset of code or of database design that goes with that part of the model.
  3. The shared part has special status and should not be changed without consultation with the other team.
  4. A continuous integration process keeps the kernel model tight and aligns the ubiquitous language of the teams, and a functional system is integrated frequently, though somewhat less often than each team integrates its own work.

Continuous integration is Evans's pattern for keeping one context sound by merging code frequently with automated tests that flag fragmentation quickly, so a shared kernel applies it to the shared part across two contexts.

A symmetric relationship on the context map

Many relationships on a context map have a direction, with an upstream team whose actions affect a downstream team more than the reverse. A shared kernel has no such direction, which is why Context Mapper writes it with arrows at both ends. Both teams are exposed to changes in the shared part, and each depends on the other's willingness to consult.

Evans also marks where the pattern stops being available. He presents the anticorruption layer as the defensive choice when control or communication is not adequate to pull off a shared kernel, partner or customer and supplier relationship. In another pattern he notes that a shared kernel is not feasible for teams that do not work closely together. The 2003 book's contents also have sections on merging contexts that had gone separate ways into a shared kernel, and on merging a shared kernel into continuous integration. On the wiki's maps the pattern would be recorded only where joint ownership and the consultation rule can be seen in practice.

A kernel for two models of one disease

The design below is the wiki's illustration and has not been tested in practice. A health economics group builds a cost-effectiveness model and a budget impact analysis for the same treatment, with one team on each. Both are three-state Markov models with the states Well, Sick and Dead, and both need the cohort to move through those states in the same way. In this illustration the budget impact team adds each year's newly eligible patients in its own context before calling the shared function. The kernel would hold the agreed list and order of health states and the layout of the transition matrix with its validity rules, while each team supplies the probabilities from its own parameter set, since the cost-effectiveness team redraws them in probabilistic analysis. It would also hold the function that moves the cohort forward one cycle.

The cohort tutorial by Alarid-Escudero and colleagues states the rules such a matrix must meet. Every entry should lie between 0 and 1, each row must sum to one, and each cycle is computed as the product of the state vector and the matrix.

mt+1=mtPm_{t+1} = m_t P

where mtm_t is the row vector of the number of people in each state at the start of cycle tt, mt+1m_{t+1} is the same vector one cycle later and PP is the transition matrix, whose entry pijp_{ij} is the probability of moving out of state ii into state jj in one cycle. The wiki's planned Rules and Invariants records express the row rule with a tolerance of 0.000001, and planned component pages on transition-matrix validation and cohort propagation are meant to define the two operations. Neither set of pages is published yet.

Costs, utilities, discounting and corrections for the timing of transitions within a cycle stay outside, in each team's own context, because the two models use the cohort for different purposes. The tutorial keeps this separation in its code, applying its within-cycle correction to costs and QALYs through Simpson's 1/3 rule after the cohort trace has been computed.

The DARTH coding framework of Alarid-Escudero and colleagues notes that when a repeated operation is written as a function, any update to it is propagated across all function calls, and it recommends writing tests alongside each new function. In a shared kernel that propagation reaches the other team's model, so the kernel's unit tests belong in both teams' builds.

Worked example with a proposed change to the shared function

The numbers in this example are illustrative. A cohort of 1,000 people starts in Well. The Well row of the matrix used in the joint tests gives 0.85 for staying Well, 0.10 for falling Sick and 0.05 for dying. After one cycle the shared function returns 1000 × 0.85 = 850 people in Well, 1000 × 0.10 = 100 in Sick and 1000 × 0.05 = 50 in Dead, a total of 850 + 100 + 50 = 1000. The kernel's joint test suite holds these counts as expected values.

The cost-effectiveness team then proposes to build a timing correction into the shared function, so that it returns the average of each state's count at the start and end of the cycle.

mˉt=mt+mt+12\bar{m}_t = \frac{m_t + m_{t+1}}{2}

where mˉt\bar{m}_t is the averaged state vector for cycle tt, and mtm_t and mt+1m_{t+1} are the state vectors at the start and end of that cycle, as defined above.

For the first cycle the averaged counts are (1000 + 850) / 2 = 925 in Well, (0 + 100) / 2 = 50 in Sick and (0 + 50) / 2 = 25 in Dead, still a total of 925 + 50 + 25 = 1000. The averages may suit the cost-effectiveness team's accounting of QALYs. The budget impact team, in this illustration, costs everyone recorded in Sick at the end of each annual cycle at GBP 4,000 a year. Its first-year cost would fall from 100 × 4,000 = GBP 400,000 to 50 × 4,000 = GBP 200,000 with no change to its own code. If people fall ill evenly through the year, the averaged count approximates the time the cohort spends in Sick, so the smaller figure may even be the better estimate, but the shared function would no longer return the number of people in each state at the end of the cycle, which is the quantity the budget impact team's rule was written to cost.

Because the function sits in the kernel, the change needs consultation with the budget impact team, and the joint test that expects 100 people in Sick fails at once. The likely settlement follows the tutorial's design, with the shared function still returning counts at the cycle boundaries and the cost-effectiveness context applying its correction in its own calculation of costs and QALYs.

How a shared kernel differs from nearby relationships

Several relationships on a context map look alike at first sight. In a partnership the two teams plan together and coordinate their interfaces, yet Evans writes that most of the time developers need not understand the model of the other subsystem in detail, whereas a shared kernel makes part of that model common property. A published language is a documented medium of translation between models that stay separate, and Evans gives industry data interchange standards as an example.

A widely used package is a different arrangement. The DARTH framework relies on dampack, an R package published in the DARTH group's repository, for common procedures such as cost-effectiveness acceptability curves. On the wiki's reading, teams that install such a package use it as published, which places its maintainers upstream of them, as in Evans's conformist or customer and supplier patterns, rather than in joint ownership.

Using the same word is not a shared kernel either. The wiki's Model Execution working-language list marks time horizon as shared with the HTA Appraisal context, yet no jointly owned subset of model or code links the two contexts, and the list's own note records that its two sources define the term differently. Martin Fowler notes that different contexts may hold completely different models of common concepts, with mechanisms to map between them.

Where shared kernels go wrong in health economic work

DDD is software design practice, and no source read for this page evaluates shared kernels in health economic modelling. Four misreadings are likely when the idea is carried across.

  1. Letting the kernel grow. Evans asks for the kernel to be kept small. A kernel that gathers costs, utilities, discount rates and report templates for convenience turns every routine change into a joint decision and slows both teams.
  2. Sharing code with the checker. TECH-VER describes replication-based tests in which the reviewer tries to re-perform the calculations in the same or different software, or by pen and paper. A validation team that checks results by running the modellers' kernel code repeats any error in it, so on the wiki's reading technical verification keeps its own route to the numbers.
  3. Calling copied files a kernel. A script copied between two models without a consultation rule or joint tests is duplication, and the copies can drift apart.
  4. Proposing a kernel between a company and an HTA agency. Evans's remark that a shared kernel is not feasible for teams that do not work closely together fits the link between a submitting company and an appraising agency, whose independence matters. That link is better recorded as translation or as an exchange through a published format.

Sources

Library

Publications

5
  • Book

    Implementing Domain-Driven Design — Vernon V, 2013 (Addison-Wesley)

    Book or book chapter listed in the Sources of the HealthEconomics.wiki Concept Architecture articles on Core Domain, Context Map, Shared Kernel, Entity (Domain-Driven Design), Invariant (Domain-Driven Design), Published Language, Domain Event and Open Host Service, where it is cited as a reference for these concepts.

  • Other

    Domain-Driven Design Reference: Definitions and Pattern Summaries — Evans E, 2015 (Domain Language)

    Source listed in the Sources of the HealthEconomics.wiki Concept Architecture articles on Domain-Driven Design, Domain (Domain-Driven Design), Subdomain (Domain-Driven Design), Core Domain, Bounded Context, Ubiquitous Language, Domain Model, Context Map, Strategic Design, Domain Expert, Entity (Domain-Driven Design), Value Object, Aggregate (Domain-Driven Design), Invariant (Domain-Driven Design), Anticorruption Layer, Published Language, Domain Event, Domain Service, Shared Kernel and Open Host Service, where it is cited as a reference for these concepts.

  • Book

    Domain-Driven Design Distilled — Vernon V, 2016 (Addison-Wesley)

    Book or book chapter listed in the Sources of the HealthEconomics.wiki Concept Architecture articles on Subdomain (Domain-Driven Design), Core Domain, Bounded Context, Context Map, Strategic Design, Domain Expert, Shared Kernel, Open Host Service, Ubiquitous Language and Anticorruption Layer, where it is cited as a reference for these concepts.

  • Other

    Bounded Context — Fowler M, 2014 (martinfowler.com)

    Source listed in the Sources of the HealthEconomics.wiki Concept Architecture articles on Domain-Driven Design, Domain (Domain-Driven Design), Bounded Context, Ubiquitous Language, Context Map and Shared Kernel, where it is cited as a reference for these concepts.

  • Book

    Domain-Driven Design: Tackling Complexity in the Heart of Software — Evans E, 2003 (Addison-Wesley)

    Book or book chapter listed in the Sources of the HealthEconomics.wiki Concept Architecture articles on Domain-Driven Design, Domain (Domain-Driven Design), Core Domain, Bounded Context, Context Map, Published Language, Open Host Service, Ubiquitous Language, Domain Model, Strategic Design, Domain Expert, Entity (Domain-Driven Design), Invariant (Domain-Driven Design), Anticorruption Layer, Shared Kernel, Value Object and Domain Service, where it is cited as a reference for these concepts.

Tools & Resources

1
  • Other

    Shared Kernel (CML language reference) and Welcome page — Context Mapper, Web page, accessed 17 November 2026 ed. (contextmapper.org)

    Source listed in the Sources of the HealthEconomics.wiki Concept Architecture article on Shared Kernel, where it is cited as a reference for that concept.

Frequently Asked Questions (6)

  • What is Shared Kernel?

    A shared kernel in Domain-Driven Design is a small part of a domain model and its code that two teams own jointly, such as health states two models share.

    Source: Evans 2015

  • Where does the term Shared Kernel come from?

    Shared Kernel is a term from software design and is new to health economics. Eric Evans named it in his book on Domain-Driven Design and restated it in his free reference booklet of 2015, where it sits among the patterns of context mapping for strategic design. Evans describes sharing part of a model and its associated code as a very intimate interdependency between two teams. The wiki's Domain Layer would use the pattern to describe a close dependency between two contexts, such as two models of one disease.

    Source: Evans 2015

  • What do two teams agree to when they set up a Shared Kernel?

    A Shared Kernel requires the teams to mark with an explicit boundary the subset of the domain model they agree to share, and to keep that kernel small. The boundary also takes in the code or database design that goes with that part of the model. The shared part has special status and should not be changed without consulting the other team. A continuous integration process keeps the kernel tight and aligns the language of both teams, with the joint system integrated somewhat less often than each team integrates its own work.

    Source: Evans 2015

  • How could a Shared Kernel be used between two health economic models?

    In the wiki's illustration, a Shared Kernel links the teams building a cost-effectiveness model and a budget impact model of the same disease. The kernel holds the agreed list and order of health states, the layout of the transition matrix with its validity rules and the function that moves the cohort forward one cycle, while each team supplies the probabilities from its own parameter set. The cohort tutorial by Alarid-Escudero and colleagues requires each matrix entry to lie between 0 and 1 and each row to sum to one. Costs, utilities, discounting and within-cycle corrections stay in each team's own model, because the two models use the cohort for different purposes.

    Source: Alarid-Escudero et al. 2023

  • How does a Shared Kernel differ from a partnership or a published language?

    A Shared Kernel makes a small part of the model and its code the common property of two teams. In a partnership the teams coordinate their planning and interfaces, and Evans writes that most of the time developers need not understand the model of the other subsystem in detail. A published language is a well-documented shared language used to translate between models that stay separate, and many industries establish one as a data interchange standard. Two health economic models could therefore exchange results through a published format without sharing any model code.

    Source: Evans 2015

  • What are common mistakes when using a Shared Kernel in health economic modelling?

    One mistake is to let a Shared Kernel grow until costs, utilities and report templates sit inside it, so that every routine change needs consultation between the two teams. Another is to share the kernel with the people who check the model. The TECH-VER checklist describes replication-based tests in which a reviewer re-performs the calculations in the same or different software, or by pen and paper, and a reviewer who reuses the modellers' kernel code would repeat any error in it. A kernel between a submitting company and an HTA agency is also a poor fit, because the agency's independence matters.

    Source: Büyükkaramikli et al. 2019

Trust Record

Verified by Dr Darrin Baines

British health economist

Professional identity: darrinbaines.org

Verification date: 17 Nov 2026

Content version: 1.0.1

Canonical Identity

Term code
HS-HP-DH-128

Stable URI · Machine-readable · Resolvable · CC BY 4.0

This article is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).

Author: Dr Darrin Baines · Publisher: Intelligent Parameters Ltd · Identifier: https://healtheconomics.wiki/concept/shared-kernel