Hacker News new | ask | show | jobs
by nivertech 1816 days ago
These are 2 different kinds of idempotency:

1. request (also command/mutation) idempotency (using Idempotency-Key in HTTP, or clientMutationId in GraphQL/Relay)

2. entity idempotency (using invoice_id)

(1) is more generic one and can be applied to any mutation with a side-effect, for example sending an email. It can also work with server-side generated IDs. It can be implemented as a generic middleware via cache or DB with TTL. That's what Stripe is doing.

(2) is more application-specific, for mutations actually changing a state (usually a DB row/document, or an entity managed by another service). Here the entity id should have a uniqueness constraint in the DB, and you should use either a semantic key (i.e. customer name), or a client-side generated ID like for example UUID.

I use a combination of both, to reduce a load on the DB while still having the same guarantees as using DB only.