Glossary

Idempotency

Idempotency means doing the same operation twice has the same result as doing it once. The second call does not create a second charge, a second invoice, or a second stock deduction.

Where does this show up?

A webhook from a payment provider will be delivered more than once. Store the provider event id and ignore a repeat. The same rule applies when a POS sells offline and syncs later. Kasheer POS keeps selling when the connection drops and syncs when it returns. A retry of that sync must not create a second ZATCA invoice for the same sale.

KiipList has the sibling problem on stock. A sale on one channel has to reduce quantity once, on every channel, not twice because two workers processed the same order.

What is the smallest design?

  1. A unique key from the sender.
  2. A unique constraint in the database.
  3. A handler that returns the original result when the key is already stored.

Questions

Is an idempotency key the same as a primary key?

It can be. The point is that the sender's id is unique in your store.

Which product has to sync after offline use?

Kasheer POS.

Which product has to apply a sale once across channels?

KiipList.

Do we publish a library for this?

No. The check is part of the slice that touches payments or sync.