Why n8n runs out of memory and when a fix is needed
A workflow dies partway through a large run with a heap out-of-memory error, or the editor drops into Connection Lost while a big execution is still going. Both symptoms point to the same place: the n8n process has run out of room in the Node.js heap. n8n is a Node.js process, so the items a workflow carries between nodes, any binary data such as files and images, and the variables created by Code node scripts all compete for one memory space. A workflow that handles a few hundred small records can run comfortably, then fail when an upstream API returns a single response many times larger, or when a loop keeps every intermediate result in memory until the end.
A bigger server is not always the answer. Adding RAM raises the ceiling, but it does not change how much data a single execution holds at once, so a workflow that grows with its input will eventually hit the new limit. A fix is needed when the failure repeats with the same workflow, when memory use climbs across a run instead of spiking at one node, or when the same payload size fails on a machine with more memory than before. Confirm with your own environment first: check the container or host memory limit, the Node.js heap settings in effect, and the execution log for the node where the run stopped. If the crash is tied to one workflow and one input shape, the right fix is usually in the workflow design. If it appears across many workflows at once, look at how the instance is hosted and how many executions run in parallel.
How to diagnose which execution caused the crash
This sequence narrows an out-of-memory crash from the container log down to one workflow, one node and one input size, so the fix targets the actual cause. Each step produces a finding that feeds the next, ending with a confirmed trigger you can reproduce.
Confirm the crash in the process logs
Start by pulling the logs from the n8n container or process for the time of the failure. Look for the Node.js heap error, which reports that the JavaScript heap ran out of memory, and for the Connection Lost message that the editor shows when the backend stops responding. Check the orchestrator or service manager too, since it records whether the process exited and was restarted. Confirm the instance restarted before going further, because a restart means the process was killed rather than handling an error. Record the timestamp of the crash, which you will need to match against execution history. The step is done when you have a timestamped log excerpt that shows the heap error and the restart event together.
Match the crash to a running execution
Open the execution list in n8n and filter for executions that were running at the crash timestamp. Executions still marked as running or as having no final status when the instance came back are the likely candidates. In queue mode, check the worker logs instead, because the worker that ran the job is the process that ran out of memory. If several executions overlap the crash window, note each one's workflow name, trigger type and start time. The step is done when you have a short list of candidate executions, each tied to a workflow and a start time.
Identify the node that was running
Open each candidate execution and find the last node that started but did not finish. In the execution view, nodes that completed show their output, while the node that was active at the crash typically has no output or shows an error state. Compare the node sequence against the workflow canvas to confirm which step was executing. Pay particular attention to Code nodes, HTTP Request nodes that download files, and nodes that merge or split large lists, because these are the common places where memory use grows. The step is done when you can name one node as the probable point of failure.
Measure the input size at that node
Look at the output of the node immediately before the suspect node and count its items. Note the size of the JSON for a representative item, and whether any item carries binary data, such as a file or an attachment. Large base64 strings inside JSON fields are a frequent cause, because they are held in memory as text. If the workflow loops over a dataset, record the total item count from the previous node. The step is done when you have an item count and an approximate size per item for the input to the failing node.
Check whether the failure depends on item count
Determine whether the crash happens on every run or only when the input is large. Compare the item count and payload size of successful executions of the same workflow with the failing one. If successful runs process far fewer items or smaller files, the failure is tied to volume rather than to a logic error. Also check whether the same input fails repeatedly, which points to a deterministic trigger, or whether it fails only intermittently, which can point to concurrent executions competing for memory. The step is done when you can state whether the crash correlates with item count, payload size, or concurrency.
Reproduce the crash with a smaller test input
Run the workflow manually against a copy of the failing input, starting with a subset of items, and increase the count step by step on a non-production instance. Keep the same node configuration so the test isolates the variable you changed. Watch the process memory during each run, using your monitoring tools or the container's resource view, and note the input size at which memory begins to climb sharply. If the crash does not occur at the smaller size and occurs at the larger one, you have a reproducible threshold. This test is illustrative of the method, and the actual threshold depends on your workflow and instance resources. The step is done when you have a repeatable test that either triggers the crash or shows a clear safe limit.
Record the confirmed trigger for the fix
Write down the workflow, node, input size and threshold identified in the previous steps, along with the log excerpt and restart evidence. Confirm whether the trigger is a single large payload, a large item count, a Code node that accumulates data, or concurrent executions sharing one instance. This record decides which fix applies: splitting work into batches or sub-workflows, changing the Code node, or adjusting Node.js heap settings. Share it with the owner of the workflow so the fix is verified against the same reproduction. The step is done when the record names one trigger and one test that proves it.
Which payloads and nodes most often exhaust memory
Most n8n out-of-memory crashes trace back to a small set of patterns: data that is loaded all at once, copies of large item lists, and results that pile up during a run. Each cause shows up differently in the execution log, so identifying which one applies is the first step before changing any settings.
Large JSON responses in one node
An HTTP Request or database node that fetches a large paginated result into a single execution loads every item into memory before the next node starts. The run may show as stuck or fail with a heap error on the node that received the response. Check the item count and the size of the largest response in the failing execution, then ask whether the API supports pagination or filtering so the workflow can request smaller pages.
Binary files held in memory
Files downloaded or generated by a workflow are kept as binary data alongside the JSON items. A few large PDFs, images or exports passed through several nodes can multiply the memory footprint, because each step may hold its own copy. Check the file sizes per item and which nodes read the binary property. Storage mode also affects where those files sit during a run, so confirm the setting your instance uses.
Code node arrays that copy all items
A Code node that maps or filters with $input.all() creates a new array of every item in memory at once, and nested loops over that array can double the cost. Scripts that build large intermediate objects or string concatenations add to the load. Review each Code node for calls to $input.all() on large inputs, and test the script with a representative item count before it runs in production.
Loops that accumulate results
A loop that appends each iteration's output to a growing list keeps every result in memory until the loop finishes. The problem grows with the number of iterations, not just the size of one item, so a workflow that works on a test batch can fail on the full volume. Look for Merge or Aggregate steps placed inside a loop, and check whether the loop can write results out in smaller groups.
Large execution data saved to the database
When a run finishes, n8n stores execution data in the database according to your save settings. Very large payloads saved for many executions increase database size and the work needed to load past runs in the editor, which can pressure memory on the main process. Check which executions save full data and how long they are kept, since these settings determine how much data accumulates over time.
Fixes for batching, sub-workflows and Code node changes
The Loop Over Items node (the node previously labeled Split in Batches) takes a large set of items and passes them through the workflow in smaller groups. Each group completes its downstream nodes before the next group arrives, so the workflow never holds the full item list and all of its intermediate outputs at the same time. This is the most direct fix when a single node receives thousands of items from an API call or database query. The cost is paid in time and in execution activity: every loop iteration runs the nodes inside the loop again, and the loop itself adds latency between batches.
- Memory ceiling: Peak memory follows the batch size rather than the total item count, so a smaller batch size usually lowers the peak at the cost of more iterations.
- Execution count: Iterations run inside one workflow execution, so the number of loop passes affects run time more than the execution count shown in your plan, but confirm how your edition counts them.
- Latency: Each batch waits for the previous one to finish, so total run time grows with the number of batches.
- Upstream data still loads: The source node may still fetch the full dataset before the loop starts, so check whether the source itself is the memory spike.
- Pagination: For APIs that support it, paging at the source is often cheaper than looping over a fully loaded result.
After you add a loop, run the workflow with a realistic input volume and watch memory in your container or process metrics, not only whether the run completes.
The Execute Workflow node calls another workflow and passes it data. When the per-item logic sits in a child workflow, the parent can call it once per batch of items, and the child's intermediate data is released when that call finishes. This keeps large temporary structures out of the parent's execution context. It also makes the child reusable and easier to test on its own. The trade-off is that each sub-workflow call creates its own execution record, which adds to your execution history, database growth and, depending on your plan's counting rules, your usage count. Each call also adds startup overhead and a hop of latency.
- Execution records: Each child run is stored, so pair this pattern with an execution pruning policy before you roll it out widely.
- Batch the calls: Passing 100 items per call usually produces far fewer executions than calling once per item, so choose the unit of work deliberately.
- Data passed in: Everything you send into the sub-workflow is copied into its input, so send only the fields it needs.
- Error handling: Failures inside a child surface in the parent differently, so decide how the parent should react to a failed child call.
- Edition check: Confirm how your n8n edition counts child executions against any usage limits before you rely on this pattern at volume.
Run a test where the parent processes your largest expected input and compare the execution count and memory against the single-workflow version.
Every node in n8n receives the full output of the node before it, including every field of every item. A workflow that fetches large API responses and then passes them through five nodes keeps all of that data in memory at each step, even when the later nodes only use two fields. Trimming what each node outputs is often the cheapest change, because it requires no new execution records and no loop logic. Use the Edit Fields (Set) node, the Remove Item Fields option or an HTTP Request node with a narrower field selection to keep only what the next step needs.
- Early projection: Drop unused fields right after the node that fetches them, not at the end of the workflow.
- Binary files: Remove binary properties once a later node has consumed them, since binary data is often the largest part of an item.
- Filter before enriching: Apply IF or Filter nodes before calls that add data, so fewer items receive the extra fields.
- Source-side selection: Request only the fields you need from APIs and database queries where the source supports field selection.
- Latency: Extra Set nodes add small processing steps, but they rarely add noticeable run time compared with the memory they save.
Check that a field you removed is not referenced later with an expression, because the workflow will fail at that point rather than at the node that removed it.
The Code node runs JavaScript or Python against the full set of input items in one call, so a script that builds arrays, parses large strings or calls JSON.parse on a big response can allocate far more memory than the input size suggests. Rewriting the logic to process fewer items at a time, to avoid holding copies of the same data, or to discard intermediate values early can lower the peak substantially. The trade-off is engineering effort and the need to test edge cases such as empty input, malformed records and very large single items. Keeping the logic in a Code node also means that changes to the script are reviewed alongside the rest of the workflow.
- Process in chunks: Iterate over the input with a loop inside the script or hand chunks to a Loop Over Items node instead of building one large result array.
- Avoid duplicate copies: Map items in place where possible and avoid serializing and parsing the same payload more than once.
- Stream large data: Where the script reads large files, use streaming APIs instead of loading the whole file into a string.
- Release references: Clear large variables before returning, so the garbage collector can reclaim them during later steps.
- Test with large inputs: Measure memory on the largest realistic payload, because small test data will hide the problem.
Before you change a script, confirm the Node.js and Python version your n8n release ships with, and check the Code node documentation for the current limits on each language.
Node.js heap settings and when each fits
This table compares four ways to stop an n8n process running out of memory: raising the Node.js heap limit, raising container memory, reducing data each execution carries, and changing execution data saving. Read each row for when it fits, what it risks, and what to confirm in your n8n version and deployment method before changing anything.
| Option | When it fits | Main risk | Confirm before changing |
|---|---|---|---|
| Node.js heap limit (max-old-space-size via NODE_OPTIONS) | The container has spare memory but the Node.js process hits its heap ceiling during large but bounded runs | Raising the ceiling without more container memory can push the process into an OOM kill by the host instead of a clean heap error | Which Node.js version your n8n release runs on, how NODE_OPTIONS is passed in your Docker or Kubernetes manifest, and the current heap limit |
| Raising container memory limits | The process is healthy at normal load but spikes when a few executions handle large files or responses | Higher memory per pod or container raises hosting cost and can hide a workflow that keeps growing its data | Memory requests and limits on every main, worker and webhook process, and whether the platform restarts pods on memory pressure |
| Reducing data retained per execution | A workflow loads a full API response, a large array or a binary file when it only needs a few fields | Dropping fields too early can break later nodes or expressions that still reference them | Which nodes pass full items forward, and whether downstream expressions use fields you plan to remove |
| Splitting work into sub-workflows and batches | One execution processes thousands of items or files in a single run | More executions to monitor and more connections to the database, and error handling must be designed for each batch | Batch size against your memory test results, and how failed batches are retried and reported |
| Execution data saving settings | Completed runs store large input and output data that fills memory and the database during or after execution | Turning off saving removes the history you need to debug failures and may affect audit expectations | Which executions your team needs to inspect, and the save settings for successful and failed runs in your version |
| Code node restructuring | A Code node builds large arrays or strings in memory, or keeps references between items | Rewriting logic can change results, so each change needs a test against representative data | Code node usage on the failing workflow and whether the logic can read fewer items per run |
How queue mode changes where memory pressure appears
In queue mode, memory pressure can sit on three different processes, so the first step in fixing an out-of-memory error is finding which one crashed. The main instance handles triggers and webhooks and hands executions to a pool of workers through Redis. Workers read and write workflow data in PostgreSQL and run the nodes. Webhook processors, if you deploy them, accept inbound HTTP requests and can take large request bodies before any execution starts. A heap error on a worker usually follows a heavy workflow run, while a crash on the main process or a webhook processor often follows a large incoming payload or a burst of requests. Check which container or process logged the fatal heap message, and match its timestamp to the execution that was running.
Queue mode also changes what a worker holds in memory. Each worker loads the workflow, its inputs and any binary data it processes, and runs those steps within its own Node.js heap. Several workers on one host share that host's memory, so a limit that looks safe for a single worker can fail once concurrency rises. Before you raise heap limits, confirm how many workers and concurrent executions each host runs, and set the memory limit of each container to leave headroom for the others.
Two configuration constraints shape the fix. Workers and webhook processors must share the main instance's encryption key so they can read credentials stored in the database, so a worker you add to relieve memory pressure must be configured with that same key. Multi-main setup, which runs several main instances for high availability, is limited to Enterprise self-hosted deployments and is not available in the Community edition or n8n Cloud, according to the n8n queue mode documentation. If you rely on a single main instance, plan for a restart to be the recovery path when the main process runs out of memory, and confirm your licensing before you design around a second main instance.
Set up a stable configuration and verify it
This sequence turns a diagnosed out-of-memory problem into a tested configuration that handles the largest input you expect without heap errors or lost editor sessions. Each change is measured against the same baseline so you can tell which fix actually worked.
Capture a baseline with a representative input
Before changing anything, run the failing workflow with a test input that reproduces the problem, and record the outcome. Note the input size, the node that fails, the error text (heap out of memory or Connection Lost), the instance's memory limit, and how many executions the instance runs at the same time. Keep the execution ID and the relevant log lines. The step is done when another person can rerun the same input and see the same failure.
Build a staging copy of the instance
Copy the workflows, the database and the encryption key to a staging environment that matches production's n8n version, database and memory limits as closely as possible. Make changes only in the copy until the fix is verified. Confirm that credentials decrypt in staging, since a mismatched encryption key will make tests fail for unrelated reasons. The step is done when the staging copy runs the baseline workflow and reproduces the same error.
Apply batching and sub-workflow changes
Change the workflow so that it processes items in smaller groups, using the Loop Over Items (Split in Batches) node, and moves heavy per-item processing into a sub-workflow that the parent calls with a bounded number of items. Remove or reduce data that is carried forward unnecessarily, such as full binary files or large API responses that later nodes do not need. Keep the change small enough that you can tell which part resolved the failure. The step is done when the workflow saves and the staging run completes on the baseline input or fails at a later, measurable point.
Review Code node logic for large data
Inspect any Code node in the path for steps that hold every item in memory at once, such as building large arrays, parsing whole files into strings or repeatedly cloning objects. Rewrite these to work per item or per batch where the logic allows it, and return only the fields later nodes use. Confirm the result with the same test input. The step is done when the Code node output matches the original for a small sample and the memory behavior no longer grows with the full input.
Adjust Node.js heap settings in staging
If the workflow still fails after the design changes, raise the Node.js heap limit in the staging environment using the documented heap size setting for your deployment method, and confirm the container or host has enough memory for that value. Raise the limit in measured steps rather than to the largest value the host allows, so that the host keeps memory for the operating system and the database. Record the value you chose and why. The step is done when the staging instance starts cleanly with the new setting and the configuration is written down for production.
Rerun the largest expected input
Run the largest input you expect in production through the changed workflow in staging, and watch the process while it runs. Track memory use over time, the execution duration and whether the workflow finishes or fails. If it fails, compare the failure point with the baseline before making another change. The step is done when the largest expected input completes without a heap error and the memory curve levels off instead of climbing until the process exits.
Check logs, restarts and editor stability
Review the n8n and container or service logs for the test window. Look for heap out-of-memory messages, process restarts, Connection Lost messages in the editor, and database connection errors. Open the affected workflow in the editor during and after a large run, and confirm that the canvas loads and saves and that execution history displays. The step is done when the logs show no heap errors or unexpected restarts, and the editor stays connected through the test.
Promote and monitor the production change
Apply the verified workflow and configuration changes to production during a window agreed with the workflow owners, and keep the baseline record with the change. Watch memory and restart events on the first real runs of the workflow, and compare them with the staging results. Ask your team or your partner to confirm which metrics and alerts they will use for this instance, since the exact monitoring setup depends on your environment. The step is done when production runs complete without heap errors and the change record is filed with the staging results.
How data moves through a split workflow
The diagram starts with a large trigger input held in the parent workflow's memory, then shows the Split in Batches step handing one batch at a time to a sub-workflow. Each sub-workflow call returns its result to the parent, which writes it to storage or the database before the next batch starts. Check where the full input and the accumulated results stay in memory, and confirm that each batch's data is released once its results are written.
Parent workflow hands one batch at a time to a sub-workflow and writes each result out.
Security and operational risks of memory changes
Raising memory limits or restructuring workflows fixes a crash but can create new exposure on the host, in stored data and in access control. The cards below cover the checks a self-hosted team should run before and after each memory change.
Raising limits can hide runaway workflows
A higher Node.js heap ceiling lets a workflow that loads too much data keep running until it consumes the host's physical memory, which can also starve other services on the same server. Before raising the limit, find the workflow that caused the growth and confirm which execution triggered it. Set an alert on resident memory of the n8n process, and check that the host has headroom for the operating system, the database and any other containers.
Payloads can hold personal or health data
Large JSON responses and binary files often contain customer records, patient details or identifiers that were never meant to be stored. When execution data is saved, those payloads can persist in the n8n database for as long as your retention settings allow. Before you split or batch a workflow, list the fields each node passes forward, decide which ones to drop with Set or Code nodes, and confirm that your retention policy covers the remaining data.
Sub-workflow changes shift credential access
Moving logic into a sub-workflow changes which credentials and permissions run that logic, because the called workflow executes under its own nodes and credential references. A split that looks like a refactor can give a workflow access to a system it did not previously reach, or break a call that depended on a shared credential. Review each new sub-workflow's credential usage and project placement, and test it with the same role and permission set that production uses.
Limit changes need an audit trail
Memory settings live in environment variables, container definitions and sometimes in orchestration manifests, and a change to one of them can be made without a record. Keep the previous and new values in version control, record who approved the change and when it took effect, and tie each change to the workflow that prompted it. This makes it possible to roll back a setting when a later failure appears to be unrelated.
Track restarts and memory over time
A single crash tells you little, while a pattern of restarts and rising memory between them points to a leak or a growing backlog. Record container restart counts, the memory use of the n8n process and the size of the execution database over days, not minutes. Compare these trends after each change so you can tell whether the fix held or whether the crashes have moved to a different workflow.
Questions teams ask before fixing n8n memory problems
Does a bigger server alone fix n8n out-of-memory errors?
Sometimes it buys time, but it rarely fixes the cause. A larger host raises the ceiling only if the Node.js heap limit is also raised, and a single execution that loads a very large JSON or binary payload can still exhaust memory on any size of machine. The durable fix usually comes from reducing how much data one execution holds at once: splitting work into sub-workflows, processing items in batches, trimming fields early and checking what Code nodes keep in memory. Before buying hardware, confirm which execution failed, the payload size it handled and whether the crash repeats with the same input.
What does a fix cost and what drives the effort?
Cost depends on how many workflows are affected, how complex their data handling is and how much of the work your own team keeps. The main drivers are the number of failing workflows, whether the payloads are JSON, binary files or both, how many Code nodes hold large in-memory arrays, and whether the instance runs in single-process mode or queue mode with workers. Ask any provider for a written quote that lists the workflows in scope, the environments to change, the test runs needed to prove a fix and the retest after changes. Ask whether any cost recurs, such as monitoring or an upgrade retainer, and what is one-time.
How long does a typical diagnosis and fix take?
No single duration applies, because it depends on the number of workflows, the size of the payloads and how quickly the team can reproduce the failure with real or representative data. Diagnosis usually takes longer than the change itself, since it requires matching a crash to a specific execution and payload. A fixed-scope engagement should state its timeline in writing before work starts, along with the points where the client must review results. If you need a planning figure, ask the provider to base it on your workflow count and a sample of failing executions, not on a general estimate.
What should our team provide before the work starts?
The most useful inputs are the workflow exports, the n8n version in use, the hosting details and the logs from the failed runs. Sample payloads matter most, ideally anonymized copies of the data that triggered the crash, with their approximate size and file types. Also provide the Node.js heap settings currently in place, the container or virtual machine memory limits, the database type and the execution data retention settings. Confirm with your security team how sample data can be shared, since payloads often contain personal or regulated data that should be masked or replaced with synthetic records.
Can an in-house engineer fix n8n memory errors without outside help?
Often yes, if the engineer has Node.js and container experience and can reproduce a failing execution. The work involves reading execution logs, measuring memory use per run, reviewing workflows for large item lists and tuning settings such as the heap size. It becomes harder when many workflows share one instance, when the failures appear only under production load or when the same Code node patterns appear across teams. Ask whether your team has time to change workflows and test them with real volumes, because the redesign often takes longer than the diagnosis.
Why does Connection Lost appear alongside memory crashes?
A Connection Lost message in the editor often means the n8n process stopped or restarted, which can happen after the Node.js process runs out of heap. It may also appear when a reverse proxy times out while the server is busy with a large execution. Check the container logs for heap errors or restarts before changing timeouts, because raising a proxy timeout will not solve a process that is being killed. Confirm whether the restart happened in the same minute as the failing execution, and whether the instance runs in queue mode, where workers and the main process can fail separately.
Does a fix change how workflows behave or what they produce?
It can, so changes should be tested against the original outputs before they reach production. Splitting a workflow into sub-workflows or batches changes execution counts and the order in which items are processed, and it may affect how errors are reported. Removing fields early can break downstream nodes that expect them. Ask the provider to document each changed workflow, compare outputs for the same input before and after the change and agree on a rollback plan. Note that n8n counts an execution as one run of a whole workflow regardless of the number of steps, which matters when you plan changes that alter run counts.
Does the fix depend on our n8n plan or license?
The core memory fixes, including batching, sub-workflows and heap settings, work on the self-hosted Community edition, which n8n lists as free to self-host. Features such as SSO, environments with Git and log streaming are included only in the Business and Enterprise plans, so they are not part of a standard memory fix. Confirm your current edition and the license terms of the Sustainable Use License before sharing modified or embedded workflows externally, since that license limits use to internal business purposes and non-commercial use.
How DeployOpen works on this
DeployOpen starts by reading how your n8n instance fails: which workflows load large JSON or binary payloads, where Code nodes hold data, and how the process is started. We then agree a fixed scope in writing and change only what the evidence supports, with each step documented so your team can review it.
How we scope
- Review the crash logs, container limits and Node.js heap settings currently in use on your instance.
- Identify the workflows that process the largest payloads and the Code nodes that hold data in memory.
- Agree in writing which workflows, settings and deliverables are covered before any change starts.
How we build
- Split large workflows into sub-workflows and batches, and reduce the data each node holds at once.
- Adjust Node.js heap settings and container memory limits, tested against your own workflow runs.
- Test fixes with representative payloads, including the binary files your workflows actually process.
How we hand over
- Document each workflow change, heap setting and limit, with the reason it was made.
- Provide a retest record showing the failing runs before and after the fixes were applied.
- Walk your platform and operations team through the runbook so they can repeat the checks.
How we support
- Support after handover is available as a retainer, covering upgrades and recurring checks.
- Confirm with DeployOpen which upgrade and monitoring items your retainer includes before you sign.
- Ask for the retainer scope and response expectations in writing alongside the fixed-scope quote.

