n8n Static Data: Storing State Between Workflow Executions
By Abhishek Patoliya · 2026-08-16
A scheduled workflow that needs to process only new records since its last run — new rows added to a table, new files uploaded since the last check — needs somewhere to remember what "last run" actually means between one execution and the next, since each execution otherwise starts with no memory of what came before it. n8n static data is built specifically for this: small pieces of state, attached to the workflow itself, that persist across separate executions without needing to stand up an external database purely to hold a timestamp or a cursor.
When n8n Static Data Is the Right Tool, and When It Isn't
The deciding question is scale and structure, not just whether state needs to persist at all. A single value or a small bounded list that one workflow needs to remember between its own runs fits static data well. Anything larger, anything queried by more than simple key lookup, or anything multiple different workflows need to share is better served by a real external table from the start.
What Static Data Actually Is
Regular item data — the json and binary properties flowing through a workflow's nodes — exists only for the life of one execution and is gone once that execution completes. Static data is different: it's explicitly designed to persist, attached to the workflow definition itself rather than to any single run, and accessible from a Code node across every future execution of that same workflow until it's explicitly changed again.
A Basic Example: Tracking the Last Successful Run
The most common use case is a scheduled workflow that only wants to process records created or updated since the last time it ran successfully:
// n8n Code node — at the start of a scheduled workflow
const staticData = this.getWorkflowStaticData('global');
const lastRunAt = staticData.lastRunAt || '1970-01-01T00:00:00Z';
// Use lastRunAt to filter the query for only new/changed records
// ... fetch records updated after lastRunAt ...
// At the end of a successful run, update the stored value
staticData.lastRunAt = new Date().toISOString();
return $input.all();
The key detail: update the stored timestamp only after the run has actually completed successfully, not at the start. Updating it too early means a failed run still advances the cursor, silently skipping records that were never actually processed because the run failed partway through.
The 'global' vs 'node' Scope Distinction
n8n's static data API supports scoping to 'global' (shared across the whole workflow) or 'node' (scoped to the specific node accessing it). For most simple state-tracking needs — a single last-run timestamp used by one part of the workflow — global scope is simpler and sufficient. Node-level scope is useful specifically when multiple nodes in the same workflow each need to track their own independent piece of state without them colliding under the same key.
What Static Data Is Not a Substitute For
Static data is meant for small, simple values — a timestamp, a cursor, a short list of recently-processed IDs. It's not a substitute for a real database when the state involved grows large, needs to be queried in ways beyond a simple key lookup, or needs to be shared across multiple different workflows (static data is scoped to the individual workflow it's set in, not shared globally across an instance). If what's being stored starts looking like actual application data rather than a small operational marker, that's the signal to move it into a proper external table instead.
A More Involved Example: Deduplicating Across Runs
Combined with the deduplication patterns covered elsewhere on this blog, static data can track a rolling set of recently-seen record IDs to avoid reprocessing the same item across separate scheduled runs, without needing an external table purely for this purpose:
// n8n Code node — avoiding reprocessing across scheduled runs
const staticData = this.getWorkflowStaticData('global');
const seenIds = new Set(staticData.recentlySeenIds || []);
const newItems = $input.all().filter(item => !seenIds.has(item.json.id));
for (const item of newItems) seenIds.add(item.json.id);
// Keep the set bounded — retain only the most recent N IDs
staticData.recentlySeenIds = Array.from(seenIds).slice(-1000);
return newItems;
Bounding the stored set's size, as shown here, matters — static data isn't designed to grow without limit, and an ever-growing unbounded list stored this way will eventually become a genuine problem worth having avoided from the start.
Persistence and Backup Considerations
Static data is stored as part of the workflow's own definition in n8n's database, which means it's included in whatever backup strategy already covers workflow definitions generally — no separate backup mechanism is needed specifically for it. It's worth knowing, though, that restoring a workflow from an older backup also restores its static data to that older point in time, which matters if a restore is ever needed after static data has since moved forward — a restored workflow may reprocess records it had already handled since the backup was taken, which is worth accounting for in any restore procedure rather than assuming static data recovers seamlessly along with everything else.
Debugging a Workflow's Current Static Data Value
When a scheduled workflow behaves unexpectedly — skipping records it should have processed, or reprocessing ones it shouldn't — checking the current stored static data value directly is often the fastest way to understand why, faster than reasoning about the workflow's logic in the abstract. A quick Code node run manually, simply logging this.getWorkflowStaticData('global'), shows exactly what the workflow currently believes its own state to be, which frequently makes an otherwise confusing symptom immediately obvious — a stuck timestamp from a run that failed before updating it, or a seen-IDs list that never got bounded and grew unexpectedly large.
Manually Resetting Static Data When Needed
Occasionally a workflow's stored state itself needs a deliberate manual reset — after fixing a bug that had been silently corrupting it, or when intentionally reprocessing a historical date range. This is a normal, safe operation as long as it's done deliberately and the consequence is understood: resetting a last-run timestamp back to an earlier date, for instance, will cause the next run to reprocess everything since that earlier point, which is either exactly the intended recovery action or an expensive accident depending on whether it was done on purpose.
Static Data in Queue Mode and Multi-Worker Setups
In a queue-mode n8n instance with multiple workers, be aware that concurrent executions of the same workflow reading and writing static data close together in time can race — two executions both reading the same starting value before either has written its update, then both writing back a version that doesn't account for the other's change. For workflows where this matters (state that must stay strictly consistent even under concurrent execution), a real database with proper transactional guarantees is a safer choice than static data, which isn't designed to arbitrate concurrent writes from multiple simultaneous executions.
A Quick Reference for the Decision
Reach for static data when the state is small, simple, scoped to one workflow, and doesn't need to be queried in complex ways — a last-run timestamp, a small bounded cursor value, a short deduplication list. Reach for a real external table instead once the state needs to be shared across workflows, queried beyond simple key lookup, kept strictly consistent under concurrent writes, or once it's grown large enough that "small piece of state" no longer accurately describes what's actually being stored.
Written by Abhishek Patoliya, Senior n8n Developer & Automation Architect, Surat, India. Verified n8n Creator.