सामग्री पर जाएँ

लेसन 21 · Hosting and Security

Self-hosting and Scaling n8n

Plan a self-hosted n8n deployment with Docker Compose, a database, HTTPS and webhook URLs, then understand queue mode, workers, Redis and capacity planning.

Self-hosting gives you control, and it makes you the operator. This lesson shows the parts of a solid deployment and how n8n scales. Treat the snippets as starting points and compare them with the current official documentation for your version.

The pieces

A production setup

n8n containers Pinned version
PostgreSQL Stores your data
Reverse proxy HTTPS
Backups Database and key
1 / 2

SQLite works for trials. For production, PostgreSQL is the recommended choice. Since 2.0, MySQL and MariaDB are no longer supported as n8n's own database (the MySQL node still works).

A Compose sketch

YAML
# Read-only sketch: add your own secrets, versions, health checks and proxy
services:
  postgres:
    image: postgres:17
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: n8n
    volumes: [db_data:/var/lib/postgresql/data]

  n8n:
    image: n8nio/n8n:${N8N_VERSION}   # pin an exact version
    ports: ["127.0.0.1:5678:5678"]    # only the local proxy reaches it
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: ${DB_PASSWORD}
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
      N8N_WEBHOOK_URL: https://n8n.example.com/
      N8N_PROXY_HOPS: 1
      GENERIC_TIMEZONE: Etc/UTC
    volumes: [n8n_data:/home/node/.n8n]
    depends_on: [postgres]

volumes:
  db_data:
  n8n_data:

Keep secret values in an environment file or secrets manager that never goes into version control. In 3.0, configuration and storage paths changed in places, so read the breaking-changes page and run the Migration Report before upgrading an existing server.

HTTPS and the reverse proxy

Put a reverse proxy in front to handle TLS. Because n8n cannot guess its public address behind a proxy, set the webhook URL variable (N8N_WEBHOOK_URL in recent versions; older ones use WEBHOOK_URL) and N8N_PROXY_HOPS to the number of proxies. Configure the proxy to pass the forwarded headers.

Queue mode

By default one process handles the editor, triggers and executions. In queue mode, the main instance hands executions to workers through Redis.

flowchart LR
  W["Webhooks and schedules"] --> M["Main instance"]
  M --> R["Redis queue"]
  R --> K1["Worker 1"]
  R --> K2["Worker 2"]
  K1 --> DB["PostgreSQL"]
  K2 --> DB

Redis hands jobs to workers, and everyone shares one database.

Key points from the documentation:

Terminal
# Every main and worker process
EXECUTIONS_MODE=queue
QUEUE_BULL_REDIS_HOST=redis
N8N_ENCRYPTION_KEY=<same value everywhere>

# Start a worker with its concurrency (default is 10)
n8n worker --concurrency=5

All processes share the database and Redis, and workers must use the same encryption key as the main instance. Optional webhook processors handle high volumes of incoming requests behind a load balancer. Running several main instances for high availability is an Enterprise feature. Binary data storage needs extra thought when several machines share work.

Capacity thinking

More workers help only if the database, Redis and external APIs can keep up. This stand-in estimates throughput with made-up numbers.

Python Stand-in: rough capacity estimate

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real load is bursty, so leave headroom. Long waiting jobs, large files and slow APIs change the picture.

Operations checklist

  • Pin versions; test upgrades on a copy first.
  • Back up the database and the encryption key, and practice restoring.
  • Monitor disk space, since execution data grows; set pruning.
  • Check health endpoints and set alerts.
  • Document who owns the server.
JS Stand-in: check an environment file before deploy

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Before you go live

Walk through a rehearsal on a spare machine. Start the stack from your Compose file with fresh volumes, create a user, add a harmless credential and publish a small scheduled workflow. Then check each of these points. Does the webhook address shown in the editor use your public domain and HTTPS? Does the schedule fire at the time you expect in your chosen zone? Does an automatic failure reach your error workflow?

Next, practice a disaster. Take a database backup and note where the encryption key is kept. Destroy the test stack, restore both on a clean machine and use the credential. If n8n cannot decrypt it, you have found the problem while it was still harmless.

When to scale

Do not add queue mode only because it exists. A single instance is simpler to run and to debug, and it can suit a small team. Consider queue mode when long executions get in each other's way, when incoming webhooks arrive in large bursts, or when you need more capacity than one process gives you. Before you add workers, find the real bottleneck. If a third-party API limits you to a few requests per second, more workers will only hit that limit sooner and produce more failed runs. If the database is slow, review how much execution data you save and how long you keep it. Watch queue length, execution duration, memory use and error rate, and change one thing at a time. Keep every process on the same n8n version, and include workers in your upgrade rehearsal, so you never discover a mismatch in production.

Practice

Draw your planned deployment on one page: the containers, the database, the proxy, where the encryption key is kept, where backups go and who receives alerts. For each box, write what happens if it fails and how you would notice. If the whole server disappeared, how long would recovery take, and how much data could you lose? Compare the answer with what the business needs. If the gap is large, improve backup frequency or consider the hosted option. A simple setup that you can restore is better than a complex one that you cannot.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What does queue mode use to pass jobs to workers?

    Redis holds the job queue.
  2. 2. What must workers share with the main instance?

    Workers need the key to read stored credentials.
  3. 3. Why set a webhook URL variable behind a proxy?

    n8n cannot reliably guess its public URL behind a proxy.

Summary

  • A solid setup has pinned containers, PostgreSQL, HTTPS and tested backups.
  • Set public webhook URLs correctly behind proxies.
  • Queue mode adds Redis and workers sharing one database and key.
  • Measure capacity and keep operations routines.

Next: Security and Maintenance

आपकी प्रगति इसी ब्राउज़र में सेव होती है। खाते की ज़रूरत नहीं है।