Course contentsShow
← Software Engineering
Lesson 1107 of 1,93333. Error Handling and ResilienceFree lesson

Fail-Safe and Fail-Secure Defaults

Designing systems to fall back to safe states that protect data and users when failures occur.

Fail-Safe and Fail-Secure Defaults

You'll learn how to design systems that automatically choose protective default behaviors when things go wrong.

The Core Idea

When a system encounters an unexpected failure or uncertainty, it faces a choice: what should the default behavior be? Fail-safe and fail-secure are two philosophies for making that choice, and picking the right one depends on what you're protecting.

Fail-safe defaults prioritize safety and availability. When in doubt, the system allows access or continues operation to prevent harm from denial of service. Think of a fire door that unlocks automatically during a power outage—it fails in a way that keeps people safe, even if security is temporarily reduced.

Fail-secure defaults prioritize security and data protection. When in doubt, the system denies access or shuts down to prevent unauthorized actions. A bank vault that locks tight during a power failure is fail-secure—it fails in a way that protects assets, even if access is temporarily blocked.

Choosing Your Default

The decision hinges on your system's primary risk:

  • Fail-safe: Use when false negatives (denying legitimate access) cause more harm than false positives. Emergency systems, physical safety controls, and availability-critical services often choose this path.

  • Fail-secure: Use when false positives (allowing unauthorized access) cause more harm than false negatives. Authentication systems, financial transactions, and data access controls typically choose this approach.

Many systems use both in different subsystems. An e-commerce site might fail-secure on payment authorization (deny uncertain transactions) but fail-safe on product browsing (show generic content if personalization fails).

Key Takeaway: Design every uncertain state with an explicit default: fail-safe when availability protects users, fail-secure when restriction protects them. Never leave failure modes undefined.