Zero Rows Returned
A payouts API reserves the idempotency key before doing any work, using a unique constraint so that concurrent duplicates cannot both proceed.
-- idempotency_keys(key TEXT PRIMARY KEY, request_hash TEXT,
-- status TEXT, response_body JSONB)
INSERT INTO idempotency_keys (key, request_hash, status)
VALUES ($1, $2, 'in_progress')
ON CONFLICT (key) DO NOTHING
RETURNING key;
const rows = await db.query(RESERVE_KEY, [key, hash]);
if (rows.length === 0) {
throw new ServerError('could not reserve idempotency key'); // 500
}
await createPayout(key, amount);
No payout is ever duplicated, but a handful of clients get a 500 and retry forever, never learning what happened to their payout. What is the defect and its fix?
Sign in to answer questions and track your progress
Sign In