n8n
Fair-code workflow automation: visual glue, with a Code node escape hatch.
Overview
n8n is a fair-code workflow automation platform, source-available but not OSI open source, founded in 2019 with 400+ integrations. The core abstraction is a directed graph of nodes: a trigger node starts the run, then data flows node to node as an array of JSON items, each node receiving the items and returning a transformed array. The visual canvas covers the common cases; the Code node is the escape hatch for the rest.
On the agentic side, n8n ships 70+ nodes built on LangChain. The AI Agent node (Tools Agent) implements LangChain tool-calling, and AI nodes connect through typed sub-connections: language model, memory, tool, retriever, embedding. You can stand up an agent with tools, memory and a vector store visually in minutes. That speed is exactly its place in the landscape: glue and fast prototyping, not the deep orchestration core.
Two things shape the economics. Pricing is execution-based: one full workflow run counts as one execution regardless of the number of steps, unlike tools that bill per task. Scaling is operational: main mode runs everything in a single process, while queue mode adds a Redis broker and a worker pool you scale horizontally (Postgres required). Self-hosting is free under the Sustainable Use License; files marked .ee. require an Enterprise License.
Architecture
Two mental models cover most of what matters. A workflow is a node graph: a trigger emits items, each node transforms the items array, branches (IF/Switch) split the flow and Merge recombines it, with the Code node as the escape hatch when no node fits. Scaling is orthogonal to the graph: main mode runs everything in one process, queue mode offloads each execution to a Redis-brokered worker pool that scales horizontally.
Key concepts
- Node
- A single step in a workflow. Receives the incoming array of items, performs one action (HTTP call, transform, condition), and returns an array of items. Nodes connect through the main data connection.
- Item
- The unit of data passed between nodes, a JSON object wrapped as { json: {...} }. A node runs once over the whole items array (or once per item), and most data bugs come from forgetting that webhook payloads sit under .body.
- Trigger node
- The entry point that starts a run: webhook, schedule (cron), or an app event. In queue mode the trigger lives on the main instance, which generates the execution without running it.
- Code node
- The escape hatch: JavaScript or Python run inside the workflow. Access data via $input.all() / $input.first(), return [{ json: {...} }]. Use it for logic no node expresses; when it grows into tested business logic, that is a graduation signal.
- AI Agent node
- A LangChain-based node where an LLM picks and calls tools to reach a goal. The Tools Agent implements LangChain tool-calling; model, memory, tools and retriever attach as typed sub-connections rather than main data connections.
- Queue mode
- The scaling mode: the main instance pushes execution IDs to Redis, a pool of worker instances picks them up, runs them and writes results to the database. Scale by adding workers. Postgres is required; SQLite is not supported.
When to use
Good fit
- Internal automation gluing SaaS and APIs together: a webhook in, a few transforms, a write to a CRM or a database out.
- Webhook-driven and scheduled jobs where a visual flow is faster to ship and to hand over than a deployed service.
- Rapid prototyping of an AI agent (tools, memory, a vector store) to validate the shape before committing it to code.
- Human-in-the-loop steps: an approval or wait node that pauses the run until someone validates, without building a UI.
- Teams that want a visual canvas but can drop into the Code node for the small share of logic no node expresses.
Anti-patterns
- Stateful multi-agent cycles needing fine control and durable checkpointing: graduate to LangGraph, where state and resumption are first-class.
- Business logic that must be unit-tested, peer-reviewed and version-controlled: a node graph is a poor home for it, move it to code.
- Tight latency SLAs or high throughput where the operational cost of queue mode exceeds the cost of writing the service yourself.
- A workflow that has sprawled past fifty to eighty nodes and is no longer readable: the sprawl itself is the graduation signal.
Code examples
Code node: normalize lead items
// Code node, mode "Run Once for All Items"
const items = $input.all();
return items.map((item) => ({
json: {
email: item.json.email?.toLowerCase() ?? null,
domain: item.json.email?.split('@')[1] ?? null,
createdAt: DateTime.now().toISO(),
},
}));The contract: read with $input.all(), return an array of { json } objects. This is the glue case n8n is built for, a transform between a webhook and a CRM.
Code node: call an API, guard failures
// Code node: drop to code when no node fits
try {
const scored = await $helpers.httpRequest({
method: 'POST',
url: 'https://api.internal/score',
body: { items: $input.all().map((i) => i.json) },
json: true,
});
return [{ json: { ok: true, scored } }];
} catch (error) {
return [{ json: { ok: false, error: error.message } }];
}Fine while it stays glue. The day this node carries real, tested business logic with branching error policies, that is the signal to move it out into a versioned service or a LangGraph graph.
Comparison
vs LangGraph
Visual glue vs code-first state
n8n wins on integration breadth and time-to-first-run; LangGraph wins on cycles, precise state machines and durable checkpointing. Prototype the agent in n8n, graduate to LangGraph when the orchestration needs real state.
vs Make / Zapier
Pricing and control
n8n bills per execution (one full run, any number of steps) where Make and Zapier bill per task or step. It is self-hostable and source-available, with a Code node escape hatch the closed SaaS tools do not offer.
vs Hand-written code
Speed vs control
n8n trades fine control for visibility and speed. Keep it while the logic is glue and stays readable; move out the day it becomes a tested product surface with reproducibility and review needs.
Resources
FAQ
- Is n8n open source?
- Not in the OSI sense. n8n is fair-code: the source is available and self-hosting is free under the Sustainable Use License, but commercial use is restricted and files marked .ee. require an Enterprise License.
- Can n8n build real AI agents?
- Yes. It ships 70+ LangChain-based nodes, including an AI Agent node whose Tools Agent implements LangChain tool-calling. Model, memory, tools and retriever attach as typed sub-connections, so an agent with tools and memory is a few nodes away.
- How does n8n scale?
- Through queue mode: the main instance pushes execution IDs to Redis and a pool of worker instances runs them, writing results to Postgres. You scale horizontally by adding workers. SQLite is not supported in this mode.
- n8n or LangGraph?
- Use n8n for integration glue and to prototype agents fast. Graduate to LangGraph when you need cycles, precise state machines or durable checkpointing. The two are a sequence, not a rivalry: n8n first, code when the orchestration earns it.
- How is n8n priced?
- Cloud pricing is execution-based: one full workflow run is one execution, regardless of how many steps it has, which is cheaper than per-task tools for multi-step flows. Self-hosting is free under the Sustainable Use License.