Residuality Theory: Stressors, Attractors, and Contagion
Why Domain-Driven Design boundaries drawn around business nouns still fracture under shock — and how Barry O'Reilly's Incidence Matrix tells you where to put the walls.
Traditional software architecture asks: What are the entities in this business today, and what features do users want next?
Barry O’Reilly’s Residuality Theory starts from the opposite premise. Real software operates inside hyperliminal systems: strictly logical, complicated deterministic modules embedded inside an unpredictable, complex environment of shifting vendor PDFs, flaky remote APIs, regional tax updates, and hurried human operators.
Drawing on theoretical biologist Stuart Kauffman’s work on Random Boolean Networks, O’Reilly notes that although a complex business environment has an astronomical number of possible configurations, stressed systems settle into a much smaller family of stable operating regimes called attractors.
From Hand-Waving to the Incidence Matrix
When Domain-Driven Design teams draw Bounded Contexts purely from nouns on a whiteboard, hidden couplings lurk beneath the surface. Everything looks modular until a single supplier changes an invoice header and suddenly breaks line arithmetic, catalog matching, ledger deduplication, and audit logging all at once.
Residuality Theory replaces architectural intuition with an Incidence Matrix: rows represent random and adversarial stressors, columns represent system modules, and each cell records whether that module breaks, forces a recompile, stays cached untouched, or holds an invariant firm.
Explore the interactive workbench below. Switch between a Naive Coupled System and Residual Bounded Contexts, or fire stressors at random to measure the exact Contagion Score and Blast Radius.
Does Your Boundary Actually Stop Contagion Under Stress?
A major distributor shifts barcode positions and moves bottle-deposit fees into a nested summary box.
| Stressor Scenario | Document Intake tier2 | Extraction Adapter tier2 | Line Math & Totals tier0 | Catalog & Account Match tier1 | Ledger Write & Dedupe tier2 | Immutable Audit Trail tier0 | Blast |
|---|---|---|---|---|---|---|---|
| Beverage supplier redesigns invoice layout | sha256-cached Ingestion queue isolated by content hash | recompiled Only Tier 2 extraction adapter recompiled + gate-checked | invariant-held Tier 0 penny-sum invariant rejects bad parses | sha256-cached Catalog lookup untouched (zero tokens) | invariant-held Idempotent ledger boundary never sees bad input | invariant-held Immutable run verdict recorded | 1/6 |
| Accounting ledger API renames tax-code field (422) | sha256-cached Ingestion unaffected | sha256-cached Extraction untouched; canonical bill unchanged | invariant-held Tier 0 math core isolated from wire format | sha256-cached Policy rules untouched | recompiled Tier 2 anti-corruption adapter recompiled + verified | invariant-held Provenance bundle updated atomically | 1/6 |
| Accounting ledger API suffers 15-minute 503 outage | sha256-cached Items stay queued safely | sha256-cached Zero re-extraction needed | invariant-held Math core untouched | sha256-cached Policy bundle unchanged | invariant-held Stressor classifier detects outage -> pauses with 0 thrash | invariant-held Circuit-breaker pause logged cleanly | 0/6 |
| Operator adds bottle-deposit rule in shared playbook | sha256-cached Ingestion unchanged | sha256-cached OCR layout unaffected | invariant-held Tier 0 accounting math bounds candidate rulebook | recompiled Tier 1 rulebook compiled & verified against Golden Pins | invariant-held Dedupe & balance gates enforced before promote | invariant-held Version bundle promoted atomically with rollback link | 1/6 |
| New hospitality venue onboarded with local codes | sha256-cached Shared runtime unchanged | sha256-cached Vendor parser reused via hash | invariant-held Same core invariants apply | recompiled Per-location Tier 1 rulebook compiled in isolation | invariant-held Site-scoped tenant key verified statically | invariant-held Separate durable conversation & spec pack initialized | 1/6 |
| Regional tax regime alters credit-note rounding | sha256-cached Ingestion untouched | sha256-cached Extraction untouched | recompiled Conflict halted; requires person-ratified Tier 0 update | recompiled Tier 1 tax mapping compiled after Tier 0 decision | invariant-held Signed credit-note guard waits for Gate 1 + Gate 2 pass | invariant-held Decision record appended with human ratification | 2/6 |
Contagion Analysis Unifies DDD and Freshware
Watch what happens inside the matrix when you compare the two modes:
- In Naive Mode (
28 / 36cells affected): Because prompts, parsing logic, math rules, and external API DTOs share unseparated state, almost every shock propagates across 4 to 6 modules. Worse, Tier 0 accounting invariants break under stress — penny equality slips during layout shifts and transient503outages provoke frantic prompt rewrites. - In Residual Mode (
6 / 36cells affected): Placing Tier 2 Anti-Corruption Adapters at the perception edge (Extraction Adapter) and ledger edge (Ledger Write & Dedupe), insulating Tier 1Policy Rules, and hardening Tier 0Accounting Corecuts mean blast radius to 17%, keeps untouched modules skipped at zero token cost (sha256cache hits), and ensures 6 / 6 shocks leave Tier 0 invariants unbroken.
Inspect Incidence Matrix & Contagion Equations
Let S be the set of simulated stressors (|S| = 6) and M be the set of system modules (|M| = 6). Each matrix cell c(s, m) belongs to {broken, recompiled, sha256-cached, invariant-held}.
- Row Contagion:
Contagion(s) = count(m in M where c(s, m) in {broken, recompiled}). - Blast Radius Ratio:
Blast(s) = Contagion(s) / |M|. - Zero-Token Cache Savings: Modules marked
sha256-cachedprove identical build inputs and skip LLM recompilation completely. - Tier 0 Survival Predicate: A shock
spreserves core safety iff no Tier 0 module (Line Math,Audit Trail) enters statebroken.
Notice a subtle bonus of viewing software through O’Reilly’s Incidence Matrix: you never have to predict the exact future. Simulating enough diverse stressors exposes structural couplings before production traffic discovers them. Once the walls sit in the right places, we need a mechanical runtime harness that actually extracts, stores, protects, and forks those constraints as sessions unfold.
Go Deeper: Residuality Talks & Primary Readings
Barry O'Reilly's architectural theory of hyperliminal systems, random stressor simulation, contagion analysis, and Kauffman attractors — defining what must survive external shocks.
Keynote: Residuality Theory in Software Architecture
An Introduction to Residuality Theory
Residues: Time, Change, and Uncertainty in Software Architecture ↗
Primary theoretical source for Part II and for separating surviving Tier 0 cores from mutable operational policies.
An Introduction to Residuality Theory: Software Design Heuristics for Complex Systems ↗
Establishes the formal vocabulary connecting naive architecture baselines to verified invariant survival.
Residuality Theory Explained for Functional Architects ↗
Pairs directly with Dexter Horthy's expected-pain heuristic in Chapter 01 to avoid over-specifying volatile UI glue while locking core edges.
Designing Resilient Architectures with Residuality Theory ↗
Illustrates practical incidence scoring in production teams and motivates automating matrix checks against extracted specs.