Skip to main content
Build your agent on Neon and provision backends you fully control. See how Ideavo does it
Function templatesFirst Party

Durable workflow with Inngest

A minimal multi-step workflow with retries and a durable sleep on Neon Functions, with job state in Lakebase Postgres.

About this template

This template runs a minimal multi-step workflow as a Neon Function. Inngest orchestrates the steps. It checkpoints and retries each step.run on its own, and step.sleep waits without keeping the function running. The function stores job state in Lakebase Postgres.

How it works

  1. POST /api/events sends an app/job.created event to Inngest.
  2. Inngest calls POST /api/inngest to run the workflow:
    • start-job inserts the job with status running
    • wait-before-finishing sleeps durably for 5 seconds
    • finish-job marks the job completed
  3. GET /api/jobs/:id shows the current row, so you can see the job change from running to completed.
  4. Inngest retries a failed step without re-running the steps that already succeeded.
RoutePurpose
POST /api/eventsSend an app/job.created event
GET /api/jobs/:idRead a job's current state
GET, PUT, POST /api/inngestInngest's serve endpoint
GET /Route index

Scaffold it

Install the latest Neon CLI, then create the function from the registry:

npm install -g neon@latest
neon login
neon link
neon functions new inngest-workflow --slug inngestworkflow

The CLI writes functions/inngestworkflow/index.ts, declares the function in neon.ts, and adds the Inngest keys to .env.example.

Configure Inngest

For production, create a free account at inngest.com, then copy the two keys into .env.local:

INNGEST_SIGNING_KEY="signkey-prod-..."
INNGEST_EVENT_KEY="..."
VariableDescriptionRequired
INNGEST_SIGNING_KEYSigning key from Inngest Cloud. Inngest uses it to sign requests to /api/inngest; find it under Apps > Sync new app.Yes
INNGEST_EVENT_KEYEvent key from Inngest Cloud. The function uses it to send app/job.created events; find it under Manage > Keys.Yes

For local runs, any non-empty values work because the Inngest Dev Server ignores them. neon dev still validates the env declared in neon.ts, so add placeholders before you start it:

INNGEST_SIGNING_KEY=dev
INNGEST_EVENT_KEY=dev

Run locally

Local development uses the Inngest Dev Server, so the placeholder keys above are enough.

neon dev prints the URL it serves. The examples below use http://localhost:8787, the port it picks when that port is free. If it prints a different URL, use that one instead.

# Terminal 1
INNGEST_DEV=1 neon dev

# Terminal 2
npx inngest-cli@latest dev -u http://localhost:8787/api/inngest

Send an event:

curl -X POST http://localhost:8787/api/events \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "app/job.created",
    "data": { "jobId": "job_1" }
  }'

The job starts in running, which you can check right away:

curl http://localhost:8787/api/jobs/job_1

After the 5-second sleep, the same request returns completed. The Inngest Dev Server UI at http://localhost:8288 shows the run and each of its steps.

Deploy

neon deploy --env .env.local
neon functions get inngestworkflow

In Inngest Cloud, open Apps, choose Sync new app, and enter this URL:

https://<function-url>/api/inngest

Then trigger the deployed workflow with the same curl and the function URL as the host.

curl -X POST https://<function-url>/api/events \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "app/job.created",
    "data": { "jobId": "job_1" }
  }'

Replace <function-url> with the URL from neon functions get inngestworkflow.

Notes

  • The function creates the jobs table on its first run with CREATE TABLE IF NOT EXISTS, so there is no migration step.
  • POST /api/events has no authentication in this demo, so anyone with the function URL can start a workflow. Add authentication before you expose it.
  • Add more step.run calls around the sleep to extend the workflow. Keep side effects inside step.run so a retry doesn't repeat completed work.
  • step.sleep("wait-before-finishing", "5s") simulates a processing window. Inngest holds the timer, so the function isn't running or billed while it waits.