Fintech adverts we read listed retries, idempotency, failure recovery and reconciliation as core duties. These words sound advanced, but the problem behind them is everyday Ghana: a customer taps "Pay", the network drops, they tap again. Did they just pay twice? A good backend makes sure the answer is no.
Timeouts: decide how long to wait
Every call to another service should have a time limit, as you saw in the asynchronous code lesson. But a timeout does not mean the call failed. The provider may have received your request and charged the customer; only the reply got lost. That uncertainty is the heart of this lesson.
Retries: try again, carefully
Many failures are temporary: a brief network drop, a busy server. Retrying often works. Good retries follow a few rules:
- Retry only errors that might be temporary, such as timeouts and
5xxcodes, not400errors caused by bad input. - Wait a little longer between each attempt, for example 1 second, then 2, then 4. This is called exponential backoff, and it avoids hammering a service that is already struggling.
- Stop after a few attempts and record the failure for a person or a scheduled job to follow up.