~learn.
0:00 / 1:26
W06 · Notification platform

Your idempotency store saved a timeout. Now every retry fails for 24 hours.

transcript

One network blip on a payment call. Your system retries. And for the next 24 hours, every retry fails. Instantly.

Food delivery interview. The interviewer asks: how do you never double charge? You call Stripe. It times out. You retry. Without a key, that's a second charge.

So every payment call carries an idempotency key. First: is a result stored for it? Yes? Return exactly that result. No new charge. No? Take a Redis lock on the key, for 30 seconds. Only one request goes on. It calls Stripe with the same key. Then stores the result for 24 hours.

But here's the catch. Stripe times out. That's a result too. Do you store it? Store it, and every retry with that key gets the timeout back. For 24 hours.

A success is final. Store it. A declined card is final too. Retrying won't change it. Store it. A network error, a 5xx, a rate limit? Those can pass. Never store them. The retry goes back to Stripe, with the same key. So it still can't charge twice.

A declined card is an answer. A timeout is an accident. Store answers. Keep accidents retryable.

Full breakdown in the lecture.