Skip to main content

Reliability Quiz

Last Updated: 2026-12-01 Status: Complete

Test your judgment on idempotency, events, webhooks and API design. Answers are collapsed; try each question before opening it.

Question 1: Same key, different amount​

A client retries a payment with the same idempotency key but a different amount. What does your API return and why?

View answer

It returns 422 with RFC 9457 problem details. A key is tied to one business intent, so a different payload is a client bug. Detect it by comparing a request fingerprint (hash of method, path and canonical body) with the one stored on the first request. Never process the new amount, and never replay the old result for different input. Return 409 only when the same request is still in flight. The blog post allows either 409 or 422 for a mismatched payload; this module follows the IETF draft: 422 for a mismatch, 409 for in flight. See Idempotency Key Implementation.

Question 2: Concurrent duplicates​

Two identical requests with the same key arrive within milliseconds. How do you prevent two charges?

View answer

A read-then-insert check lets both requests pass. Insert first, using INSERT ... ON CONFLICT DO NOTHING under a unique constraint on tenant and key, and commit it before any business work. The request that inserted the row executes; the other finds an in-progress row and gets 409, or a replay of the stored response if the winner has already completed. Scope the constraint by tenant so keys cannot collide across customers. See How Does Insert-First Locking Work?.

Question 3: Timeout after the processor call​

Your service calls a processor, the call times out, and the client retries with the same key. What should the retry do?

View answer

The outcome is unknown, so a blind second authorization risks a double hold. The key's committed recovery point processor_call_started, written before the call, shows the call may have happened, so the retry always takes the status-lookup or reversal path instead of restarting. Use the derived per-attempt key to look up the status at the processor; if you connect at ISO 8583, send a reversal before any new authorization. Hold the payment in the explicit unknown state until resolved. The inbound key never travels to the network. See Idempotency Key Implementation.

Question 4: Which failures to persist​

A request fails with a database error before any processor call, and the key is stored as completed with a 500. What is the consequence, and what would you do?

View answer

Replaying that 500 (Stripe v1's model) means the client can never succeed with that key, even though nothing happened downstream. The better policy is to persist definitive outcomes, such as success or a deterministic decline, and release the key on failures that occurred before any side effect, so the same key can be retried. If a side effect may have happened, keep the recovery point and resolve the outcome first. See Stripe v1, v2 and Adyen compared.

Question 5: Lost events​

A service commits a capture and then publishes payment.captured to the broker. After a crash, the ledger never learns of the capture. Fix it.

View answer

This is the dual-write problem: a database transaction cannot span the broker. Write the status change and an outbox row in one DataSource.transaction, then run a relay that publishes unpublished rows, either as a polling publisher using FOR UPDATE SKIP LOCKED or by log tailing with a tool such as Debezium. The relay can publish twice after a crash, so consumers must deduplicate by event id. With several relay workers, partition by aggregate so one payment's events stay ordered. See Event-Driven Payment Architecture.

Question 6: Out-of-order events​

A consumer receives refund.succeeded before payment.captured for the same payment. What do you build?

View answer

Only per-aggregate order can be trusted, and only if you partition by aggregate id. Carry a per-aggregate sequence in the envelope, taken from a dedicated counter incremented only when an outbox row is written. It is monotonic but not gapless, so the consumer compares "greater than", not "next": it ignores events at or below the last applied sequence and applies later ones, fetching current state when an earlier fact it needs is missing. For notification-style events, fetch the current state from the API instead of relying on arrival order. Never depend on global ordering across payments. See How Do You Keep Events in Order?.

Question 7: Consumer duplicates​

A broker redelivers a payout.paid event and the ledger posts it twice. How do you make the consumer safe?

View answer

Add an inbox table with a primary key on consumer and event id, and insert into it in the same transaction as the ledger posting using ON CONFLICT DO NOTHING; if nothing was inserted, return. If the posting throws, the inbox row rolls back so a retry is processed. Add a unique external reference on the journal entry as a second guard. Exactly-once delivery is not available end to end, so the consumer provides it. See How Do You Write an Idempotent Consumer?.

Question 8: Signature failures​

Webhook signature verification fails for every request after a framework upgrade added a body parser. What is the cause and the fix?

View answer

Signatures cover the exact raw bytes, and a parser that re-serializes JSON changes whitespace and key order. In NestJS create the app with rawBody: true, take req.rawBody through RawBodyRequest, and compute the HMAC over the signed string (timestamp, a dot, then the raw body, in Stripe's format). Compare with crypto.timingSafeEqual against every candidate signature, check the timestamp tolerance, and parse JSON only after verification. See What Must the Receiving Endpoint Do?.

Question 9: Duplicate webhook complaint​

A platform says it receives duplicate webhook events from you. How do you investigate and what do you change?

View answer

Duplicates are expected under at-least-once delivery, so look for the cause. Check the delivery log for slow 2xx responses followed by retries, multiple endpoints that match the same event type, manual resends, and two events generated for one occurrence. Keep the webhook id identical across retries, document at-least-once behavior, and show the delivery log to the customer. Advise the receiver to persist, acknowledge fast, and dedupe on event id with a unique constraint. See How Do You Investigate Duplicate Webhooks?.

Question 10: Declines in the API​

Product asks whether a declined card should return a 4xx or a 200. What do you recommend, and what must be consistent?

View answer

Both conventions exist: Stripe documents a 402 for card errors, while an outcome-in-body design returns a successful call with a payment whose status is declined. Recommend the outcome-in-body approach, because the declined payment is a resource with an id, an audit trail and events, and a decline is normal business, not an API fault. Whatever you choose must be uniform across endpoints, use a normalized decline category rather than raw network codes, and include a retryable signal. Reserve problem details for real API errors. See Payments API Design.

Share: