← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Shared Kernel

Architecture Advanced
debt(d7/e7/b7/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints list deptrac and phpstan as tools, which can detect dependency violations and large shared libraries, but detecting whether the Shared Kernel is growing inappropriately, lacks team governance, or is being misused as a general utility library requires careful code review and architectural awareness. Automated tools can flag structural issues but not the conceptual misuse.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix says to keep the kernel small, but when misuse has already occurred — a Shared Kernel that has grown into a monolithic shared library — remediation requires decomposing the shared model, redistributing concepts to their owning contexts, and coordinating changes across multiple teams and bounded contexts. This is a cross-cutting concern that touches multiple components and teams.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). The applies_to covers web and cli contexts broadly. A Shared Kernel that grows or lacks governance shapes every change made in both bounded contexts — teams must coordinate for every modification, and the kernel exerts gravitational pull on design decisions. Common mistakes confirm the decay pattern: it 'becomes a monolithic shared library' over time, progressively increasing coupling.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field directly states that developers confuse Shared Kernel with a general shared database or common utility library, which is the opposite of its DDD meaning — a formally governed, minimal, intentionally bounded subset of the domain model. This contradicts how 'shared libraries' work in most other architectural contexts, making it a serious conceptual trap for developers familiar with standard shared library patterns.

About DEBT scoring →

Also Known As

shared kernel DDD shared domain model

TL;DR

A DDD strategic pattern where two bounded contexts intentionally share a small subset of the domain model — requiring tight coordination between teams but reducing duplication.

Explanation

A Shared Kernel is a deliberate coupling point: two contexts agree to share specific classes (value objects, domain events, DTOs) and coordinate on any changes. It is NOT accidentally shared code — it is a formal agreement. Best for: tightly related contexts owned by the same team, where the coordination cost is lower than maintaining two separate but nearly identical models. Anti-pattern when: teams are independent, the shared portion grows unchecked, or the shared code becomes a dumping ground for anything two contexts need.

Common Misconception

Shared Kernel means sharing a database or common library — a Shared Kernel is a specific, bounded, intentionally chosen subset of the domain model with formal team agreement, not a general utility library.

Why It Matters

Without a Shared Kernel, two contexts independently model the same Money value object — a Shared Kernel eliminates this duplication for concepts that genuinely belong to both contexts.

Common Mistakes

  • Shared Kernel that grows over time without governance — becomes a monolithic shared library.
  • No team agreement on change process — one team changes the kernel, breaks the other.
  • Sharing infrastructure code as a Shared Kernel — infrastructure utilities are not domain concepts.
  • Using Shared Kernel to avoid duplicating convenience code — duplication is often better than coupling.

Code Examples

✗ Vulnerable
// Shared kernel used as a dumping ground:
namespace SharedKernel;
// Originally: just Money and CustomerId
// 2 years later: 200 classes, utilities, helpers, configs
// Every team change breaks others
// No clear ownership — everyone and nobody owns it
✓ Fixed
// Disciplined shared kernel — minimal, governed:
namespace SharedKernel;

// Only truly shared domain concepts:
final class Money { /* amount + currency */ }
final class CustomerId { /* UUID value object */ }
final class OrderId { /* UUID value object */ }

// Change process: both teams must review and approve
// Version controlled independently — SharedKernel v2.1
// Both contexts pin to the same version
// Size limit: if > 20 classes, something is wrong

Added 16 Mar 2026
Edited 22 Mar 2026
Views 48
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 2 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 2 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 Google 6 Perplexity 5 Scrapy 5 Ahrefs 3 SEMrush 3 Claude 2 Bing 2 ChatGPT 1 Meta AI 1 Sogou 1 PetalBot 1
crawler 35 crawler_json 5
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Keep the Shared Kernel as small as possible — only put in it what both contexts genuinely share and can agree to maintain together; a growing shared kernel becomes a source of coupling
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
Large shared library between contexts with frequent changes; two teams coordinating for every change to shared code; shared kernel growing beyond minimal domain concepts
Auto-detectable: ✓ Yes deptrac phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant