Skip to content

Fail-Fast Principle

Systems should detect and report errors at the earliest possible moment, because errors propagating through code layers become harder to diagnose and may corrupt state irreversibly.

Tension Addressed

Fail-Fast vs. Fault Tolerance

Recognizable As

Precondition checks, constructor validation, assertions, null checks at boundaries, input validation at entry points, type systems as compile-time fail-fast

Canonical Sources

Shore, "Fail Fast" (2004); Hunt & Thomas, "The Pragmatic Programmer" (1999)

Transfers To

Distributed Systems (circuit breakers), API Design (input validation), Testing (assertion design), Database Design (constraints)

Fail-fast code produces errors close to their cause. Without it, errors surface far from their origin (null pointer exceptions deep in code from null assigned much earlier), requiring expensive debugging to trace causation.

Sub-concepts: - Defensive programming: Systematic precondition checking - Design by contract: Preconditions, postconditions, invariants