Joshua Opolko

n8n Self-Hosted Setup Guide (2026): Docker, AI Agents, and Scaling

A machine of glowing teal conduits and amber brass nodes carrying capsules of data, representing an n8n automation workflow

n8n is the workflow automation tool developers reach for when Zapier gets expensive and Make feels like a black box. It is fair-code, self-hostable, connects to 400-plus services, and since the LangChain-powered AI nodes landed it doubles as an AI agent builder. The Community Edition is free to self-host under the Sustainable Use License, with no execution limits, and the current release is 2.25.7 (June 10, 2026). A single Docker container gets you running in minutes. The work, as always, is production: queue mode for scale, surviving upgrades without breaking webhooks, and backing up the right things. This guide covers the install, an AI agent workflow, and the problems people actually hit, plus how n8n stacks up against Make and Zapier.

Key takeaways

Install n8n with Docker (quick start)

The fastest way to try n8n is a single container. Set an encryption key up front so the credentials you create are portable, and mount a volume so nothing is lost on restart.

# Create a persistent volume and run n8n
docker volume create n8n_data

docker run -d --name n8n -p 5678:5678 \
  -e N8N_ENCRYPTION_KEY="replace-with-a-long-random-string" \
  -e GENERIC_TIMEZONE="America/Toronto" \
  -v n8n_data:/home/node/.n8n \
  docker.n8n.io/n8nio/n8n:2.25.7

# Open the editor
# http://localhost:5678

Note the pinned tag :2.25.7 rather than :latest. That single choice prevents a surprise upgrade from breaking live workflows, which is the most common self-hosting regret.

Production install with Docker Compose

For real use, run n8n against Postgres rather than the bundled SQLite, which struggles under concurrent executions. This Compose file wires n8n to Postgres; add Redis and workers when you reach the scaling section.

# docker-compose.yml
services:
  postgres:
    image: postgres:16
    restart: always
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: change-me
      POSTGRES_DB: n8n
    volumes: ["pg_data:/var/lib/postgresql/data"]

  n8n:
    image: docker.n8n.io/n8nio/n8n:2.25.7
    restart: always
    ports: ["5678:5678"]
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: change-me
      N8N_ENCRYPTION_KEY: replace-with-a-long-random-string
      WEBHOOK_URL: https://n8n.example.com/
    volumes: ["n8n_data:/home/node/.n8n"]
    depends_on: ["postgres"]

volumes: { pg_data: {}, n8n_data: {} }

Build an AI agent workflow

n8n's AI features are built on LangChain. The AI Agent node is a root, or cluster, node: on its own it does nothing, but you attach sub-nodes to give it a brain and hands. Connect a Chat Model sub-node (OpenAI, Anthropic, or a local model), an optional Memory sub-node to carry context across turns, and one or more Tool sub-nodes the agent can call. Trigger the workflow from a webhook, a schedule, or a chat trigger, and the agent reasons over its tools to complete the task. For a fully private, no-API-cost setup, point the Chat Model at a local model served by Ollama, and if you outgrow single-agent workflows, compare the dedicated frameworks in my CrewAI guide.

1. Webhooks break after an upgrade

What you see: a workflow that worked yesterday stops firing after you pulled a new image, or webhook URLs return 404.

What it is: running :latest means an automatic, untested version jump. n8n moves fast, and breaking changes occasionally land that affect webhook registration or node behavior.

The fix: pin a specific version tag in your Compose file and upgrade on purpose. Read the release notes, bump the tag in staging, confirm your critical workflows still fire, then promote. Keep the previous tag handy so a rollback is one edit away.

2. Executions pile up and the instance is slow

What you see: workflows queue behind each other, the editor feels sluggish, and a busy webhook drops events under load.

What it is: by default n8n runs in "main" mode, executing everything in one process. That is fine for light use but does not parallelize.

The fix: switch to queue mode. Set EXECUTIONS_MODE=queue, add a Redis service as the message broker, and run one or more dedicated worker containers that pull jobs from the queue. The main instance handles the UI and webhooks while workers execute in parallel. A common trigger to make the move is sustained CPU around 80%. Scale by adding workers, and reach for an external broker like RabbitMQ only if you need more resilience than Redis provides.

3. You lost your workflows or credentials

What you see: after a container rebuild, workflows are gone, or restored credentials fail to decrypt.

What it is: two separate mistakes. Either the data volume was not persisted, or the N8N_ENCRYPTION_KEY changed, which makes every stored credential undecryptable.

The fix: persist the /home/node/.n8n volume, use Postgres and back up the database on a schedule, and store the N8N_ENCRYPTION_KEY somewhere safe and never let it change between deployments. Treat the key like a production secret, because losing it means re-entering every credential by hand.

4. Webhooks do not work behind a reverse proxy

What you see: webhooks work locally but external services cannot reach them, or the URLs n8n generates point at localhost.

What it is: n8n needs to know its public URL to register webhooks correctly.

The fix: set WEBHOOK_URL (and N8N_HOST) to your public HTTPS domain, terminate TLS at a reverse proxy such as Caddy or Nginx, and forward to port 5678. After changing these, re-save the affected workflows so the webhook URLs regenerate.

5. Self-hosting is not actually free

What you see: you moved off Zapier to save money, then spent weekends on Docker, SSL, backups, monitoring, and queue tuning.

What it is: the license is free; the operations are not. Hosting, patching, monitoring uptime, and tuning queue mode are real engineering time.

The fix: be honest about the trade. Self-hosting pays off when your task volume is high enough that per-task billing would dwarf the ops cost, or when data residency matters. For low volume, a managed plan can be cheaper once you price your own time. Right-size the decision rather than defaulting to self-host on principle.

6. The database fills up with execution data

What you see: over weeks of running, the database grows steadily, backups get slower, and disk usage creeps toward full on a busy instance.

What it is: by default n8n stores the full execution history, including the data that passed through every node. High-frequency workflows accumulate this fast, and nothing prunes it automatically unless you ask.

The fix: turn on execution pruning so old runs are cleared on a schedule. Set EXECUTIONS_DATA_PRUNE=true and a retention window with EXECUTIONS_DATA_MAX_AGE (in hours), and optionally cap the row count. For noisy workflows you do not need to audit, set them to save only on error rather than on success, which keeps the table lean.

# Environment for the n8n service
EXECUTIONS_DATA_PRUNE=true
EXECUTIONS_DATA_MAX_AGE=336        # keep 14 days of execution history (hours)
EXECUTIONS_DATA_PRUNE_MAX_COUNT=10000

Secure a self-hosted n8n instance

An n8n instance holds credentials to everything it automates, so treat it like production infrastructure, not a hobby container. A few essentials cover most of the risk:

Back up the right things

A working backup of n8n is three parts, and missing any one of them makes a restore fail. Back up the database (a scheduled pg_dump if you are on Postgres), the /home/node/.n8n volume, and most importantly the N8N_ENCRYPTION_KEY, stored separately in your secrets manager. The encryption key is the part people forget: without it, a restored database cannot decrypt any of your stored credentials, so you would have to re-enter every API key and connection by hand. Test a restore into a throwaway instance occasionally, because a backup you have never restored is a hope, not a plan.

n8n vs Make vs Zapier (2026)

All three automate workflows, but they bill and scale very differently, and only n8n is self-hostable.

ToolHostingCost modelAI agentsBest for
n8nSelf-hosted or cloudFlat (self-host) or per-executionNative LangChain AI Agent nodesHigh volume, data control, AI workflows, 400+ integrations
MakeManaged cloud onlyPer-operationSome AI modulesVisual builders who want zero ops
ZapierManaged cloud onlyPer-task (expensive at scale)AI actions and agentsSimple, broad app coverage, non-technical users

The pattern: Make and Zapier scale your bill linearly with usage, while self-hosted n8n scales vertically. More tasks mean a bigger server, not a bigger invoice. For data-heavy or high-frequency automation, that difference compounds fast.

Frequently asked questions

Is n8n free?

The n8n Community Edition is free to self-host under the Sustainable Use License, with no execution limits. Paid plans cover n8n Cloud (managed hosting) and the Enterprise edition (SSO, advanced permissions, scaling features). For most self-hosters the Community Edition is enough.

n8n vs Zapier: which is cheaper?

At low volume, Zapier's managed convenience can be cheaper once you price your own time. At high volume, self-hosted n8n is dramatically cheaper because it is flat-rate, while Zapier bills per task. The crossover comes when per-task fees exceed the cost of running and maintaining a server.

How do I scale n8n?

Scale vertically first by giving the instance more CPU and RAM. When you approach roughly 80% CPU, switch to queue mode: set EXECUTIONS_MODE=queue, add Redis as the broker, and run dedicated worker containers that execute jobs in parallel. Add workers to scale out further.

Why did my webhooks stop working after an upgrade?

You were likely running the :latest tag and an automatic version jump introduced a breaking change. Pin a specific version, read release notes before upgrading, test in staging, and keep the previous tag ready for rollback.

Can n8n run local LLMs?

Yes. Attach a Chat Model sub-node pointed at a local model served by Ollama to the AI Agent node. This gives you fully private, no-per-token-cost AI workflows. See the Ollama setup guide for running the model locally.


Resources

Last updated: June 13, 2026.

Josh writes about AI agents, automation, and GEO, and runs nowservingto.com, a daily-fresh directory of Toronto's newest restaurants.