Fail fast
An operation should stop and report an error as soon as the program can tell it cannot finish correctly. This avoids doing more work or producing a result based on invalid data.
Also known as: быстрый отказ
What fail fast means
Fail fast is the practice of stopping an operation once you have enough information to know it cannot produce a valid result. If a service needs a database connection string and none was configured, report the missing setting at startup. Otherwise the process may appear healthy until the first request that needs the database fails, farther from the source of the problem.
The key question is not how quickly the code runs, but when it can know something is wrong. A malformed request can usually be rejected before a database call. A conflict between two concurrent writes may only be known when the database enforces a constraint. An earlier check is useful only if it can reliably answer the question you're asking.
Example: check before changing state
def schedule_report(queue, report_id: str):
if not report_id.strip():
raise ValueError('report_id must not be blank')
return queue.enqueue('generate_report', report_id)
The guard stops a blank ID from becoming a queued job that a worker will inevitably reject. The exception is one way to report the failure, not a requirement of the principle. A function could return a typed error result instead. At an HTTP boundary, invalid client input should become an appropriate 4xx response rather than an unexplained 500. In each case, the caller gets an explicit failure instead of a misleading success or a silent default.
Where it helps and where it doesn't
In CI, run quick checks such as linting before expensive jobs when a lint failure would block the build anyway. On a web form, however, returning only the first invalid field can make the user submit the form repeatedly. You can collect all independent validation errors while still failing early enough to prevent any writes.
Failing fast does not mean crashing the whole service. Stop the smallest unit of work that cannot continue safely: a function call, a request, a job, or startup if the process cannot serve at all. A transient dependency failure is a separate decision. A bounded retry may make sense if repeating the operation is safe; retrying an invalid argument without changing it will not help.
How it comes up in interviews
An interviewer might ask where to put validation in an order flow that reserves stock and charges a customer. Explain what you can reject before either side effect, what must be enforced atomically when updating stock, and what happens if a later step fails. An exception alone does not undo a charge or roll back a committed write. Showing how you handle work that has already happened is as important as showing where you stop.