@Peter_Gavin Emmas and Jarvis1 have already covered the important part (write the intent to the DB be4 the call, keep “unknown” as its own state, resolve it by asking the provider). What was missing for me was how you actually wire that up in n8n, which node settings matter & what happens when n8n itself dies mid call. So I built it and tried to break it. have n8n 2.38.7 in docker, Postgres 16, plus a tiny fake payment API where I can make a request timeout, get declined, or kill n8n while the call is in flight.
The short answer is that u don’t need n8n to “resume” anything. 2 scheduled workflows and 1 table. The table is your outbox and every tick jst asks the DB what is still owed.
The table
CREATE TABLE jobs (
id bigserial PRIMARY KEY,
order_id text NOT NULL UNIQUE, -- business key = idempotency key
amount integer NOT NULL,
status text NOT NULL DEFAULT 'pending'
CHECK (status IN ('pending','processing','completed','failed','unknown','review','dead')),
attempt integer NOT NULL DEFAULT 0, -- charge attempts
reconcile_attempt integer NOT NULL DEFAULT 0, -- times we asked the provider about an unknown row
claimed_at timestamptz,
charge_id text,
last_error text,
updated_at timestamptz NOT NULL DEFAULT now()
);
Whatever triggers ur flow today (webhook, form, another workflow) should only INSERT a pending row and stop. It should not call the API. Once the side effect is driven by a row in Postgres instead of by an execution that happens to be running, recovery becomes boring, which is what you want.
Workflow 1: charge jobs (Schedule Trigger, every minute)
Schedule Trigger → Postgres (claim) → Filter → HTTP Request (charge) → IF (2xx?) → Postgres (completed / failure), plus a Postgres node on the error output of the HTTP Request
Postgres, Execute Query, “Claim up to 10 jobs”. Same idea as Jarvis1’s conditional update, just batched:
UPDATE jobs j
SET status = 'processing', attempt = attempt + 1,
claimed_at = now(), updated_at = now()
FROM (SELECT id FROM jobs
WHERE status IN ('pending', 'failed')
ORDER BY id
FOR UPDATE SKIP LOCKED
LIMIT 10) c
WHERE j.id = c.id
RETURNING j.id, j.order_id, j.amount, j.attempt;
FOR UPDATE SKIP LOCKED means 2 overlapping executions (or 2 workers in queue mode) can’t grab the same row. No explicit transaction needed, a single UPDATE is atomic anyway.
Filter, “Skip if nothing was claimed”, condition {{ $json.order_id }} exists. Easy to miss: when the query above matches no rows the Postgres node does not output zero items, it outputs one item { "success": true }. Without the Filter the HTTP Request runs with an undefined order_id on every idle tick. I only noticed because my first version did exactly that and my fake API got a charge with order_id null. With the Filter in place an idle tick looks like this, claim outputs the success item, Filter keeps nothing, HTTP node never runs:
HTTP Request, “POST /charge”. Four settings do the real work here:
- Header
Idempotency-Key: {{ $json.order_id }}, so a retry is also safe on their side if they support it.
- Options > Timeout = 5000 ms. Set it explicitly so “uncertain” has a known upper bound you can size the recovery lease against. (HTTP Request node docs, Timeout)
- Options > Response > Never Error = on and Include Response Headers and Status = on. Every HTTP response, 200 or 502, now comes out of the Success output as an item with
statusCode and body. The Error output is left with only the cases where there was no HTTP response at all (timeout, reset, DNS). (Response options)
- Settings tab > On Error = Continue (using error output), and Retry On Fail = off.
“Continue (using error output)” gives the node a second output with the error attached to the item, so the transport failures get recorded in the same execution instead of stopping it. (node settings docs) Why split it this way: the error item only carries message, name and stack, no status code, so anything you classify from it is string matching. The full response on the Success output gives you a real status code and a parsed body to decide on.
About Retry On Fail being off: it retries on a timeout as well, and a timeout is exactly the case where the provider may already have done the work. I checked this with a separate little workflow (Retry On Fail on, 3 s timeout, provider that answers after 20 s). The provider counted two requests for one item. The second one was only harmless because my fake provider honours the idempotency key. Without that it’s a second charge. And even when it is safe, the retry happens inside n8n where your table can’t see it. I’d rather keep retries in the table (failed rows get re-claimed on the next tick) so they are counted and visible.
IF, “2xx?” on {{ $json.statusCode }} between 200 and 299.
Postgres, “Mark completed” on the true branch:
UPDATE jobs
SET status = 'completed', charge_id = $2, updated_at = now()
WHERE order_id = $1 AND status = 'processing'
RETURNING order_id, status, attempt, charge_id;
Query Parameters: {{ [ $('Claim up to 10 jobs').item.json.order_id, $json.body.charge_id ] }}
Postgres, “Record failure” on the false branch. The provider answered, but not 2xx. The default is unknown. Only a response that the provider documents as “nothing happened” is allowed to reach the attempt-limit / failed / dead logic:
UPDATE jobs
SET status = CASE
WHEN NOT $2::boolean THEN 'unknown' -- 5xx, 502 html page, empty body, anything unfamiliar
WHEN attempt >= 3 THEN 'dead' -- definite failure, out of attempts
ELSE 'failed' -- definite failure, re-claimed next tick
END,
last_error = $3, updated_at = now()
WHERE order_id = $1 AND status = 'processing'
RETURNING order_id, status, attempt, last_error;
Query Parameters:
{{ [ $('Claim up to 10 jobs').item.json.order_id,
[402, 400, 422].includes($json.statusCode) && ['card_declined','insufficient_funds','invalid_request'].includes($json.body?.error),
`${$json.statusCode} ${typeof $json.body === 'object' ? JSON.stringify($json.body) : String($json.body ?? '').slice(0,200)}` ] }}
The whitelist in the second parameter is the one bit you write from your provider’s docs, and it is the only way to failed. Everything that is not on it, a 502 from a gateway, a bare 504, a 500 with an empty body, a new error code they added last week, stays unknown and gets resolved by workflow 2 asking the provider. (My first version had this backwards: a regex that recognised timeouts and treated everything else as definite. @DovahkiinMOL pointed out below that an unfamiliar error would then fall through to failed, which contradicts the whole point. He is right, and the fix is the inverted default above, not a longer regex.)
Postgres, “No response → unknown” on the Error output. Nothing to classify here, the provider may have done the work:
UPDATE jobs
SET status = 'unknown', last_error = $2, updated_at = now()
WHERE order_id = $1 AND status = 'processing'
RETURNING order_id, status, attempt, last_error;
Query Parameters: {{ [ $('Claim up to 10 jobs').item.json.order_id, String($json.error?.message ?? 'no response') ] }}
(Docs for the $1, $2 placeholders: Postgres node, query parameters. Passing them as a single array expression worked for me on Postgres node v2.6 and avoids the problem of an error message that contains commas.)
One tick with five orders set up to hit every path: a good one, a structured 402 decline, a 502 html page, a 500 with an empty body, and one where the provider takes 20 s to answer:
order_id | status | attempt | charge_id | last_error
----------------+-----------+---------+-------------+------------------------------------------------
ord-4001 | completed | 1 | ch_90361165 |
ord-4002-fail | failed | 1 | | 402 {"error":"card_declined","message":"Your card was declined."}
ord-4003-502 | unknown | 1 | | 502
ord-4004-empty | unknown | 1 | | 500
ord-4005-slow | unknown | 1 | | timeout of 5000ms exceeded
Only the documented decline reached failed. And on the provider side for the timed-out one, the charge exists, n8n just never got the response:
GET /charges?idempotency_key=ord-4005-slow
{"found": true, ...}
If that row had been marked failed and retried, that’s your double charge.
Workflow 2: reconcile unknown jobs (Schedule Trigger, every 5 minutes)
Schedule Trigger → Postgres (sweep + list) → Filter → HTTP Request (GET by idempotency key) → IF → Postgres (settle), plus a Postgres node on the error output of the GET
Postgres, “Sweep stale processing to unknown”. Three things in one statement: stale processing rows become unknown, rows that have been unknown too long become review (a human’s problem, see below), and everything else that is unknown gets asked about and counted:
WITH swept AS (
UPDATE jobs SET status = 'unknown', updated_at = now()
WHERE status = 'processing' AND claimed_at < now() - interval '5 minutes'
RETURNING id
),
aged AS (
UPDATE jobs SET status = 'review', updated_at = now()
WHERE status = 'unknown'
AND (updated_at < now() - interval '24 hours' OR reconcile_attempt >= 288)
RETURNING id
),
asked AS (
UPDATE jobs SET reconcile_attempt = reconcile_attempt + 1
WHERE status = 'unknown'
AND NOT (updated_at < now() - interval '24 hours' OR reconcile_attempt >= 288)
RETURNING id, order_id, amount, attempt, reconcile_attempt
)
SELECT id, order_id, amount, attempt, reconcile_attempt FROM asked
UNION ALL
SELECT j.id, j.order_id, j.amount, j.attempt, j.reconcile_attempt
FROM jobs j WHERE j.id IN (SELECT id FROM swept)
ORDER BY id;
The 5 minute lease has to be comfortably longer than the HTTP timeout in workflow 1, otherwise you sweep a row that is still genuinely in flight. 288 is just 24 hours of 5 minute ticks. The aged and asked conditions are complements of each other on purpose, Postgres does not support updating the same row from two CTEs in one statement. updated_at is only written when a row changes state, never by the “ask the provider” step, so it doubles as the “unknown since” clock. Same Filter on order_id after this node, same reason as before.
HTTP Request, “GET /charges?idempotency_key=” with Options > Response > Never Error turned on, so a 404 (“we have nothing for that key”) is data and not an exception. (HTTP Request node docs, Response options) Never Error only covers response codes though. A timeout or a dropped connection has no code and still throws, and with the default On Error = Stop Workflow one unreachable provider ends the tick and the rest of the batch waits. So this node also gets Settings > On Error = Continue (using error output), and the error output goes to a small Postgres node that leaves the row where it is:
-- error output of the GET: provider could not answer. Stay unknown, note why,
-- and do NOT touch updated_at, the 24h clock keeps running.
UPDATE jobs SET last_error = $2
WHERE order_id = $1 AND status = 'unknown';
IF, “Provider has it?” on {{ $json.found }} (or whatever your provider returns), then:
-- true: it succeeded, we just never heard
UPDATE jobs SET status = 'completed', charge_id = $2, last_error = NULL, updated_at = now()
WHERE order_id = $1 AND status = 'unknown';
-- false: that attempt definitely did not happen. Now it is safe to count it.
UPDATE jobs SET status = CASE WHEN attempt >= 3 THEN 'dead' ELSE 'failed' END, updated_at = now()
WHERE order_id = $1 AND status = 'unknown';
The crash test (API succeeds but n8n dies before saving)
With workflow 1 published I added a slow order and ran docker kill on the n8n container about 1.5 s after the row went to processing, so while the request was in flight.
After the restart n8n shows this:
The executions list shows it as an error (status crashed if you look at it through the API) and the node panel literally says the data was not saved. So n8n has no idea whether the call returned. One warning here: don’t reach for the Retry button on that execution. I tried it. It runs from the trigger again, the claim finds nothing because the stranded rows are processing, the execution goes green and nothing is recovered. Only the sweep in workflow 2 brings those rows back. Meanwhile the provider had this:
GET /charges?idempotency_key=ord-1004-slow
{"found": true, "charge_id": "ch_69032535", ...}
and both rows from that execution were stuck in processing:
order_id | status | attempt | claimed_at
---------------+------------+---------+-------------------------------
ord-1002-fail | processing | 2 | 2026-09-13 13:55:38
ord-1004-slow | processing | 1 | 2026-09-13 13:55:38
Workflow 1 kept running every minute after that (you can see the ticks in the sidebar of the screenshots) and never touched those two rows, because processing is not claimable. So a crash can’t cause a double charge no matter how long recovery takes. Once the lease expired, workflow 2 settled both based on what the provider said, not on a guess:
order_id | status | attempt | charge_id
---------------+-----------+---------+-------------
ord-1002-fail | failed | 2 | (provider had nothing, re-claimed next tick)
ord-1004-slow | completed | 1 | ch_69032535 (provider had it, n8n just never saw the response)
Two ticks of workflow 1 later the declined order hit attempt 3 and went to dead:
ord-1002-fail | dead | 3 |
So, to your questions
How to resume safely: don’t resume the execution, re-derive the work from the table. A schedule that claims pending/failed rows is a “resume” that works after a node error, a timeout, a crash or a redeploy and needs nothing from n8n’s execution history.
Transaction vs outbox vs recovery workflow: the table above is the outbox, workflow 1 drains it, workflow 2 is the recovery workflow. A Postgres transaction only helps for the pure DB part. The Postgres node does have a Query Batching > Transaction option if you have several statements that must succeed together (docs), but it can’t cover the HTTP call, so don’t try to make it.
API succeeded but n8n crashed before saving: the row is still processing with a claimed_at. Nothing retries it. After the lease it becomes unknown and only the provider’s answer moves it to completed or failed. That is the test above.
Dead letter: on a definite failure at attempt N (I used 3), decided in SQL where the attempt counter lives. Never from unknown, in the crash test that would have dead-lettered a charge that actually went through. Unknown gets its own exit instead: if the provider has not been able to answer for 24 hours the row goes to review. dead is the machine saying it definitely failed, review is the machine saying it could not find out, and that one might be money, so they need separate alerts. A third tiny workflow doing SELECT status, count(*) FROM jobs WHERE status IN ('dead','review') GROUP BY status and posting to Slack is enough. For real node errors (bad credentials, Postgres down) set an Error Workflow on both workflows so you at least hear about it (docs).
Happy to paste the two workflow JSONs if that helps, they are 8 nodes each and you’d only need to swap the Postgres credential and the two URLs.
Edit 14 Sep: added the review state, the error output on the reconcile GET and the Retry warning after @Anshul_Namdev’s review below. The test run for those changes is in my follow up post.
Edit 14 Sep, later: inverted the failure classification in workflow 1 (unknown by default, failed only on a documented provider response) after @DovahkiinMOL’s review below.