Good question, and it is the one that bites in production: an in-memory “deferred” job dies with the process, so the fix is to move the queue out of the execution and make recovery idempotent. What has worked for me:
1. Do not try to resume the execution - recover the job.
n8n execution state is not a durable queue. After a restart the original execution (and anything a Wait node held in memory) is gone. Treat n8n as a worker and keep the deferred work in a store you control (Postgres preferred; Sheets/Airtable only if it must be codeless).
2. Persist a self-contained job row.
Useful columns: id (stable dedup key derived from the source event - order/message id, or a hash of the meaningful fields; never $execution.id, $now or a random uuid), state (queued|claimed|done|review), payload (everything needed to re-run without the original trigger), attempts, claimed_at, updated_at, last_error, provider_ref.
Enqueue with a unique constraint + INSERT ... ON CONFLICT DO NOTHING so the same event can never create two jobs.
3. Claim atomically, not check-then-insert.
One Postgres node:
INSERT INTO jobs (id,state,...) VALUES ($1,'claimed',...) ON CONFLICT (id) DO NOTHING RETURNING id
or UPDATE jobs SET state='claimed', claimed_at=now() WHERE id=$1 AND state='queued' RETURNING *. Only the row-returning branch proceeds; the empty branch does nothing. That is what makes simultaneous duplicate delivery safe.
4. Make completion monotonic.
UPDATE jobs SET state='done', provider_ref=$2 WHERE id=$1 AND state='claimed'. After the side effect, a late duplicate cannot flip a finished job back.
5. Recover on a schedule, not on restart.
A separate sweeper workflow (Schedule Trigger, every N minutes): SELECT * FROM jobs WHERE state='claimed' AND claimed_at < now() - interval '10 minutes'. For each stale claim the right move depends on the provider:
- provider honours an idempotency key / unique reference (Stripe Idempotency-Key, a natural-key upsert, an order API with a client reference) → re-issue with the same key, or query by reference. That is the only real exactly-once.
- provider only suggests the key (SMTP, most generic webhooks, append-only APIs) → you cannot distinguish “submitted but unconfirmed” from “not submitted”. Move the row to
review, keep the reconciliation handle + execution id, and alert a human. Never blindly re-send.
6. Test the unknown, not the happy path.
Your table already covers the good cases. Add the failure boundary: kill the process after the external action returns but before mark-done, then run the sweeper. Assert (a) no duplicate send on the provider side, not just one n8n execution; (b) a legitimate new event still proceeds; (c) an ambiguous one lands in review and stays visible.
Two traps: do not hold “deferred” in a Wait node and assume a restart resumes it - externalize the delay; and do not treat lastNodeExecuted as proof the side effect did not happen.
Curious whether your deferred jobs live in Postgres or in n8n’s own execution table - the recovery story changes a lot depending on that.