How PostHog delivers messages reliably
A message can fail in many places between your app and the recipient: a network timeout, a crashed worker, a throttled email provider, or a burst of sends that is larger than your allowance. PostHog's delivery pipeline turns temporary failures into delays and permanent failures into clear errors instead of silent loss.
This page explains how the pipeline works, and which parts of reliability stay in your app. For the steps to handle errors, see retries and errors.
The delivery pipeline at a glance
- A trigger creates a message. Your code calls the transactional email API, or an automation or broadcast reaches an email step.
- PostHog checks it. A transactional API call goes through its idempotency check, then the checks for suppression, paused or suspended sending, quota, and recipient domain. A refusal returns to your code at once, with an error code.
- PostHog queues it. The message becomes a job in a durable queue. For a transactional API call, the
202response means PostHog accepted the email and will send it from the queue. - A worker claims the job. Workers take jobs from the queue, highest priority first.
- The worker checks pacing. Workflow rate limits and the project's daily allowance decide whether the email can go now. If it can't, the job goes back to the queue with a later run time.
- The worker sends it. The worker hands the email to Amazon SES. If SES throttles the request, the job goes back to the queue.
- The outcome comes back. PostHog records the status, and engagement events when they are on.
Durable queueing
PostHog runs its email queue on a dedicated PostgreSQL database. Each message is a row in a jobs table. The row stays there until a worker finishes it, so a message survives a restart of any worker.
Four mechanisms keep the queue correct when many workers share it:
- Atomic claims. Workers claim jobs with
FOR UPDATE SKIP LOCKED. Two workers can never claim the same job, and a worker never waits for a row that another worker holds. - Lock IDs. Each claim gets a unique lock ID. Every write that finishes, fails, or reschedules a job must match that lock ID. If a slow worker loses its claim, its late write changes nothing, so it cannot overwrite the work of the worker that took over.
- Heartbeats. A worker renews its claim while it works on a job. A heartbeat tells the rest of the system that the worker is still alive.
- A janitor. A separate service watches for jobs with stale heartbeats. When a worker crashes in the middle of a job, the janitor puts the job back in the queue, and another worker runs it.
A job that stalls again and again, for example because it crashes every worker that runs it, cannot stay in the queue forever. After too many stalls in a row, the janitor stops retrying it. It does not drop the job without a record: first it writes a failed result that you can see in the workflow's Invocations, and that PostHog can run again. Only then does it remove the row from the queue.
Recovery has a cost. If a worker crashes in the short time after SES accepts an email and before the worker records the result, the janitor runs the job again, and the email can go out twice. This is rare. When SES does not answer in time but may have accepted the email, the worker does not send it again. Idempotency keys, below, protect your API calls against duplicates. They do not cover a crash inside PostHog's own worker.
Priority lanes
The email queue has two lanes:
- Fast lane: transactional email, including transactional API sends without a marketing category and any workflow or broadcast email with a transactional category.
- Bulk lane: marketing email and email with no category.
Workers always take fast-lane jobs first. Without lanes, a broadcast to 100,000 people would put a password reset behind 100,000 marketing emails from the same project. With lanes, the password reset goes first, even while the broadcast is still in the queue.
The fast lane only works because it stays small. Only email that you mark as transactional goes in it. That is one reason to keep marketing out of the transactional category. See marketing vs. transactional email.
Transactional email also skips the wait for the daily allowance. It still uses up allowance, but it never waits for the allowance to refill.
Idempotency keys prevent duplicate sends
Network failures make retries necessary, and retries make duplicates possible. If your app sends a password reset and the connection drops before the response arrives, your app can't know whether PostHog got the request. An idempotency key makes the retry safe.
You send a key with each transactional API call, in the Idempotency-Key header or as idempotencyKey in the SDKs. PostHog keeps the key for 7 days, separately for each project. Then:
| What happens | Result |
|---|---|
| A retry with the same key and the same request | Nothing new sends. PostHog returns the first message ID, with "replayed": true. |
| A retry while the first request is still running | 409 idempotency_key_in_flight. Retry after a few seconds. |
| The same key with a different request | 422 idempotency_key_reused. A new email needs a new key. |
| A request that PostHog refused | The key stays unused, so you can send it again. |
The key works because it comes from your data, not from the moment of the call. Build it from the record that caused the email, such as password-reset-{reset_request_id}. A random value or a timestamp makes each retry look like a new email.
Retries and pacing instead of drops
A send that can't go now waits in the queue. PostHog separates temporary problems from permanent ones:
Temporary problems wait.
- SES throttling. When Amazon SES returns
TooManyRequestsExceptionorThrottlingException, the worker puts the job back in the queue with a backoff, and does not fail it. - Workflow rate limits. A workflow with a sending rate limit spreads its sends over time. Sends above the rate wait in the queue.
- The daily allowance. The allowance works like a token bucket that refills continuously. A marketing email that does not fit waits in the queue until the bucket has enough room, with a random spread so that waiting emails don't all wake at once. The workflow's invocations show the delay.
Permanent problems fail fast.
- An invalid or unreachable recipient.
- A suppressed address.
- Paused or suspended sending.
Another attempt gives the same result for these, so a retry only adds load and delay. PostHog fails the send at once, with an error code that says why.
The per-person frequency cap is a separate control. It skips marketing messages over the cap, unless you set a hold time. It does not queue them.
What you still handle in your app
PostHog makes a message durable once it is in the queue. Your app owns the part before that: getting the request to PostHog.
- Send an idempotency key with every transactional call. Build it from your own record ID, so every retry uses the same key.
- Retry the temporary errors by error
code. Retry409 idempotency_key_in_flight,429 throttled,503 delivery_unavailable, and network timeouts, with backoff and the same key. For429 throttled, wait for the time in theRetry-Afterheader. - Don't retry permanent or quota errors. A
400, a422(such asrecipient_suppressedorsending_suspended), or a429 quota_limitedwill not succeed on retry. For429 quota_limited, check your billing limits. - Check the status. A
202means PostHog queued the email, not that it arrived. See the status on the Log tab, through the API for sent emails, or with a status lookup.





