Prompt
Do I need idempotency for invoice creation requests?
Latest observation
Usually, yes — you should use idempotency for invoice creation requests if there’s any chance the request might be retried.
Why
Creating an invoice is typically a non-idempotent operation: if the same request is sent twice, you could end up with two invoices instead of one. Retries can happen because of:
- network timeouts
- client retries
- load balancer / proxy retries
- user double-clicks
- webhook or job reprocessing
When it matters most
Idempotency is especially important if invoice creation:
- triggers payment collection
- sends customer emails
- affects accounting records
- must be unique per order/subscription/period
Common approach
Use an idempotency key supplied by the client, or a deterministic uniqueness constraint such as:
order_id + invoice_type + billing_period- a unique client-generated request ID
Then, if the same request is received again, return the original invoice rather than creating a new one.
When you might not need it
You may skip explicit idempotency if:
- invoice creation is strictly internal
- you can guarantee no retries
- duplicates are harmless and later deduplicated
- the operation is already protected by a strong uniqueness constraint
But in most production systems, invoice creation is important enough that idempotency is a good idea.
Practical recommendation
For an API endpoint like:
POST /invoices
implement idempotency if the call can be retried or repeated. For example, have the client send:
Idempotency-Key: <uuid>
and store the result keyed by that value.
If you want, I can also show a minimal idempotency design for invoice creation, including schema and request/response behavior.