Use natural keys, idempotency tokens, upserts or state-based writes; never rely on "the client will not retry".
Making an operation idempotent
Use a natural key
PUT /users/42is naturally idempotent.POST /usersis not; generate the ID client-side or use an Idempotency-Key header.Use idempotency keys
Stripe's approach: client sends
Idempotency-Key: <uuid>. Server stores the response; a repeated key returns the cached response.Prefer upserts
INSERT ... ON CONFLICT DO UPDATE(Postgres),MERGE(SQL standard),PUTin REST.Design the schema for it
Unique constraints, version columns, state machines. Schema enforces idempotency that code alone cannot.