how to host n8n on railway

Why should hosting n8n feel harder than building the automations themselves? Beginners often get stuck on webhooks, storage, domains, or database settings. One incorrect setting can leave workflows unreachable or put stored data at risk.

Railway removes much of the server management required by a traditional VPS. It can run the official n8n Docker image with persistent storage and a public HTTPS address. Railway also supports PostgreSQL when your workload needs a more production focused database.

This guide explains how to host n8n on Railway in eight practical steps. You will configure deployment, storage, PostgreSQL, environment variables, domains, webhooks, security, and backups. You will also learn how to troubleshoot common problems and decide when scaling becomes necessary.

Table of Contents

How to Host n8n on Railway

You can host n8n on Railway by deploying the official Docker image, adding persistent storage, and configuring a public webhook URL. Railway also provides an n8n template that can provision the basic setup automatically. The official Railway guide currently supports both template deployment and manual Docker deployment.

The eight steps are choosing a deployment method, creating the service, adding persistence, configuring variables, setting a domain, testing webhooks, securing n8n, and protecting the installation. A simple installation can use one n8n service with SQLite and one Railway Volume. Production workloads can add PostgreSQL, while larger workloads can later add Redis and workers.

What Do You Need Before Hosting n8n on Railway?

You need a Railway account, an n8n deployment method, and enough resources for your expected workload. A custom domain is optional because Railway can generate a public domain automatically. GitHub is also optional when you deploy from a template or public Docker image.

Railway offers new users a trial with a one time $5 credit lasting up to 30 days. The current trial limits include 1 GB RAM and shared CPU resources, with up to five services per project. After the trial, Railway’s Free plan currently provides $1 in monthly credit.

Railway Account, Domain, and GitHub Requirements

A Railway account is required, but you do not need a custom domain or GitHub account for basic deployment. Railway can generate an address such as n8n-production-xxxx.up.railway.app for browser access and webhooks. GitHub becomes useful when your deployment depends on repository files or custom configuration.

A custom domain becomes useful when you want an address such as automation.example.com. It can also give OAuth integrations a stable callback address that you control. If the public domain changes later, update related webhook and OAuth callback URLs.

How Much RAM and CPU Does n8n Need?

Resource requirements depend on what your workflows process rather than a single fixed n8n requirement. Small automations using webhooks, schedules, or simple API requests consume less memory than AI processing or large data operations. Start with the smallest practical deployment and monitor actual CPU and memory consumption.

Railway charges for resource usage such as memory, CPU, disk storage, and network traffic. This makes monitoring more useful than choosing oversized resources before you know your workload. Railway’s billing documentation confirms that running services consume resources even when request traffic is low.

Step 1: Which Railway Deployment Method Should You Use?

Use the Railway n8n template for simplicity, Docker for direct image control, or GitHub for customized deployments. Each method ultimately creates a Railway service that runs n8n. Beginners usually need only the template or Docker approach.

Railway n8n Template

The Railway template is the simplest method because it can create n8n with storage already configured. Railway currently offers an n8n template using the official stable image and a persistent volume at /home/node/.n8n. This setup uses SQLite and does not require a separate database service.

Docker Image Deployment

Docker deployment gives you direct control over the n8n image and environment configuration. Create a Docker Image service and enter n8nio/n8n as the image name. Railway then pulls the official image and creates the service.

GitHub Repository Deployment

GitHub deployment is useful when your setup includes custom files, scripts, or version controlled configuration. Connect the repository to Railway and deploy the required branch. You do not need this method for a standard n8n installation.

Step 2: How to Deploy n8n on Railway

Create one Railway project, add the n8n service, and confirm that the container starts successfully. A project can later contain related services such as PostgreSQL and Redis. Keeping them in one project also simplifies private communication between services.

Create a Railway Project and Add n8n

Open Railway, create a new project, and select your chosen deployment method. For manual Docker deployment, select Docker Image and enter n8nio/n8n. For the template method, select the n8n template and let Railway create the required service.

Deploy the n8n Service

Start the deployment and check the Railway logs for successful startup. The service is not automatically useful for public webhooks until networking and environment variables are configured. Fix startup errors before adding more components.

Open n8n and Create Your Owner Account

Generate a public Railway domain and open that address in your browser. n8n will ask you to create the first owner account when the installation is new. Use strong account credentials before connecting external services such as Gmail, Slack, or OpenAI.

Step 3: How to Make n8n Data Persistent on Railway

Attach persistent storage before trusting the installation with important workflows or credentials. n8n stores important local data under /home/node/.n8n when using its default SQLite setup. Railway warns that this data is lost across deployments if no persistent volume is attached.

Railway recommends mounting a Volume at /home/node/.n8n. Its current guide suggests 1 GB as a reasonable starting size for a basic installation. The volume preserves n8n data across restarts and redeployments.

Railway Volume vs PostgreSQL

A Railway Volume preserves filesystem data, while PostgreSQL provides a separate relational database for n8n. They are not interchangeable storage methods. Railway notes that a volume remains useful for local files even when PostgreSQL stores the main application database.

SQLite vs PostgreSQL for n8n

SQLite works well for a basic single service deployment, while PostgreSQL suits heavier production workloads. Railway’s standard n8n template uses SQLite with a persistent volume and requires no separate database. Railway recommends PostgreSQL when execution volume becomes higher.

Step 4: How to Configure n8n Environment Variables

Configure environment variables so n8n understands its port, public address, timezone, encryption settings, and database connection. Add these values through the Variables area of the n8n service. Store passwords, tokens, and encryption keys there instead of committing them to public repositories.

Set N8N_PROTOCOL and WEBHOOK_URL

Set N8N_PROTOCOL to https and point WEBHOOK_URL to the public Railway address. Railway’s current guide also sets N8N_PORT to ${{PORT}}, which uses Railway’s injected application port. After generating your Railway domain, replace the placeholder webhook address with the real HTTPS URL.

An incorrect WEBHOOK_URL can cause webhook nodes to produce unreachable addresses. Redeploy the service after changing environment variables. Then confirm that newly generated webhook URLs use the correct public hostname.

Set N8N_ENCRYPTION_KEY and Timezone

Keep one permanent N8N_ENCRYPTION_KEY because n8n uses it to protect stored credentials. Back up this key separately from the database. Losing the key can make encrypted credentials unreadable even when the database backup remains available.

Set GENERIC_TIMEZONE to the timezone used by scheduled workflows. Valid examples include America/New_York, Europe/London, and Asia/Karachi. This prevents schedule triggers from running according to an unexpected timezone.

Connect PostgreSQL to n8n

Set DB_TYPE=postgresdb and provide the Railway PostgreSQL connection variables. These include the host, port, database name, username, and password. Railway supports reference variables so n8n can read values directly from its PostgreSQL service.

Common variable names include DB_POSTGRESDB_HOST, DB_POSTGRESDB_PORT, and DB_POSTGRESDB_DATABASE. You will also need DB_POSTGRESDB_USER and DB_POSTGRESDB_PASSWORD. Redeploy n8n after adding the database configuration.

Step 5: How to Add a Domain and HTTPS to n8n

Generate a Railway domain first, then connect your own domain only when you need one. Railway Public Networking provides automatic SSL for Railway generated addresses. It also supports automatic certificates for correctly configured custom domains.

Use a Railway Generated Domain

Open the service settings and select Generate Domain under Public Networking. Railway then creates a public HTTPS address for the n8n editor. Use this address to complete the initial deployment and webhook tests.

Connect a Custom Domain

Add the custom domain in Railway and copy the provided DNS records to your DNS provider. Railway currently requires both a CNAME record and a TXT record for standard custom domain verification. After verification, Railway automatically issues and renews the SSL certificate.

DNS changes can take up to 72 hours to propagate worldwide. After changing domains, update WEBHOOK_URL and any editor URL setting used by your deployment. Also update OAuth callback URLs for integrations such as Google or GitHub when they reference the old domain.

Step 6: How to Configure and Test n8n Webhooks

Set the correct public webhook URL, then test both development and production webhook behavior. Webhooks let external services send events directly into n8n. Examples include Stripe payments, Shopify orders, and form submissions.

Test Webhooks vs Production Webhooks

Use the test webhook while building the workflow, then use the production URL after publishing or activating it. A test URL waits for incoming data during manual testing. Production webhooks are intended for live events reaching active workflows.

Send one real request after activating the workflow. Confirm that the execution appears inside n8n and contains the expected data. This catches domain or routing mistakes before the automation becomes important.

Fix Incorrect Webhook URLs

Check WEBHOOK_URL, HTTPS, workflow status, and the public domain when webhook requests fail. If the URL still shows an old domain, update the variable and redeploy n8n. Also update the sending application when its saved endpoint still points to the previous address.

OAuth failures can have a similar cause because providers compare callback URLs closely. Update authorized callback addresses after changing your n8n hostname. This is especially important for integrations using Google, GitHub, or other OAuth providers.

Step 7: How to Secure Your n8n Railway Setup

Secure n8n by protecting account access, environment secrets, database connections, and the encryption key. Use HTTPS for editor access, OAuth callbacks, and public webhooks. Keep PostgreSQL and Redis on private networking whenever public exposure is unnecessary.

Do not place API keys, passwords, or database credentials inside public GitHub repositories. Keep N8N_ENCRYPTION_KEY backed up in a separate secure location. Changing or losing it can prevent n8n from decrypting stored credentials.

n8n also provides a built-in security audit using the n8n audit command. The audit checks credentials, database usage, filesystem access, risky nodes, unprotected webhooks, and instance settings. It can also identify whether the installed n8n version is outdated.

Step 8: How to Back Up, Update, and Verify n8n

Back up important data before updating the n8n image or changing database configuration. Preserve the database, persistent volume data, encryption key, environment values, and domain configuration. Workflow exports provide another useful recovery copy for critical automations.

When updating Docker deployments, change to the intended n8n image version and redeploy. Railway templates note that database migrations run when newer n8n versions start. Test important workflows, webhooks, schedules, and API connections immediately after the update.

Avoid upgrading production components independently when using workers or task runners. Matching versions reduce compatibility problems between the main instance and supporting services. Keep the previous working image version recorded so you have a clear rollback target.

How Much Does It Cost to Host n8n on Railway?

Railway’s Hobby plan currently costs $5 per month and includes the first $5 of resource usage. If monthly usage reaches $8, the total becomes $8 rather than $5 plus another $8. Unused included usage does not roll into the next billing cycle.

Actual cost depends on resources such as memory, CPU, disk storage, and network traffic. PostgreSQL, Redis, and worker services increase total consumption because each service uses additional infrastructure. A single n8n service using SQLite and one volume is therefore simpler to budget than a multi service architecture.

New users currently receive a one time $5 trial grant lasting up to 30 days. After the trial, Railway’s Free plan provides $1 of monthly credit under current documentation. These terms can change, so check Railway’s pricing before estimating long term hosting costs.

How to Troubleshoot Common n8n Railway Problems

Start troubleshooting with deployment logs, environment variables, networking settings, and persistent storage. These four areas explain many common Railway n8n failures. Change one setting at a time so you can identify what solved the problem.

n8n Does Not Start or Keeps Restarting

Check Railway logs for missing variables, database errors, port issues, or memory problems. Confirm that the image name and required connection values are correct. If PostgreSQL was recently added, verify every database reference before redeploying.

Workflows Disappear After Redeployment

Missing workflows usually mean SQLite data was stored without a persistent volume. The default database resides inside /home/node/.n8n, so that path must persist between deployments. Railway’s official guide specifically warns that deployment data is lost without a volume.

PostgreSQL Connection Fails

Verify DB_TYPE, host, port, database name, username, and password first. Use Railway reference variables instead of manually copying database credentials where possible. Redeploy n8n after changing any connection value.

Webhooks or Custom Domains Do Not Work

Check the CNAME record, TXT record, SSL status, and WEBHOOK_URL. Railway states that a missing TXT verification record can cause a custom domain to return a 404 response. DNS propagation and incorrect Cloudflare settings can also delay successful HTTPS access.

When Should You Use Redis, Queue Mode, and Workers?

Use Redis and workers when one n8n process no longer handles your required execution volume reliably. Queue mode separates workflow coordination from execution processing. Redis holds queued work while worker services perform the executions.

Railway currently offers an n8n worker template with PostgreSQL, Redis, a primary service, and worker services. The template automatically connects queue and database variables through Railway’s private network. It can also route editor traffic and production webhook traffic according to the deployed architecture.

Do not add this complexity to a small personal deployment without a workload reason. Begin with one n8n service and measure execution demand first. Scale when concurrency, long running jobs, or increasing workflow volume creates a clear bottleneck.

Railway vs VPS vs n8n Cloud for Hosting n8n

Railway reduces infrastructure management, a VPS gives more server control, and n8n Cloud manages hosting for you. Railway handles areas such as deployments, public networking, SSL certificates, logs, and persistent volumes. A VPS requires you to manage more of the operating system, Docker stack, firewall, proxy, and updates yourself.

n8n Cloud removes most infrastructure work because n8n operates the hosting environment. Railway sits between managed cloud hosting and direct VPS administration. It suits users who want self hosting without managing an entire server.

A VPS can provide more predictable control over dedicated server resources and system configuration. Railway can be easier when your priority is deploying containers and related databases quickly. The better option depends on workload, budget, maintenance skills, and infrastructure requirements.

Is Railway a Good Choice for n8n?

Railway is a practical choice when you want to self host n8n without maintaining a traditional VPS. Its official n8n guide provides Docker deployment, persistent volumes, public domains, webhook configuration, and optional PostgreSQL. These features cover the main requirements of a small or growing n8n installation.

Start with SQLite and a persistent volume when your workload is simple. Move to PostgreSQL when execution volume or production requirements justify it. Add Redis and workers only when one n8n instance becomes a real performance limitation.

Railway may be less suitable when you need complete operating system control or a fixed server configuration. A VPS gives direct access to those infrastructure layers. n8n Cloud remains the simpler choice when you do not want to manage hosting at all.

Conclusion

In conclusion, Hosting n8n on Railway gives you a practical way to run your own automation platform without managing a full VPS. A reliable setup depends on persistent storage, correct environment variables, working webhooks, HTTPS, secure credentials, and regular backups. Start with SQLite and a Railway Volume for simpler workloads, then move to PostgreSQL, Redis, and workers as your automation needs grow. Create your Railway project, follow the eight setup steps, and test your first n8n workflow before putting important automations into production.

Frequently Asked Questions About Hosting n8n on Railway

Can I host n8n on Railway for free?

Railway currently offers limited free usage, but continuous n8n hosting can exceed those credits. New users receive a $5 trial credit for up to 30 days, followed by the Free plan’s current $1 monthly credit. Resource consumption determines whether your deployment stays within that amount.

Do I need PostgreSQL for n8n on Railway?

No, PostgreSQL is not required for a basic n8n installation on Railway. SQLite works with a Railway Volume mounted at /home/node/.n8n. PostgreSQL becomes more useful for higher execution volumes and more demanding production deployments.

Do I need a custom domain for n8n?

No, Railway can generate a public HTTPS domain for your n8n service. This generated address works for the editor and webhooks. A custom domain is useful when you want branded URLs or greater control over your public hostname.

Do I need GitHub to deploy n8n on Railway?

No, GitHub is unnecessary when you deploy through a Railway template or public Docker image. GitHub becomes relevant when your deployment uses a repository containing custom configuration or code. Choose it only when version controlled deployment files are part of your setup.

Does Railway provide HTTPS for n8n?

Yes, Railway provides automatic SSL for Railway domains and correctly configured custom domains. Custom domains require the DNS records Railway provides before certificate issuance can complete. Railway automatically renews its managed Let’s Encrypt certificates.

Why did my n8n workflows disappear after redeployment?

Your SQLite database was probably stored in temporary container storage instead of a persistent volume. Mount a Railway Volume at /home/node/.n8n before saving important workflows. This path stores the default SQLite database and other local n8n data.

Can n8n use Redis and workers on Railway?

Yes, Railway can run n8n with Redis, PostgreSQL, and separate worker services. This architecture supports queue based execution when a single process becomes insufficient. Railway currently provides templates that automatically connect these components through private networking.

Is Railway suitable for production n8n?

Yes, Railway can support production n8n when persistence, security, backups, and resources are configured correctly. PostgreSQL is a sensible option when reliability and execution volume exceed a small SQLite installation. Production deployments should also preserve the encryption key, monitor resource usage, and test backups before they are needed.

Table of Contents

→ Table of Content