← Back to Guides
Profile image for Amr Essam
Profile image for Daniel Cosby
Published 2nd May 2025

How to self-host n8n AI workflow automation on Northflank

Automation is no longer a luxury addition for organizations, it is becoming an essential component for efficient and cost-effective business and IT processes. However, implementing automated workflows used to require extensive development experience and involves complex setup and configurations.

No-code automation to the rescue!

No-code automation platforms allow organizations to configure their automated workflows without the need to write code or having a dedicated automation team with development experience. Workflows can simply be created using a visual interface or text-based input that configures the different steps of the workflow.

What is n8n?

n8n is a popular workflow automation platform that offers various integrations with different tools and frameworks allowing for a wide range of automation use-cases, including AI agents. n8n can benefit different teams in an organization, from IT teams automating technical workflows, marketing teams automating processes for marketing campaigns, or HR teams analyzing employee turnover risk, n8n can make life easier by automating their required workflow tasks using a visual drag-and-drop interface.

In this guide, we will explain how to deploy n8n on Northflank. First we'll look at the architecture of self-hosted n8n, then we’ll create a deployment service utilizing the n8n container image and a PostgreSQL add-on as an external database to persist data. We'll then expand our deployment by adding Redis and a worker for even better scalability.

If you want to get started straight away, you can instead use the one-click deployment options for n8n.

n8n self-hosted architecture

n8n can be deployed in different ways for scalability. The simplest deployment would be a single n8n service with a persistent volume, however for scalability we'll look at two different options for this guide:

  1. A single deployment with a PostgreSQL database
  2. A deployment for the UI/API and a separate worker deployment, with PostgreSQL and Redis

Prerequisites

Before going through the steps in this guide, you need to have already completed the following:

  1. Login to your existing Northflank account, or create a new account if you don’t have one already.

Deploy in one click

You can deploy n8n with Postgres, or n8n with a worker using the respective Northflank stack templates:

  1. Customise your project name, colour, and region, if desired
  2. Click Deploy stack to save and run the n8n template
  3. Once the template run has finished deploying all components, open the project and select the n8n service
  4. When the n8n service shows as running, open the code.run domain under Ports & DNS in the service header to access your n8n instance and begin configuration

Deploy n8n with PostgreSQL

The simplest way to host n8n on Northflank is by using a deployment service. Northflank's deployment services let you deploy a container instance (or multiple instances for scalability) from a container image. This image can be built on Northflank itself using a build service, or pulled from any other registry as a ready image.

Using a deployment service is straightforward, you can just point Northflank to the location of your image, provide any additional configuration you want for your deployed instance, and then Northflank takes it from there to get your application running.

Deploy n8n

  1. Under the project, create a new service and choose its type as a deployment service.
  2. Provide a name for the service, and choose the deployment source as external image.
  3. In the image path, use docker.n8n.io/n8nio/n8n:latest, this is the official n8n image from the repository.
  4. In the networking section edit port 5678 and choose the protocol type as HTTP. Check the option to publicly expose this port to the internet. This will allow you to connect to the n8n service publicly from anywhere using the domain name provided by Northflank. You can also use your own domain by expanding the option for custom domains.
  5. In the resources section, choose a compute plan that fits your needs for the CPU and memory requirements. Without a worker deployed, this deployment will also execute workflows and code.
  6. Click on create service, and you should see a running instance of your n8n deployment
  7. To access your n8n instance you can simply use the Northflank-generated URL in the top right corner of the service overview page

Creating a n8n deployment on Northflank

Any changes we make in this deployment will be lost if it restarts, however, as it's only using ephemeral storage. Containers use ephemeral disks, meaning that any data written to the filesystem will be wiped out once the container is restarted. We could mount a volume to /home/node/.n8n as n8n uses an SQLite database saved to the local disk by default, but this will become an obstacle to scaling n8n in future. Instead, we can use a PostgreSQL database and environment variables to persist data outside of the ephemeral containers.

Deploy Postgres

We’ll first need to provision our PostgreSQL instance and then pass the required environment variables to n8n.

A simple way to provision a PostgreSQL instance is by using Northflank addons, which integrate common infrastructure components like databases, caches, message queues with your application. The addons are provided as managed services, meaning that the Northflank platform takes care of the heavy lifting for provisioning and setting up these components, allowing you to focus more on your application.

We can create a PostgreSQL database addon with the following steps:

  1. Click on create new > addon under your project. Then choose PostgreSQL and provide a name for the Addon.
  2. Disable deploy with TLS
  3. Specify the compute plan for your addon, the size of disk, and the number of replicas. You can scale both these up later.
  4. Click on create addon and Northflank will start provisioning your database

Depolying Postgres on Northflank

After the database instance is provisioned, you’ll find the database connection details under the overview section.

Create a secret group

To enable n8n to use the new PostgreSQL database, we’ll need to provide the connection details as environment variables for our deployment instance. We can link the Postgres addon to the sevice by using a secret group, which will automatically provide the relevant connection details even if they are changed by updating the addon's configuration. As we're not using a persistent volume, we'll also add the neccessary secrets and configuration values as environment variables.

  1. Click on create new > secret group under your project and give it a name

  2. Edit secrets and add the following variables. You can use the key button in the secret editor to generate a value for the encryption key, which should be at least 32 characters long in hex mode (256-bits).

    # Tells n8n to use our Postgres addon
    DB_TYPE="postgresdb"
    # Encrypts sensitive data in the database, saves the key outside the ephemeral container
    N8N_ENCRYPTION_KEY="<some-random-string>"
    # Tell n8n it's behind the Northflank load balancer
    N8N_PROXY_HOPS="1"
    # Enable code execution in workflows
    N8N_RUNNERS_ENABLED=true

    Managing secrets in Northflank

  3. Next, expand show addons and click configure on the Postgres addon. Select USERNAME, PASSWORD, DATABASE, HOST, and PORT, and give them the following aliases:

    KeyAlias
    USERNAMEDB_POSTGRESDB_USER
    PASSWORDDB_POSTGRESDB_PASSWORD
    DATABASEDB_POSTGRESDB_DATABASE
    HOSTDB_POSTGRESDB_HOST
    PORTDB_POSTGRESDB_PORT

    Linking database connection details to environment variables in Northflank

  4. Create the secret group

You can now return to your n8n deployment service and restart it, and the container will be deployed with the environment variables from the secret group, configuring it to store data in the PostgreSQL database.

n8n deployed on Northflank

If you're just testing n8n, or don't need to scale it up to handle heavy usage yet, you can skip to the section on configuring and using n8n. Otherwise, you can follow the rest of the guide to deploy Redis and a n8n worker in addition, and scale up your n8n deployment to handle heavy usage.

Deploy a n8n worker

Deploy Redis

  1. Click on create new > addon under your project, then choose Redis and provide a name for the addon
  2. Disable deploy with TLS
  3. Specify the compute plan for your addon, the size of disk, and the number of replicas. You can scale both these up later.
  4. Click on create addon and Northflank will start provisioning your database

Deploying Redis on Northflank

Deploy n8n worker

Create a new deployment service following the same steps as we did to create the main n8n deployment. However, this time:

  • do not expose the 5678 HTTP port to the public internet
  • select custom command for the Docker runtime mode in the advanced section and enter the command worker. This will start this n8n deployment in worker mode.

Configuring an n8n worker on Northflank

Update secret group

To configure the n8n main deployment to use the n8n worker, add the following enviornment variables to your existing secret group:

EXECUTIONS_MODE="queue"
QUEUE_HEALTH_CHECK_ACTIVE=true
OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true

Configuring n8n worker environment variables on Northflank

Next, expand linked addons and configure the Redis addon, linking the following values with the corresponding aliases:

KeyAlias
PASSWORDQUEUE_BULL_REDIS_PASSWORD
HOSTQUEUE_BULL_REDIS_HOST
PORTQUEUE_BULL_REDIS_PORT

Managing Redis secrets on Northflank

You can now restart your n8n and worker deployments and begin executing workflows. You can check the logs for the n8n worker to confirm it's recieving and executing tasks.

You can now scale the worker component of your self-hosted n8n deployment independently of the main n8n application and API.

Configure and use n8n

Congratulations! You now have your n8n self-hosted instance running. No YAML files needed, no Helm charts, and no Kubernetes cluster complexities. Northflank allows you to focus on your workloads instead of worrying about the underlying infrastructure, this abstraction offers a seamless and efficient deployment experience for any containerized workload.

Open the domain in the n8n service header, and follow the steps to create an account and set up your n8n deployment.

Registering for n8n on Northflank Configuring n8n on Northflank

You can now begin designing and executing workflows!

Creating n8n workflows on Northflank

You can add health checks to your services to handle redeployments gracefully, scale your n8n deployment up to meet demand, and add custom domains.

Check the n8n docs for more configuration options for n8n.

Conclusion

n8n is a workflow automation platform that supports a wide range of automation use cases and offers various integrations. It simplifies the process of creating workflows by using a visual editor instead of writing code for the workflow steps.

Northflank simplifies the deployment of n8n by removing the need for provisioning and configuring infrastructure resources to self-host the n8n instance. You can simply use a deployment service and point it to the n8n container image, and Northflank will take care of the underlying infrastructure for the deployment.

You can also make use of Northflank templates to host your n8n instance. Instead of manually creating the project, deployment service, database addon, and other components, templates act as a package that groups all these related resources in a single deployable object. This enables a consistent and seamless one-click deployment that can be replicated across different locations.

You can explore other guides for deploying different applications on Northflank.

Deploy on Northflank for free

Northflank allows you to deploy your code and databases within minutes. Sign up for a Northflank account and create a free project to get started.

  • Build, deploy, scale, and release from development to production
  • Observe & monitor with real-time metrics & logs
  • Deploy managed databases and storage
  • Manage infrastructure as code
  • Deploy clusters in your own cloud accounts
  • Run GPU workloads
Share this article with your network
X