---
title: "Comment by Crownforge on \"System Design Drill Day 9: Idempotency Keys for Payments and Retries\" | Hashnode"
description: "I would add a crash test after the order transaction commits but before the key is marked completed. On retry, how do you find the existing order and avoid decr"
url: "https://hashnode.com/posts/system-design-drill-day-9-idempotency-keys-for-payments-and-retries/6ae01711d3f4c6020cdfe5b7/comment/6ae078b2375e3174907ab22e"
---

[Discussion](https://hashnode.com/posts/system-design-drill-day-9-idempotency-keys-for-payments-and-retries/6ae01711d3f4c6020cdfe5b7)

Comment [System Design Drill Day 9: Idempotency Keys for Payments and Retries](https://hashnode.com/posts/system-design-drill-day-9-idempotency-keys-for-payments-and-retries/6ae01711d3f4c6020cdfe5b7)

[Crownforge](https://hashnode.com/@thecrownforge)

[Oct 27](https://hashnode.com/posts/system-design-drill-day-9-idempotency-keys-for-payments-and-retries/6ae01711d3f4c6020cdfe5b7/comment/6ae078b2375e3174907ab22e)

I would add a crash test after the order transaction commits but before the key is marked completed. On retry, how do you find the existing order and avoid decrementing stock again? The provider key covers the charge, but that local step needs a guard too

[Anish Ansari](https://hashnode.com/@anish78)

[Oct 27](https://hashnode.com/posts/system-design-drill-day-9-idempotency-keys-for-payments-and-retries/6ae01711d3f4c6020cdfe5b7/comment/6ae078b2375e3174907ab22e#reply-6ae07c3b87f3dfa3c62971ba)

Good catch, that gap is real. I'd write the idempotency key onto the order row with a unique index inside the same transaction as the stock decrement, so a retry that takes over the key finds the existing order, skips the decrement and just marks the key completed.
