Transient vs Permanent Failures
Concepts covered: Retry & Failure Handling
A task fails when a call it makes returns an error or never returns at all. The error says what happened; it does not say what to do next. That decision comes down to one question: if the task ran the same step again in 10 seconds, would it succeed? Each of the 3 possible answers calls for a different response.
One question, 3 answers
A transient failure is one where the answer is yes. The cause sits outside your code and passes on its own: a network connection dropped halfway through a request, a database refused a new connection because its pool was full, an API returned 503 because the server behind it was restarting. The request itself was fine, so sending it again after a pause gets it through.
A permanent failure is one where the answer is no. The cause is in the request itself or in the code, and waiting changes nothing: the file you asked for does not exist, the API key expired last week, a record carries the string N/A where the schema expects an integer, a function raised KeyError on a column the source renamed. The second attempt fails for the same reason as the first, and so does the fiftieth.
An ambiguous failure is one where the error does not tell you. A request timed out after 30 seconds: did the server never receive it, or did it process the request and lose the response on the way back? A 500 Internal Server Error says the server hit a bug, which might be a one-off under load or might be triggered by your exact payload every time. The status code alone cannot settle it.
| What the task sees | Typical cause | Category | First response |
|---|---|---|---|
| Connection reset by peer | A network hop dropped the socket | Transient | Retry after a pause |
| 503 Service Unavailable | The service is restarting or overloaded | Transient | Retry after a pause |
| 429 Too Many Requests | You exceeded the service's rate limit | Transient | Retry after the pause the service asks for |
| 401 Unauthorized | The credential is wrong or expired | Permanent | Stop, alert, rotate the credential |
| 404 Not Found | The resource or endpoint does not exist | Permanent | Stop and alert |
| ValueError parsing a row | The data does not match the expected shape | Permanent | Set the row aside, continue |
| Timeout after 30 s | Slow network, slow server, or a lost response | Ambiguous | Retry only if the step is idempotent |
| 500 Internal Server Error | The server raised an unhandled error | Ambiguous | Retry a few times, then stop |
The response follows the category
Transient failures get a retry: wait, then run the same step again, a limited number of times. Permanent failures get the opposite. Retrying them wastes the time budget, delays the alert that someone needs to see, and in the worst case does damage, such as locking an account after too many bad logins. The task should stop at once and surface the error with its full traceback.
Ambiguous failures are where the idempotency lesson pays off. A timed-out call to write a batch of 5,000 rows may have landed every row before the response was lost. If the write replaces the partition rather than appending, running it again is safe, and you can treat the timeout as transient. If the write appends, a retry risks 10,000 rows where 5,000 belong, and the timeout has to be treated as permanent until someone checks what landed. The category of an ambiguous error depends on the step, not on the error.
A nightly task that loads a partner's daily order file raised a different error on each of 4 nights. Which of these should the task stop on at once, rather than retry?
- A 503 from the partner's API while it was mid-deploy, which cleared within a minute
- A KeyError: 'customer_id' raised after the partner renamed that column to cust_id
- A connection reset 40 seconds into downloading a 900 MB file from the partner
- A 30 second timeout on the first call, after which the partner's status page showed a brief outage
About this lesson
This section is part of the Failure Handling: Beginner lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.