A single task is a chore; a thousand identical tasks is a system. Arrays and loops are the fundamental programming concepts that allow you to handle data at scale without writing redundant logic.
1Understanding Arrays
An Array is essentially a list. Instead of a variable holding one single value (like name = 'Alex'), an array holds a collection of values. In automation, when you fetch rows from a Google Sheet or contacts from a CRM, the data comes back as an array of structured JSON objects.
In n8n, this is the fundamental data model: every node produces an array of Items. Even if a trigger fires for just one record, it wraps that record in a single-element array. Once you internalize this, you'll stop being confused about why nodes behave differently on single vs. multiple inputs.
Arrays are zero-indexed, meaning the first element is at index 0. Accessing items[0] gives you the first item. This is one of the most common off-by-one bugs that trips up beginners — they try items[1] and wonder why they're missing the first record.
// Array of CRM contacts from Google Sheets
const contacts = [
{ id: 1, name: 'Alex', email: 'alex@co.com' },
{ id: 2, name: 'Sam', email: 'sam@co.com' },
{ id: 3, name: 'Jo', email: 'jo@co.com' }
];
// Access first item
console.log(contacts[0].name); // 'Alex'2The Power of Loops
A Loop repeats a set of instructions for every item in an array. The most common is the forEach pattern: take each item, run it through your logic, repeat until the array is exhausted. In n8n, most nodes do this automatically — if you connect a 'Send Email' node to a 50-item array, it sends 50 emails without you writing a single loop manually.
But sometimes you need explicit control. When you have complex conditional logic that changes *how* each item should be processed, or when you need to aggregate results before moving on, you reach for manual iteration constructs like n8n's SplitInBatches node or JavaScript's for...of loop inside a Code node.
The real skill is knowing when to let the platform loop for you and when to take over. Trusting automatic iteration for simple cases and writing explicit loops for complex cases keeps your workflows both lean and powerful.
// Explicit loop in n8n Code node
const items = $input.all();
const results = [];
for (const item of items) {
const processed = {
json: {
email: item.json.email,
greeting: `Hello, ${item.json.name}!`
}
};
results.push(processed);
}
return results;3Batching at Scale
When your array grows to thousands of items, you run into rate limits — the external API refuses to accept more than N requests per minute. The solution is batching: split your large array into smaller chunks and process one chunk at a time, with a deliberate pause between chunks.
In n8n, the Split In Batches node is your go-to. You set a batch size (e.g., 10), and it feeds items through in groups of 10, looping back until all items are done. Pair it with a Wait node (e.g., 1 second delay) between iterations and you've built a polite, rate-limit-safe processing pipeline.
The danger to watch for is the infinite loop bug: if your loop's exit condition is never triggered, the workflow runs forever until the server runs out of memory. Always verify your loop has a guaranteed termination path.
// n8n workflow structure
[Google Sheets: Get All Rows]
→ [Split In Batches: size=10]
→ [HTTP Request: Update CRM]
→ [Wait: 1 second]
→ [back to Split In Batches]
// 1,000 rows = 100 batches
// Total time ~100 seconds4Step-by-Step Breakdown
Arrays and Loops. Automation at scale requires significantly more architecture than just processing one single item at a time. In this comprehensive lesson, we will deeply explore and master the fundamental logic of massive volume: Arrays and Loops, which enable you to bridge the gap between simple tasks and enterprise-grade infrastructure.
The Item List. An array is a powerful collection of identical or related data items grouped together in a sequence. In automation platforms like n8n, almost every single node inherently produces an array of items, even if that array only contains one single entry. Understanding this 'Item List' structure is completely critical to success.
Automatic Iteration. A 'Loop' allows you to systematically perform the exact same action on every single item housed within your array. While modern platforms like n8n actually perform this iteration automatically for most standard nodes, sometimes you must take over and exert explicit manual control to handle complex logic requirements.
Checkpoint: If you pass an array of 50 items into a 'Slack Send' node, how many messages will be sent by default?
- →1 (The entire list as one message)
- →50 (One message per item)
Batch Logic. For truly massive datasets containing thousands of individual records, we implement 'Batching'. This logic smartly splits a giant array into smaller, manageable chunks—for example, processing 10 items at a time—to entirely avoid hitting API rate limits or inadvertently crashing the automation server during high-volume operations.
Scale Orchestration. The 'Split In Batches' node in n8n serves as your absolute primary tool for enterprise scale. It effectively creates a durable loop that continuously runs over and over again until every single item in your original source array has been fully and successfully processed, ensuring robust data integrity.
Checkpoint: What is the main benefit of 'Batching' when using external APIs?
- →It makes the automation run faster
- →It prevents 'Too Many Requests' errors by controlling the pace of execution
High Performance. By thoroughly mastering these advanced looping structures, you can confidently process tens of thousands of records—flawlessly syncing databases, sending massive amounts of personalized emails, or auditing extremely large content libraries without any fear of system failure or data loss.
Throttling Strategy. Pro-tip: Strategically use a 'Wait' node directly inside of a looping structure to add a highly specific delay between batches. This crucial pause provides the external API ample time to 'breathe', fully guaranteeing you will never trigger a service ban or encounter strict rate limitations while running long-lived automations.
Checkpoint: True or False: In n8n, a workflow will automatically stop looping when the 'Split In Batches' node has no items left to process.
- →True
- →False
Scalable Status. Loop logic fully mastered! You are now fully trained and entirely ready to securely automate complex tasks at true, uninterrupted, and reliable enterprise scale. Your foundation is solid and prepared for any volume of traffic.
GSheets Next. Next, we will shift our focus and learn exactly how to utilize Google Sheets as an incredibly powerful, low-code database to directly feed and power these complex automation loops.
Conclusion. Mastering loops and structured batches guarantees that your highly complex automations will absolutely never break or crash under exceptionally heavy server loads. You are officially prepared to tackle any integration challenge.
Filter Real Lead Data. Finish filtering a list of leads down to just the high-scoring ones.
Level Up 🚀
Advanced cheat sheets, SEO tricks, and interview prep for this topic.
Browser Support
Fully supported.
Fully supported.
Fully supported.
Fully supported.
Accessibility (A11y)
1Surface Batch Progress to Users Watching a Long-Running Workflow
When a workflow processes thousands of items in batches, any dashboard showing its status should announce progress updates via an aria-live region (e.g. 'Batch 42 of 100 complete'), not just a silently updating progress bar, so screen reader users tracking a long automation run aren't left without feedback.
<div aria-live="polite">Batch {current} of {total} complete</div>SEO Implications
- 1
Rank for 'n8n Rate Limit' and 'Batch Processing' Search Terms
Developers hitting API rate limits in production search for exactly this problem — content that explicitly covers Split In Batches, Wait nodes, and rate-limit-safe patterns captures that troubleshooting-stage search traffic better than generic array/loop terminology alone.
Best Practices
Always Verify a Loop Has a Guaranteed Termination Path Before Deploying
An infinite loop in a workflow doesn't just hang — it can consume server memory until the process crashes. Before shipping any Split In Batches or manual loop construct, trace through the exit condition explicitly rather than assuming it will naturally terminate.
Batch Size Should Be Tuned to the External API's Actual Rate Limit, Not Guessed
Check the target API's documented rate limit (requests per minute/second) and size batches plus Wait delays to stay comfortably under it, rather than picking a round number like 10 and hoping it works.
Frequent Bugs
Accessing items[1] expecting the first record, forgetting that arrays are zero-indexed, and silently skipping the actual first item in every run.
Remember items[0] is always the first element. When debugging 'missing first record' issues in a workflow, check for off-by-one indexing errors before assuming the data source itself dropped a row.
Real-World Examples
Bulk CRM Update Without Hitting Rate Limits
A workflow pulling 5,000 rows from Google Sheets and pushing each one to a CRM's HTTP API uses Split In Batches (size 20) paired with a 1-second Wait node between batches — processing the full dataset in about 4 minutes without ever triggering the CRM's 429 Too Many Requests response.
[Split In Batches: size=20] → [HTTP Request: Update CRM] → [Wait: 1s] → loop back