[ BLOG POST ]

Sending email exactly once with idempotency keys

An Idempotency-Key header lets you retry a send safely. Learn how the same key and body behave, and what a 409 response means.

Quick answer

An idempotency key is a unique value you send with a request so the server can recognize a retry. Sending the same key with the same body returns the original result instead of sending the email twice.

Key takeaways

  • Send an Idempotency-Key header on every send and batch request.

  • The same key with the same body returns the original result, with no second email.

  • A key reused with a different body is rejected with a 409 response.

Why do retries create duplicate emails?

A network timeout does not tell you whether the server received your request. If your code retries a send without a way to recognize it, the recipient may get the same email twice. Receipts, password resets and invoices make this painful.

An idempotency key solves the problem. You generate a unique value for each logical send, store it with your record, and send it in the Idempotency-Key header.

How does Sendflit treat repeated keys?

Send the same key with the same body and Sendflit returns the original result without sending the email again. Reuse the key with a different body and the request fails with a 409 response, because the two requests no longer describe the same message.

A 409 usually means your code reused a key for a different message. Generate a new key for the new message. If you meant to retry the first message, send the original body with the original key.

How should you choose a good key?

Use an identifier that is stable for the logical send, such as the order id plus the message type. A random value generated on each attempt defeats the purpose, because every retry then looks like a new message.

Keep keys for as long as your retry window lasts. Store each key with the record it belongs to, so a retry after a restart can find the original key.

Frequently asked questions

What is an idempotency key?

A unique value sent with a request so the server can tell a retry from a new request. Sendflit uses it on sends and batches.

What does a 409 response mean for an email?

The key was reused with a different request body. Use a new key for a new message, or resend the original body with the original key.

Does the idempotency key work for batches?

Yes. Send the Idempotency-Key header with a batch request, and retry the whole batch with the same key and body.

Last updated September 2026 by the Sendflit team.