Skip to Content
Runlane
Run in production

Deliver wakeups over HTTP

Compose durable storage with signed HTTP delivery and choose a host lifetime.

Use @runlane/transport-http when Runlane should POST wakeups straight to your app. It includes a direct sender and a standard (Request) => Promise<Response> handler. It supports Node.js, not edge runtimes. Use @runlane/lane-postgres-http or @runlane/lane-redis-http to pair it with durable storage. No third-party broker is required.

Storage holds the runs, payloads, leases and pending delivery records. HTTP carries canonical wakeup bytes, not task payloads. The direct transport has no retention, native delay, ordering or deduplication guarantee. Its profile is best_effort; a composed lane reports productionDurable: false even with durable storage. That flag currently gates no runtime operation. Durability of accepted state still depends on storage, and progress depends on maintenance.

Compose a lane

Install @runlane/transport-http, @runlane/core, and @runlane/lane-postgres-http (or @runlane/lane-redis-http). Generate a secret once and save it in your secret manager:

node --input-type=module -e "import { randomBytes } from 'node:crypto'; process.stdout.write('whsec_' + randomBytes(32).toString('base64') + '\n')"

Use the same environment name and signing secrets on producers and receivers. The direct transport uses the Standard Webhooks wire format. Secrets must be whsec_ plus canonical base64 encoding 24–64 random bytes; the command above generates 32 bytes. The handler first verifies the exact body bytes, then decodes the canonical envelope. An environment mismatch gets 401 before core runs.

src/runlane.ts
import { createRunlane, RunRetention, queue, task } from '@runlane/core'
import { postgresHttpLane } from '@runlane/lane-postgres-http'
import { createDirectHttpAdapter, HttpLifetimeMode } from '@runlane/transport-http'
import * as z from 'zod'

import { logger } from './logger.js'

const config = z
  .object({
    DATABASE_URL: z.url(),
    RUNLANE_DELIVERY_URL: z.url(),
    RUNLANE_DELIVERY_SECRET: z.string(),
  })
  .parse(process.env)

const environment = { name: 'production' }
const jobs = queue({ name: 'jobs', default: true, concurrency: { total: 20 } })
const echo = task({ id: 'echo', schema: z.string(), run: (input) => input })
const lane = postgresHttpLane({
  postgres: { connectionString: config.DATABASE_URL, schema: 'runlane' },
  runHints: false,
  http: {
    lifetime: HttpLifetimeMode.InRequest,
    queues: [jobs],
    adapter: createDirectHttpAdapter({
      url: config.RUNLANE_DELIVERY_URL,
      secrets: { current: config.RUNLANE_DELIVERY_SECRET },
      publishTimeout: '1m',
      onFailure: (failure) => logger.error(failure.error, failure.phase),
    }),
    maxDuration: '50s',
    onFailure: (failure) => logger.error(failure.error, failure.phase),
  },
})
export const runlane = createRunlane({
  retention: {
    succeeded: RunRetention.deleteAfter('7d'),
    cancelled: RunRetention.deleteAfter('7d'),
    failed: RunRetention.deleteAfter('30d'),
    expired: RunRetention.deleteAfter('7d'),
  },
  lane,
  environment,
  queues: [jobs],
  tasks: [echo],
})

With runHints: false, realtime readers fall back to streams.pollInterval, whose default is contractDefaults.streams.pollInterval (1s). Updates can arrive in one-second bursts; lower the interval if needed.

The example validates environment variables at module load. Supply your app's logger and apply Postgres migrations before startup. Missing secrets and invalid URLs fail construction. Production URLs must use HTTPS. For loopback development only, set allowInsecureLocalhost: true and use a local URL.

For Redis or Valkey, use the same HTTP options with redisHttpLane():

import { redisHttpLane } from '@runlane/lane-redis-http'

const lane = redisHttpLane({
  redis: { url: redisUrl, namespace: 'runlane-jobs' },
  runHints: false,
  http: { ...httpOptions, lifetime: HttpLifetimeMode.InRequest },
})

Supply a validated redisUrl and the http options shown above as httpOptions. Follow the Redis durability and startup rules. Both factories expose operator reads and disable work hints because HTTP delivers work. runHints uses contractDefaults.realtime.runHints; set it to false on serverless hosts. Storage and HTTP options retain their owning packages' defaults. Keep database pools small and reuse one warm runtime per instance. Do not close the runtime after each request.

For a custom store, compose by hand with createLane({ storage, operatorReads, runSignal, queues: http.queues, delivery: { mode: LaneDeliveryMode.Transport, publisher: http.publisher, surface: http.surface } }), where http comes from createHttpDeliveryProvider({ ...httpOptions, lifetime: HttpLifetimeMode.InRequest }). Choose the lifetime explicitly for your host. The app owns the custom store's hint configuration and lifecycle.

Rotate signing keys

  1. Deploy receivers with secrets: { current: A, next: B }. They accept either key.
  2. Deploy senders with the same pair. Each request carries two space-separated signatures, one per key, so receivers still using A can verify it.
  3. Promote B to current and keep A as next during overlap. Wait for old senders, in-flight requests and the configured replay window to drain.
  4. Retire A by configuring only current: B on senders and receivers.

Keep separate secrets per endpoint and environment. Preserve raw request bytes when mounting the handler; JSON body middleware changes the signed input. See HTTP wire and authentication for header and signature rules.

Replies and capacity

lifetime is required. Neither mode is safe as a default for every app.

Choose lifetime: HttpLifetimeMode.InRequest ('in_request') on serverless or per-request hosts. It works on every supported host and holds the sending request open until the attempt finishes. await runlane.trigger() waits for publication, so a route that triggers work also waits for the attempt; it does not return immediately after saving the run. Parked workflows can resume in later requests.

On long-lived servers, choose lifetime: HttpLifetimeMode.Process ('process') for claim-time replies. Core claims the run in storage, then the handler replies 202 and releases its HTTP admission permit. The task continues in the app process. A duplicate or stale wakeup returns 204. A schedule wakeup replies 202 once its fire's run is saved, before that run's wakeup is published, so the publish does not wait for the slot the hint holds. Lifecycle-hook wakeups never use the run claim acknowledgment; they finish in-request and use the final disposition.

maxInFlight bounds body reading, signature verification and claiming. It does not bound tasks already acknowledged with 202. Core tracks active promises for shutdown. Worker concurrency does not cap these handlers. Bound execution with Runlane queue concurrency in storage and the host's execution limits. Without either limit, execution can grow without a per-process cap. Queue capacity applies across processes in the same environment.

The default maxInFlight is eight pre-claim requests. A short bounded admission queue absorbs brief contention before 429. Hook deliveries and other wakeups without acknowledgment keep a slot until their final disposition, so slow hooks can delay new claims. Outgoing POSTs have a separate shared limit of eight by default; each request timeout starts after it acquires a publishing slot. A 429 retries only the affected outbox message after the core retry delay and does not cool the whole endpoint. A 503 and endpoint configuration failures do start the process-local endpoint cooldown. Producers await publication, so claim-time replies let a parent publish children without waiting for child execution. Explicit process delivery supports nested triggers with one HTTP admission slot.

After core saves a run claim, client disconnects do not cancel execution in any lifetime mode. The storage lease remains authoritative. Before claim, a disconnect still stops delivery. Core attempt deadlines and explicit handler deadlines still apply. An in-request maxDuration expiry aborts with the task_interrupted Runlane error. A handler error then interrupts the attempt without spending a retry. See Stop crash loops for when Runlane requeues the attempt. How the next attempt is delivered depends on the adapter. See Continue across request budgets.

With lifetime: HttpLifetimeMode.InRequest, the handler waits for core's final disposition and holds admission through execution. Parents awaiting child publication need more incoming slots than their active nesting depth in this mode. Otherwise a child waits for admission, receives 429, and moves to the outbox retry delay. A due schedule wakeup counts the same way: it holds one slot while it publishes its new run. Set the adapter's publishTimeout above maxDuration plus contractDefaults.delivery.outboxSettlementReserve, with additional admission and startup margin. When both budgets are known, provider construction rejects a timeout at or below that sum. If no maxDuration is set, size the timeout above the expected attempt budget plus settlement. Otherwise the sender times out and retries its outbox row while the task continues. Duplicate POSTs are ignored while the lease is active. Prefer claim-time replies on hosts that support continued execution.

Nested child publication also needs outgoing capacity. Each active in_request parent holds one adapter publish slot while it awaits the response. If eight parents fill the default eight outgoing slots and each publishes a child, no child can send until a parent times out. Set maxConcurrentPublishes on createDirectHttpAdapter() above the maximum number of simultaneous in-request parents, leaving slots for children. Bound parent concurrency and keep spare incoming maxInFlight slots and storage-backed queue capacity for children too. For example, at most four parents with eight outgoing and eight incoming slots leave room for one level of child work. Deeper nesting needs more capacity. If you cannot bound nesting and concurrent parents, avoid nested triggers inside in-request handlers or use process delivery on a suitable host. A larger publishTimeout alone does not break this stall.

With a best-effort adapter such as direct HTTP, in_request leaves unrelated capacity refill to maintenance. Producer calls inside that request only try the runs they name. Queue controls inside the request save their changes without admitting unrelated backlog. They do not bypass older work, so an accepted child blocked by queue order or capacity waits for maintenance. The response covers this attempt and any child publication it can admit. Durable broker-backed adapters keep eager refill.

Calls made outside a delivery request keep the ordinary eager behavior. For example, trigger, triggerBatch, queues.resume, queues.setLimit, and queues.resetLimit admit ready runs in queue order and wait for their publication. In in_request mode, publication ends when the admitted run finishes. A trigger call can therefore wait for an older queued run on its key while its own run stays queued for maintenance. Opt into process lifetime on a long-lived server when callers must not wait for task execution. Keep maintenance running; a backlog can wait until its next pass. No work is launched after the response. This behavior is the same whether maintenance runs here or elsewhere. A parked workflow resumes through later deliveries; this HTTP response is not a promise that the entire workflow has finished.

Mount the handler

Mount the fetch handler using the host's Node.js request and lifetime APIs. Set duration, connection and concurrency limits for the deployed workload.

Next.js on Node

Set http.lifetime: HttpLifetimeMode.InRequest explicitly on Vercel; it needs no after or waitUntil hook. The request stays open for the attempt. Set http.maxDuration below the host limit and the adapter's publishTimeout above the expected attempt plus settlement margin.

Only when opting into claim-time background execution instead of in_request, bridge process-style lifetime through http.lifetime: (work) => after(() => work) from next/server, or (work) => waitUntil(work) from @vercel/functions. A bare process mode is unsafe on Vercel or Lambda: returning 202 can freeze the attempt. A callback lifetime cannot use http.maxDuration; remove that option and keep maxAttemptDuration below the host limit. Neither hook extends the host's maximum duration.

src/app/api/runlane/route.ts
// src/runlane.ts above sets http.lifetime: HttpLifetimeMode.InRequest.
import { runlane } from '../../../runlane'

export const runtime = 'nodejs'
export const maxDuration = 60
export const POST = runlane.createDeliveryHandler({ maxAttemptDuration: '45s' })

The provider has no required handler deadline. Core's maxAttemptDuration owns the attempt budget. Configure it below the deployed host limit, leaving time for settlement. Exporting a fetch handler does not make edge execution supported.

Hono on a long-running Node server

const lane = postgresHttpLane({
  postgres: postgresOptions,
  http: {
    lifetime: HttpLifetimeMode.Process,
    queues: [jobs],
    adapter: createDirectHttpAdapter({
      url: config.RUNLANE_DELIVERY_URL,
      secrets: { current: config.RUNLANE_DELIVERY_SECRET },
    }),
  },
})
const runlane = createRunlane({ ...runlaneOptions, lane })
const handler = runlane.createDeliveryHandler()
app.post('/runlane', (c) => handler(c.req.raw))

Use Hono's Node server adapter. Opt into http.lifetime: HttpLifetimeMode.Process for early replies while that server process remains alive. Promises alone do not provide a serverless lifetime guarantee. On SIGTERM, stop accepting HTTP requests and await runlane.close() before exiting. Close waits for admitted work; a hard kill relies on lease recovery.

Express

Mount before JSON or other body middleware; signatures require the original bytes.

import { getRequestListener } from '@hono/node-server'

const lane = postgresHttpLane({
  postgres: postgresOptions,
  http: {
    lifetime: HttpLifetimeMode.Process,
    queues: [jobs],
    adapter: createDirectHttpAdapter({
      url: config.RUNLANE_DELIVERY_URL,
      secrets: { current: config.RUNLANE_DELIVERY_SECRET },
    }),
  },
})
const runlane = createRunlane({ ...runlaneOptions, lane })
const handler = runlane.createDeliveryHandler()
const listener = getRequestListener(handler)
app.post('/runlane', (request, response, next) => {
  void listener(request, response).catch(next)
})

The maintained Hono Node adapter bridges Node request/response objects and fetch. The app owns server startup and shutdown; createDeliveryWorker() is unsupported and points callers to createDeliveryHandler().

Other Node hosts

HostLifetime guidance
Cloud RunWith request-based CPU, use HttpLifetimeMode.InRequest and set both publishTimeout and the host request timeout above maxAttemptDuration plus margin. A sender timeout can end the request while claimed work continues; request-based CPU is not a background execution guarantee. Use instance-based billing for CPU outside requests, with shutdown draining and queue limits. A host timeout closes the connection without terminating the container. Background activity, request timeout (checked 2026-11-07).
Lambda function URLsBuffered invocation must use in_request with a URL-event-to-fetch bridge preserving raw/base64 bytes. Exporting a fetch handler directly as a Lambda event handler is invalid. Continuing after a buffered return is unsafe. A streaming bridge must own response completion and invocation lifetime. Execution lifecycle.

Netlify Functions are outside this handler's supported host contract.

Limit unauthenticated traffic

Rate-limit the delivery route at your reverse proxy, load balancer or host ingress before requests reach the app. Invalid signatures still consume body-read, verification and admission capacity. HMAC authentication and maxInFlight do not provide a request-rate limit. Allow enough burst capacity for the configured outgoing POST limit and expected retries; do not trust an unverified message ID as a rate-limit identity.

Run maintenance and recover failures

Run a long-lived runlane.start({ maintenance: true }) service or invoke runlane.createMaintenanceHandler() from an authenticated recurring scheduler. The delivery endpoint does not run a maintenance pass for every POST. Maintenance and producers must register the same queues and task schedules.

A lost 202 response can cause another POST. Core ignores a duplicate while its lease is active or after completion. If the worker dies after 202, the stored lease and maintenance recover the same run. Recovery latency includes the remaining lease, the next maintenance pass, and backlog. The default lease is five minutes. A lost wakeup without a run claim uses the resendQueuedRunsAfter setting, which defaults to contractDefaults.maintenance.resendQueuedRunsAfter (15 minutes). See workers and leases.

Endpoint errors such as 401, 404, redirects or an unexpected 200 are retryable and reported to the failure observer at error level. The sender cools that endpoint rather than dead-lettering a new row for each recovery. Fix the secret, route or host configuration. Core retries the same failed outbox row after its fixed retry delay. Cooldown is process-local and does not promise durable scheduling across restarts.

Message failures (413, 415, 422) are non-retryable and dead-letter their outbox row. A network timeout or lost response is ambiguous: core retries, even if the first request claimed or completed the run. It does not prove the remote task stopped. Core owns task retry/backoff decisions; a saved task failure or retry returns Handled, not an HTTP task-error retry. Make external effects safe to repeat.

Prefer scheduled Postgres polling when waiting for the next timer is acceptable. Its createDeliveryHandler({ maxDuration }) drains storage and is a different handler shape.

Continue across request budgets

An in_request handler bases its handoff time on maxDuration. With a best-effort adapter such as direct HTTP, the handler leaves the continuation and any new child wakeups for maintenance and replies without waiting for another attempt. With a durable adapter, the handler tries to publish those wakeups before it replies.

Reaching maxDuration uses the platform-time-limit abort reason. maxDuration keeps its existing option and default. See Stop crash loops.

Reserve time for handoff

Set handoffBefore in the HTTP provider options beside maxDuration. It hands work to a fresh invocation at the next step boundary after that much time remains. Saved steps are replayed rather than run again. The reserve gives the current step time to finish and Runlane time to save progress and arrange continuation before the host deadline.

When unset, Runlane reserves 25% of the invocation budget (contractDefaults.delivery.handoffReserveFraction). A duration such as handoffBefore: '30s' reserves that much time instead. Choose a positive duration that covers your longest step plus storage and continuation time. A value at least as large as the whole budget makes handoff eligible from the start. Handoff still requires a new saved step in this attempt: handlers without saved steps never stop early for handoff.

Set handoffBefore: false to turn off step-boundary handoff. Work then runs until completion, a caller or task deadline, or the platform time limit. This does not extend the host's execution budget.

HTTP handoff applies to in_request execution with maxDuration. Direct HTTP accepts long publishTimeout values, such as 16m; core extends its outbox claim to cover the timeout plus settlement time, with the default lease as the minimum.

On this page