Stable Dependencies Principle

No Change
adopt
First Added:June 25, 2026 Updated: July 2, 2026

Stable Dependencies Principle is a technique we adopt in the garden.

Summary

When to use: Evaluate on a project when the capability clearly fits the requirement.

When to skip: When a simpler alternative already covers the need.

Details

Stability Metrics

Martin uses fan-in and fan-out at the package level. High fan-in (many importers) increases stability because many teams feel each change. High fan-out (many imports) increases instability.

Instability (I) for a package:

I = Ce / (Ca + Ce)

Where Ce is efferent coupling (outgoing dependencies) and Ca is afferent coupling (incoming dependents). I ranges from 0 (maximally stable) to 1 (maximally unstable). SDP means edges should point from higher I toward lower I.

Package profileTypical role
High fan-in, low fan-outStable foundation (types, ports, policy)
Low fan-in, high fan-outVolatile leaf (features, adapters, experiments)
Stable depending on unstableSDP violation; invert or relocate code

Component Coupling Context

SDP is one of three classic component coupling principles (Robert C. Martin). Siblings are Acyclic Dependencies Principle (ADP) and Stable Abstractions Principle (SAP).

PrincipleGist
ADPNo cycles (Acyclic Dependencies Principle)
SDPDepend toward stability
SAPStable means abstract (Stable Abstractions Principle)

Practical Signs

SignalLikely fix
Shared kernel imports feature flags from webappMove flags behind a port; invert dependency
Platform library release blocked by one product teamPeel product-specific code out of the library
“Utils” package grows because everything imports itCheck whether utils became an unstable dumping ground
Frequent breaks in widely used internal SDKSDP review plus Common Closure Principle split

Common Failure Modes

  • Treating “stable” as “old” instead of measuring fan-in and fan-out
  • Inverting dependencies with empty interfaces (fake stability)
  • Freezing the wrong layer because it has a good name (core, common)
  • Ignoring SDP while enforcing folder-based layer rules that code bypasses

Related Garden Items