Deploy to Vercel
Run the Node production server as a Vercel function, with schedules on Vercel Cron and jobs and events in Postgres.
Vercel runs your app as one Node function that serves every route, behind HTTPS, and scales it with
traffic. A function keeps nothing between invocations, so jobs, schedules and events live in an
external Postgres database through @relkit/postgres, and Vercel Cron wakes the deployment to run
due schedules.
What runs where
| Part of the app | On Vercel |
|---|---|
Routes, functions, /healthz |
One Node function (api/relkit.mjs) that serves the built server; every path is rewritten to it |
Files in public/ |
Vercel’s CDN, before the function; the build adds _relkit/vercel-output.txt so the directory is never empty |
| Schedules | Vercel Cron calls an authenticated endpoint; the database enqueues each occurrence once |
| Jobs and event consumers | Run inside the function: when Vercel Cron calls, and for up to 5 seconds after other requests |
| Durable state | Postgres, through @relkit/postgres; the build refuses the local filesystem provider |
| Realtime channels | Need an external provider, and WebSocket subscriptions need a host that keeps connections open (see below) |
A function invocation runs for at most 60 seconds. Long tasks belong on a container target such as Railway.
Pre-setup
Start from an app that builds, such as the api template. Install the
Vercel CLI and sign in:
vercel login
You also need a Postgres database that Vercel’s functions can reach over the internet, such as one from the Vercel Marketplace (Neon) or any hosted Postgres. Schedules that run more often than once a day need a Vercel plan with per-minute cron jobs.
Deploy
Store jobs and events in Postgres
Select the Postgres backend for jobs and events, whether or not the app has any yet:
bun run relkit add jobs --provider postgres
bun run relkit add events --provider postgresBoth commands read the connection string from the DATABASE_URL secret. The runtime creates its
tables on first start.
Generate the Vercel files
bun run relkit check
bun run relkit deploy init verceldeploy init vercel reads the schedules from the graph relkit check writes, then writes four files
and changes no cloud resource:
| File | Purpose |
|---|---|
vercel.json |
Install from bun.lock, build the Node server, route every path to the function, list crons |
api/relkit.mjs |
The function entry: activates the built server once per instance and answers Vercel Cron |
.vercelignore |
Keep node_modules, .relkit and .env files out of the upload |
.github/workflows/vercel-deploy.yml |
Check, type-check and test, then deploy every push to main with the Vercel CLI |
A file that already exists with different content stops the command; review it, then rerun with
--force to replace it. Commit the files with bun.lock.
To see a build error before you upload, build once locally; Vercel runs the same command:
bun run relkit build --runtime node --target vercelCreate the project and set its secrets
vercel link
vercel env add DATABASE_URL --environment production
vercel env add CRON_SECRET --environment productionCRON_SECRET is any random string of 16 characters or more, such as the output of
openssl rand -base64 24. Vercel Cron sends it as Authorization: Bearer <CRON_SECRET>, and the
cron endpoint refuses every caller without it. Add every other required value from your defineEnv
descriptor the same way.
Deploy and open the app
vercel deploy --prodVercel uploads the source, runs relkit build --runtime node --target vercel and prints the
deployment’s URLs, the production domain last. Without a terminal, add --yes to skip the prompts.
Open the production domain: Vercel’s default Deployment Protection asks for a Vercel sign-in on the
deployment’s own URL.
curl https://<your-domain>/healthzExpect {"status":"ready","live":true,"ready":true}. The first request to a new instance waits
until its providers are ready, so it is slower than the ones after it.
Schedules and Vercel Cron
Vercel Cron runs only on production deployments. Each crons entry in vercel.json calls
/_relkit/v1/vercel/cron/<job>/<schedule>; every call runs one scheduler pass for all schedules,
then the due job attempts and event deliveries, for up to 50 seconds. The database records each
occurrence once (it is unique on schedule and time), so two overlapping calls, or a call and an
instance that is already draining, never run an occurrence twice.
A schedule written as a UTC cron expression with five numeric fields keeps its expression. A schedule
with another timezone, an interval (every) or another expression wakes the deployment every minute
instead, and the backend decides which occurrences are due; deploy init names those schedules.
To check the cron endpoint yourself, call it with the secret, which answers 200 after one
scheduler pass, and without it, which answers 401:
curl -H "Authorization: Bearer $CRON_SECRET" https://<your-domain>/_relkit/v1/vercel/cron/<job>/<schedule>
curl https://<your-domain>/_relkit/v1/vercel/cron/<job>/<schedule>
relkit build --target vercel fails with
RELKIT_VERCEL_CRONS_OUT_OF_DATE when vercel.json
no longer matches the schedules. After adding or changing a schedule, run relkit check, then
relkit deploy init vercel --force, and commit the new vercel.json.
Jobs and events
A job triggered from a request, or an event published by one, is written to Postgres in the request.
After the response, the function keeps running for up to 5 seconds (through Vercel’s waitUntil) to
run due work, so most jobs and event consumers run within seconds; anything left runs on the next
cron call. Set RELKIT_VERCEL_DRAIN_AFTER_REQUEST=0 to run them only from Vercel Cron.
There is no separate worker process on Vercel. The build refuses the local filesystem provider for
jobs and events (RELKIT_VERCEL_LOCAL_DURABLE_STATE),
and the function refuses to start with it.
Realtime limits
Vercel functions accept no WebSocket connections and keep nothing between invocations. relkit check
fails with
RELKIT_VERCEL_REALTIME_PROVIDER_REQUIRED
when a project with vercel.json has a public or protected channel on the local realtime provider:
select an external provider such as redisRealtime() so every
instance shares the channel’s events and replay. An external provider does not make WebSocket
subscriptions possible on Vercel, and RelKit has not verified realtime subscriptions there; deploy
an app whose clients hold realtime connections to Railway.
Deploy from GitHub
The generated workflow deploys every push to main. Create an access token in Vercel (Account
Settings → Tokens) and add it as the VERCEL_TOKEN secret in the GitHub repository. Add the
VERCEL_ORG_ID and VERCEL_PROJECT_ID variables with the values from .vercel/project.json, which
vercel link wrote. Do not also connect the repository in Vercel’s Git settings, or each push deploys
twice.
Remove the project
Deleting the project removes its deployments, cron jobs and environment variables. It does not touch the database, which belongs to its own provider.
vercel project delete my-app --confirm-name my-app
Troubleshooting
- Every request answers
503. Read the function logs in the Vercel dashboard. AProvider startup failedrecord names the cause, such as a missingDATABASE_URLorRELKIT_LOCAL_DURABLE_STATE_IN_CONTAINER. - Schedules never run. Check that the deployment is a production deployment, that
CRON_SECRETis set, and that the project’s plan allows the cron frequency invercel.json. - The build fails with
RELKIT_VERCEL_CRONS_OUT_OF_DATE. Rerunrelkit deploy init vercel --forceafterrelkit check, and commitvercel.json. - POST requests are rejected. Production servers reject unsafe requests without an
Originheader that matches the app; browsers send it, and scripts must set it.