Never Cache a Failure
"There is none" and "I could not ask" are different answers. Cache the first, retry the second, and keep them as different types so the code cannot mix them up.
Guide collection
Retries, caches, timeouts and failure reports for software that tells the truth when things break
10 guides in this collection
"There is none" and "I could not ask" are different answers. Cache the first, retry the second, and keep them as different types so the code cannot mix them up.
Write to a temporary file beside the target and rename it into place. A reader then sees the whole old file or the whole new one, never half of either.
When twenty requests all need the same slow setup, let the first one do it and the other nineteen wait for the same promise.
A request with no timeout waits for ever, and it holds a page open while it waits. Set a deadline on every call, and never make a page wait for a slow lookup.
Responses can arrive out of order. Number each request, and let a response update the screen only if no newer request has started since.
Webhooks and jobs are delivered more than once. Make the duplicate impossible with a unique index, and claim the work in a single statement.
Record the work before you call out. Retry transient failures with a growing, randomised delay, stop on permanent ones, and hand what is left to a person.
A wrong diagnosis on screen is worse than a blank one. Classify the failure, show the upstream's own words, and never draw a zero where the truth is unknown.
curl exits 0 on a 403, and a pipeline reports the status of its last command. Mark work as done only inside a branch that checked the real result.
Browsers should not call a rate-limited public feed directly. One server fetch serves everyone, falls back to stale then bundled data, and says which it used.