Is it possible to selfhost vercel workflow(long running background jobs) setup on railway?

Looks like vercel has officially added support for long running jobs into nextjs, astro etc. I was curious if we can selfhost all setup on railway, not sure if possible. Because it's inegrated into frameworks, so it'll become very easy to create apps like agents, orchestration, bots(whatsapp, slack etc.) based on agents etc.

Anyone who can dig into their docs or github repos to selfhost setup in nextjs on railway along with a simple example. Your help will be much appreciated!

https://www.youtube.com/watch?v=C9ahOihLPVA

Docs: https://vercel.com/docs/workflows

Solved$40 Bounty

Pinned Solution

Yes, it is absolutely possible to selfhost Nextjs+Workflows on railway.

Below are the templates on railway which you can use as starter. You need to eject in settings tab, which will create this repo in your github and then you can start developing:-

  1. A very simple starter with v4-beta version of workflow https://railway.com/deploy/workflow-devkit This template is published by the creator of workflows.
  2. A chat example with streaming via workflow(background jobs) and a logs dashboard for observability https://railway.com/deploy/vercel-workflow This includes latest nextjs and workflows version with Postgres.

5 Replies

Railway
BOT

a month ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open Railway about 1 month ago


domehane
FREE

a month ago

Hello muhammad_iqbal;

yes it's possible to self-host vercel workflows on railway without using vercel at all

the workflow sdk is open source and has an official package called @workflow/world-postgres made exactly for this , self-hosting on platforms like railway, render, fly.io etc. it uses postgres for state storage and graphile-worker for job processing

here's what you need:

first, install the packages: npm install workflow @workflow/world-postgres

then, set these two env vars in railway (railway already gives you DATABASE_URL from its postgres plugin which the sdk falls back to automatically): WORKFLOW_TARGET_WORLD="@workflow/world-postgres" and WORKFLOW_POSTGRES_URL="your railway postgres url"

after that, run the db migration once: npx workflow-postgres-setup

at the end, in your next.js project create an instrumentation.ts at the root with this:

export async function register() { if (process.env.NEXT_RUNTIME !== "edge") { const { getWorld } = await import("workflow/runtime"); const world = await getWorld(); await world.start?.(); } }

that's it railway works perfectly for this because it runs long-running servers by default, which is exactly what this needs (it won't work on serverless)

Hope this help you :)


domehane

Hello **muhammad\_iqbal;** yes it's possible to self-host vercel workflows on railway without using vercel at all the workflow sdk is open source and has an official package called @workflow/world-postgres made exactly for this , self-hosting on platforms like railway, render, [fly.io](http://fly.io) etc. it uses postgres for state storage and graphile-worker for job processing here's what you need: first, install the packages: npm install workflow @workflow/world-postgres then, set these two env vars in railway (railway already gives you DATABASE\_URL from its postgres plugin which the sdk falls back to automatically): WORKFLOW\_TARGET\_WORLD="@workflow/world-postgres" and WORKFLOW\_POSTGRES\_URL="your railway postgres url" after that, run the db migration once: npx workflow-postgres-setup at the end, in your next.js project create an instrumentation.ts at the root with this: export async function register() { if ([process.env.NEXT](http://process.env.NEXT)\_RUNTIME !== "edge") { const { getWorld } = await import("workflow/runtime"); const world = await getWorld(); await world.start?.(); } } that's it railway works perfectly for this because it runs long-running servers by default, which is exactly what this needs (it won't work on serverless) Hope this help you :)

domehane
FREE

a month ago

my info source is from here ; workflow-sdk.dev/worlds/postgres and railway is explicitly listed as a supported deployment target on that page


Yes, it is absolutely possible to selfhost Nextjs+Workflows on railway.

Below are the templates on railway which you can use as starter. You need to eject in settings tab, which will create this repo in your github and then you can start developing:-

  1. A very simple starter with v4-beta version of workflow https://railway.com/deploy/workflow-devkit This template is published by the creator of workflows.
  2. A chat example with streaming via workflow(background jobs) and a logs dashboard for observability https://railway.com/deploy/vercel-workflow This includes latest nextjs and workflows version with Postgres.

Thanks!

To scale up, I think there should be anyway we can add more workers or deploy workflows as separate process. Is there any guide/way for that?


ian_rosenfeldt

Thanks! To scale up, I think there should be anyway we can add more workers or deploy workflows as separate process. Is there any guide/way for that?

domehane
FREE

a month ago

there are two confirmed ways to scale:

option 1 is to increase concurrency within the same process via env var : set WORKFLOW_POSTGRES_WORKER_CONCURRENCY to whatever number you want (default is 10). the docs also say to set WORKFLOW_POSTGRES_MAX_POOL_SIZE to queueConcurrency + 2 when going higher

option 2 is a programmatic config if you want more control : in workflow.config.ts you can do createWorld({ connectionString: "...", queueConcurrency: 20, maxPoolSize: 22 })

option 3 is horizontal scaling, so since everything is backed by postgres + graphile-worker, you can just run multiple instances of your app (multiple railway services) all pointing to the same postgres database. graphile-worker is designed to handle multiple workers polling the same queue safely, so this works out of the box on railway by just scaling your service replicas

source is the same page: workflow-sdk.dev/worlds/postgres, configuration section

Hope this help you :)


Status changed to Solved brody about 1 month ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...