Understanding n8nβs Execution Model
n8n processes data in chunks rather than loading everything into memory. Understanding streaming, webhooks, and long-running operations is crucial for building production-grade nodes that handle real-world data volumes.
- Batch Processing: Default mode where all data is loaded and processed
- Streaming Mode: Process data item by item without loading everything
- Webhook Triggers: Real-time event-driven execution
- Long-Running Operations: Asynchronous tasks that donβt block the workflow
Building Streaming Nodes
Why Streaming Matters
Without streaming, a node processing 1GB of CSV data would load everything into memory, potentially crashing your n8n instance. Streaming processes data incrementally, keeping memory usage constant.
- Processing large files (CSV, JSON, XML)
- Handling database exports with millions of rows
- Working with API responses that paginate through results
- Building ETL pipelines for data warehouses
Implementing a Streaming CSV Processor
Hereβs a production-ready streaming node that processes CSV files of any size:Memory Management in Streaming
Webhook Nodes Development
Creating a Webhook Trigger Node
Webhook nodes enable real-time event processing. Theyβre perfect for integrations with services that send instant notifications like payment processors, form submissions, or IoT devices.
Advanced Webhook Patterns
Rate Limiting and Throttling
Long-Running Operations
Implementing Async Processing
Long-running operations like file uploads, video processing, or complex calculations should be handled asynchronously to prevent workflow timeouts.
Queue-Based Processing
Real-World Implementation Examples
Building a Video Processing Pipeline
Real-Time Data Synchronization
Best Practices
Memory Management Checklist
Memory Optimization Strategies
Memory Optimization Strategies
-
Use Streaming for Large Data
- Process files > 10MB with streams
- Implement pagination for API responses
- Use cursor-based iteration for databases
-
Implement Backpressure
- Monitor memory usage during processing
- Pause streams when buffers are full
- Resume when memory is available
-
Clean Up Resources
- Close file handles after use
- Terminate database connections
- Clear intervals and timeouts
-
Monitor and Alert
- Track heap usage
- Set memory limits
- Log warnings before OOM
Error Handling in Async Operations
Performance Benchmarks
Streaming vs Batch Processing
Scenario | Batch Processing | Streaming | Improvement |
---|---|---|---|
100MB CSV | 2GB RAM, 45s | 50MB RAM, 40s | 40x memory reduction |
1M API records | 8GB RAM, 5min | 200MB RAM, 4min | 40x memory reduction |
Video processing | OOM at 500MB | 100MB constant | Handles any size |
Next Steps
Now that you understand streaming and async operations, learn about dynamic credentials and module loading:Dynamic Credentials & NPM Modules
Build nodes with dynamic authentication and runtime module loading