a month ago
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!
Pinned Solution
a month ago
Yes, it is absolutely possible to selfhost Nextjs+Workflows on railway.
- Vercel workflows was in beta and released as GA few days ago. https://vercel.com/blog/a-new-programming-model-for-durable-execution
- You can create nextjs project from workflow template which can be hosted on railway but will use sqlite(local dev). https://workflow-sdk.dev/docs/getting-started/next
- For production you need to use postgres-world, redis or mongodb, whichever you prefer. https://workflow-sdk.dev/worlds
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:-
- 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.
- 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
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
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 :)
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
a month ago
Yes, it is absolutely possible to selfhost Nextjs+Workflows on railway.
- Vercel workflows was in beta and released as GA few days ago. https://vercel.com/blog/a-new-programming-model-for-durable-execution
- You can create nextjs project from workflow template which can be hosted on railway but will use sqlite(local dev). https://workflow-sdk.dev/docs/getting-started/next
- For production you need to use postgres-world, redis or mongodb, whichever you prefer. https://workflow-sdk.dev/worlds
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:-
- 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.
- 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.
a month ago
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?
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