Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Scale and run at high availability on AWS

The terraform-aws-n8n module deploys n8n in queue mode by default, with a multi-main setup for high availability. This page covers the module-specific settings for that topology: multi-main licensing, worker autoscaling, and Redis high availability.

Multi-main setup

By default, the module runs more than one main pod and requires an Enterprise license. Set n8n_main_hpa_min_replicas = 1 to run a single main pod instead, which only requires a Business plan license, since n8n's multi-main leader-election feature is disabled in that mode.

Any load balancer or Ingress in front of the main pods needs session persistence (sticky sessions) enabled so a browser stays connected to one main pod. The module's own Ingress sets this by default. If you bring your own Ingress, see Customize the AWS infrastructure.

Worker autoscaling

Worker pods scale on Redis queue depth using KEDA, which the module installs automatically. To check whether a worker's autoscaler can reach Redis:

kubectl -n n8n get scaledobject

A healthy scaler reports READY=True. If it reports READY=False, check the KEDA operator logs for the reason:

kubectl -n keda logs -l app=keda-operator | grep -i 'connection to redis'

The worker HPA's TARGETS column can be misleading

kubectl get hpa often shows <unknown> in the TARGETS column for KEDA-backed worker HPAs, even while autoscaling works correctly. Use kubectl get scaledobject instead to check scaler health.

If you enable Redis in-transit encryption, KEDA's queue-depth triggers automatically use the same encrypted, authenticated connection as the workers.

Redis high availability

By default, the module provisions Redis as a single-node aws_elasticache_cluster, which is a single point of failure for both the worker queue and multi-main leader election. Set redis_high_availability_enabled = true to provision a replication group (one primary and one replica) with automatic failover across two Availability Zones instead:

Both nodes use redis_node_type, so enabling high availability roughly doubles the Redis cost.

Avoid restarts during a failover

Set n8n_redis_timeout_threshold to raise how long n8n waits for Redis before exiting. The useful budget is coarser than the number you set, because each failed connection attempt takes about 11.1 seconds (a 1-second retry interval plus a 10-second connection timeout):

You set
Real budget
Reconnect attempts before exit

10000 (default)

11.1 seconds

1

30000

33.2 seconds

3

60000

66.4 seconds

6

A stale Redis endpoint after a failover can take longer to resolve than the failover itself, due to DNS caching. Setting the threshold to 60000 clears this in practice, with pods logging Recovered Redis connection instead of restarting:

This is a trade-off, not a free win: the same threshold also decides how long a pod waits before restarting against a genuinely dead Redis. For a worker, that's usually an acceptable trade, since restarting doesn't help when Redis is unreachable either way.

Switching topologies

Switching redis_high_availability_enabled on a live deployment destroys the existing cache and creates a new one. Everything queued or in progress at that moment is lost. Treat this as a maintenance-window operation: stop new work from reaching n8n, let the workers drain, and verify that bull:jobs:wait, bull:jobs:active, and bull:jobs:delayed are all empty in Redis before applying.

Redis eviction policy

The module sets Redis's maxmemory-policy to noeviction (redis_maxmemory_policy), rather than ElastiCache's volatile-lru default. Under memory pressure, a noeviction Redis rejects new writes with an out-of-memory error instead of silently evicting queue keys, such as job locks. This makes a full Redis visible as failed writes and job-lock-renewal failures, rather than as queue data disappearing without explanation. Plan Redis memory for the queue and n8n's cache together, since both share the same instance.

Redis in-transit encryption and AUTH

By default, Redis sits in private subnets behind a security group that only admits VPC traffic, with no TLS and no password. Set redis_transit_encryption_enabled = true to add both: the module enables TLS, generates an AUTH token, and wires it onto every n8n container.

Last updated

Was this helpful?