Fail-Fast Systems in Engineering, Programming and Business with Examples

Lecture 12 min.



A fail-fast system (fail-fast) is an approach in which a program stops immediately and raises an error as soon as it detects unexpected or incorrect behavior. This is done to prevent the program from continuing to run under conditions that could lead to more complex and harder-to-detect errors.

In systems design, a fail-fast system is one that immediately reports at its interface any condition that may indicate a failure. Fail-fast systems are usually designed to stop normal operation rather than continue a possibly faulty process. Such designs often check the state of the system at several points in operation so that any failures can be detected at an early stage. The responsibility of a fail-fast module is to detect errors and then give the next level of the system up the opportunity to handle them.

Hardware and software

Fail-fast systems or modules are desirable in a number of cases:

  • Fail-fast architectures are based on an error-handling policy in which any detected error or unexpected condition causes the system to fail (quickly). In a sense, this error-handling policy is the opposite of the one used in a fault-tolerant system. In a fault-tolerant system, the error-handling policy is set up to have redundant components and to move computation requests to active components when some component fails. Paradoxically, fail-fast systems make fault-tolerant systems more robust. We may have 10 redundant servers for a given database, but if the common configuration for all 10 servers is updated with incorrect authentication data for clients, they will all "redundantly fail". In this sense, a fail-fast system will make sure that all 10 redundant servers fail as soon as possible, so that DevOps can react quickly.
  • Fail-fast components are often used in situations where a failure in one component may go unnoticed until it causes a failure in another component as a result of lazy initialization. For example, "A system that is 'doomed' to fail because of an incorrectly configured file system path does not fail at startup, because the file system path is not checked at startup. Only when a client request arrives does the system fail, at random, later."
  • It is easier to find the cause of a failure in a fail-fast system, because the system reports the failure with as much information as possible as close as possible to the moment of failure. In a fault-tolerant system a failure may go unnoticed, whereas in a system that is neither fault-tolerant nor fail-fast, the failure may be temporarily hidden until it causes some seemingly unrelated problem later.
  • A fail-fast system, which is designed to stop and report an error in the event of a failure, is less likely to mistakenly perform an irreversible or costly operation.

Developers also call code fail-fast if it tries to fail as early as possible when initializing a variable or an object. In object-oriented programming, an object designed to be fail-fast initializes the object's internal state in the constructor, throwing an exception if something is wrong (instead of allowing uninitialized or partially initialized objects that will later fail because of an incorrect "setter"). The object can then be made immutable if no further changes to the internal state are expected. In functions, fail-fast code will check the input parameters in a precondition. In client-server architectures, fail-fast will validate the client request immediately on arrival, before processing it or forwarding it to other internal components, returning an error if the request fails validation (incorrect parameters, ...). Code designed to be fail-fast reduces the internal entropy of the software and reduces debugging effort.

Advantages of a fail-fast system:

  • Early error detection: errors are identified at the earliest stages, simplifying diagnosis and correction.
  • Simpler debugging: because the system stops right after an error is detected, it is easier to understand exactly where the problem occurred.
  • Increased reliability: reduces the risk of errors accumulating and cascading into other parts of the system.

Examples

  • A fail-fast application/system checks the readiness of all input/output resources required for future computations before any computation request arrives.
  • A fail-fast application/system checks the correctness of all immutable initial configurations at startup.
  • A fail-fast function is a function that checks all of the function's inputs in a precondition before proceeding to any computation or business logic in that function.
  • A fail-fast function usually throws a runtime exception when it detects some abnormal computation, which causes the system to crash if no other function has provided a "catch", instead of returning some error value without any (optimistic) assumptions about the proper handling of the error that has occurred.
  • In software engineering, a fail-fast iterator is an iterator that tries to raise an error if the sequence of elements being processed by the iterator is modified during iteration.
  • Given an initial state in a finite state machine, a fail-fast system will check that state and fail quickly.
  • Given a state change in a state machine, a fail-fast system will stop the machine if the state change is prohibited. It may happen that the prohibited state change is caused by incorrect external input. In this case, the fail-fast system will stop processing the request as soon as the incorrect input is detected (instead of delegating to the state machine implementation).

Examples of using fail-fast in programming


Argument validation in methods: If a method expects certain values or data types, it can immediately throw an exception if these conditions are not met.

function processData(array $data): void {
    if (empty($data)) {
        throw new InvalidArgumentException("The data must not be empty.");
    }
    // Main logic
}
processData([]); // Immediate error because of an empty array


Fail-fast collections: In some programming languages (for example, Java) collections are implemented as fail-fast: if a collection is modified during iteration, an exception is thrown. In PHP this can be implemented through version control.

class FailFastCollection implements IteratorAggregate {
    private array $items = [];
    private int $version = 0;
    public function add($item): void {
        $this->items[] = $item;
        $this->version++;
    }
    public function getIterator(): Iterator {
        $currentVersion = $this->version;
        foreach ($this->items as $item) {
            if ($currentVersion !== $this->version) {
                throw new RuntimeException("The collection was modified during iteration.");
            }
            yield $item;
        }
    }
}
$collection = new FailFastCollection();
$collection->add(1);
$collection->add(2);
foreach ($collection as $item) {
    echo $item;
    $collection->add(3); // Error because the collection is modified
}


Fail-fast API: If a system interacts with an external API and receives a response that does not match expectations, it can immediately terminate and throw an error to avoid cascading errors.

function fetchData(string $url): array {
    $response = file_get_contents($url);
    $data = json_decode($response, true);
    
    if (json_last_error() !== JSON_ERROR_NONE) {
        throw new RuntimeException("JSON decoding error.");
    }
    if (!isset($data['expectedField'])) {
        throw new RuntimeException("The expected field is missing from the response.");
    }
    return $data;
}


In these examples, fail-fast protects the code from incorrect data, contract violations and unauthorized changes, ensuring system stability and simplifying debugging.

Fail fast (in business): essence, examples and criticism

The term has been widely used as a business metaphor since 2001, meaning that companies should run bold experiments to determine the long-term viability of a product or strategy, rather than proceeding cautiously and investing years in a doomed approach. It has become accepted as a kind of "mantra" in startup culture , that is, "Fail fast, fail often".

Fail fast , also sometimes called fail fast, fail often or fail cheap , is a business management concept and a theory of organizational psychology , which holds that companies should encourage employees to use a process of trial and error to quickly determine and evaluate the long-term viability of a product or strategy and to move on, cutting their losses, rather than continuing to invest in a doomed approach. It is an element of the corporate culture of some organizations , especially in the technology industry and in Silicon Valley in the USA .

The key rationale is that failure is discovered before significant investment, at the earliest opportunities in the effort. Related practices are intended to identify problems before extensive research and development begins and long before release or deployment . Sometimes misunderstood as encouraging outright failure, the crucial principle is "Principle 4: Contain the risk of loss – fail cheap".

The implied promise to employees is that the consequences of failure, if recognized quickly, will not negatively affect a person's standing, job or career; a key component of a successful approach is a corporate culture that not only tolerates but actively encourages and even celebrates failures that lead to valuable learning for the organization. It has been criticized for a lack of commitment to this implicit promise, for the risk of creating a culture of mediocrity, and for excessive optimism about the benefits of learning from failure.

The concept and theory holding that businesses should apply an aggressive and flexible method of trial and error to quickly determine and evaluate the long-term viability of a product or strategy, recognize that something is going wrong, and make adjustments or move on to something else, rather than spending years on a doomed approach.

The approach involves a gradual project development process with iterative checks to make sure that the product or strategy will meet the needs of the customer, consumer or organization before permanent investment is committed.

This concept was considered in academic circles as early as 1992 by Sim Sitkin of Duke University .

Speaking of the concept's implied promise to employees, Michael DePrisco of the Project Management Institute in 2022 criticized the concept as a platitude , writing that although managers encourage employees to be prepared for failure, in practice the consequences of failure often damage work or careers. He argued that a slightly modified approach, which he calls "Learn fast", can work if management follows through on the implied promise of job and career protection for failures, and also learns from those failures.

The concept has also been criticized, including by TechTarget and the University of Queensland business school , for the risk of encouraging mediocrity .

According to the New Yorker , numerous studies of entrepreneurial success have shown that "the data suggest that past failures in fact simply predict future failures" and that the predicted benefits of learning from failure may be overly optimistic.

The concept has been widely used as a business metaphor since at least 2001. It is widely used in the technology and pharmaceutical industries . It has become a mantra and a badge of honor in startup culture , especially in the technology industry and in Silicon Valley in the USA, where it is a common part of corporate culture.

Examples

Carol Bartz discussed a concept she called "fail-fast forward" in a 2001 speech at Stanford University, describing a system she implemented at Autodesk to "design a company that can fail at certain missions, be resilient to failure and respond to it, moving quickly past it".

Jeff Bezos of Amazon wrote in a 2015 shareholder letter that "failure and invention are inseparable twins. To invent you have to experiment, and if you know in advance that it's going to work, it's not an experiment". Chaos Monkey is a Netflix project that deliberately simulates or causes failure to test resilience. An early Facebook motto was " Move fast and break things ". The Japanese chemical firm Kao , considering a proposed entry into floppy disk manufacturing , tested whether consumers would accept disks branded by a company not known for technology products, by buying floppy disks from another manufacturer and labeling them as Kao disks, thereby inexpensively assessing the likelihood of failure. Procter and Gamble CEO Lafley, in his book "The Game-Changer " gives a list, which McGrath characterizes as "even [a celebration]", of costly product failures and lessons the company learned from those failures during his tenure as CEO .

There are examples of the psychological concept unrelated to business, discussed in the self-help book " Fail Fast, Fail Often " by John Krumboltz and Ryan Babineaux of Stanford University .

See also

  • Crash-only software
  • [[b12651]]
  • [[b12650]]
  • [[b12652]]
  • [[b7502]]
  • Bad failure vs. good failure
  • Fault-tolerant
  • Fail-stop
  • Fault-tolerant system

See also

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Theory of Reliability"

Terms: Theory of Reliability