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

Shared Kernel

architecture Advanced

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 22
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 3 pings S 0 pings S 0 pings M 0 pings T 1 ping W 1 ping T 2 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
No pings yesterday
Amazonbot 9 Google 5 Perplexity 5 ChatGPT 1 Ahrefs 1
crawler 18 crawler_json 3
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