
v0.9.0Background tasks. Your infrastructure.
Runlane is a TypeScript task engine for infrastructure you own. Write tasks once, then run them locally, on AWS Lambda, in long-running workers, or behind your own HTTP route. Store runs in Postgres, Redis, or Valkey.
Write a task, trigger it
Define typed inputs and outputs. Accept work from your app, then let a separate worker execute it.
import { task } from '@runlane/core'
import * as z from 'zod'
export const greet = task({
id: 'greet',
schema: z.object({ name: z.string().min(1) }),
output: z.string(),
run: ({ name }) => `Hello, ${name}!`,
})import { Hono } from 'hono'
import * as z from 'zod'
import { runlane } from './runlane.js'
const app = new Hono()
const requestSchema = z.object({ name: z.string().min(1) })
app.post('/greetings', async (c) => {
const body: unknown = await c.req.json().catch(() => null)
const input = requestSchema.safeParse(body)
if (!input.success) return c.json({ error: 'A name is required.' }, 400)
const { run } = await runlane.trigger(runlane.tasks.greet, input.data)
return c.json({ runId: run.id }, 202)
})
export default app202 means the run was accepted. A worker executes it and stores the result and attempt history. Keep runtime creation outside the request handler, and apply your app's authentication and rate limits.
Run your first task · Use Hono
See it run
Pick a feature to watch a run move through the local lane. The terminal shows what runlane dev and the CLI print for that task.
npx runlane trigger dx.proberunlane dev- No runs yet
Pick a failure mode to trigger the task.
Task code: src/tasks/dx-probe.ts
import { ErrorCode, RetryBackoffType, RunlaneError, task } from '@runlane/core'
import * as z from 'zod'
// Demo only: this set resets when dev reloads or restarts.
const seen = new Set<string>()
export const dxProbe = task({
id: 'dx.probe',
schema: z.object({
mode: z.enum(['once', 'always', 'permanent', 'reload']),
key: z.string(),
}),
retry: {
maxRetries: 2,
backoff: { type: RetryBackoffType.Exponential, delay: '1s', maxDelay: '2s' },
},
run({ mode, key }) {
if (mode === 'permanent') {
throw new RunlaneError({ code: ErrorCode.TaskFailed, message: 'Bad input', retryable: false })
}
if (mode === 'always') throw new Error('Provider is down')
if (mode === 'once' && !seen.has(key)) {
seen.add(key)
throw new Error('Provider timed out')
}
// Change this value while dev runs to reload the worker.
return { version: 'before' }
},
})
Supported lanes
A lane connects storage and delivery. Keep your task and trigger code when you change lanes.
Local
Use createLocalLane() with runlane dev for development. Dev owns the in-memory runs; stopping it clears them.
Test
Use createTestLane() from @runlane/lane-local for in-process tests without dev.
Postgres polling
Use @runlane/lane-postgres-polling for durable runs with Postgres and no message broker. Run workers continuously
or on a schedule.
Postgres + SQS
Use @runlane/lane-postgres-sqs for SQS-triggered Lambda or always-on consumers. Postgres stores the runs; SQS
delivers wakeups.
Redis polling
Use @runlane/lane-redis-polling to store runs in Redis or Valkey. Workers claim work straight from storage, with
no message broker.
Redis Streams
Use @runlane/lane-redis-streams when Redis or Valkey stores the runs and Redis Streams wakes long-running workers.
Redis + SQS
Use @runlane/lane-redis-sqs for SQS-triggered Lambda or always-on consumers. Redis or Valkey stores the runs; SQS
delivers wakeups.
HTTP push
Use @runlane/transport-http to send signed wakeups to a route in your app, such as Next.js or Hono. Pair it with
Postgres or Redis storage. No broker needed.
Build your own lane
Core owns retries, waits, leases, and schedules. A provider stores records and delivers wakeups.
Providers implement storage (get, query, withTransaction) and delivery (publish, createWorker, and an optional native createHandler). Check atomic writes and reliable delivery with the provider conformance suites and tests against your real service.
Swap the lane, keep the task
The tabs show the same runtime after importing and configuring each provider. Only the lane: line changes inside createRunlane().
import { createRunlane, RunRetention, queue } from '@runlane/core'
import { createLocalLane } from '@runlane/lane-local'
import { greet } from './tasks/greet.js'
const defaultQueue = queue({ name: 'default', default: true })
export const runlane = createRunlane({
retention: {
succeeded: RunRetention.deleteAfter('7d'),
cancelled: RunRetention.deleteAfter('7d'),
failed: RunRetention.deleteAfter('30d'),
expired: RunRetention.deleteAfter('7d'),
},
lane: createLocalLane(),
queues: [defaultQueue],
tasks: { greet },
})Same trigger on every lane: await runlane.trigger(runlane.tasks.greet, { name: 'Ada' }). Local development uses runlane dev. Postgres lanes keep runs across restarts. Redis lanes keep them when the server saves data to disk or uses a durable managed service; see Redis durability. The namespace keeps one app's runs apart from others on the same Redis server.
Choose a lane · Understand lanes
Serverless or always-on
Serverless
Postgres polling can run maintenance and drain due work in a scheduled function. Start latency follows the timer interval; each run must fit within the function timeout.
export const handler = runlane.createDeliveryHandler({
maxDuration: '50s',
})For an SQS-triggered Lambda, use the lane's native handler:
export const handler = runlane.createDeliveryHandler()For HTTP push, export the fetch handler as a route. Runlane sends a signed POST, the handler claims the run, and an explicit in_request lifetime holds the request open for the attempt:
import { postgresHttpLane } from '@runlane/lane-postgres-http'
import { createDirectHttpAdapter, HttpLifetimeMode } from '@runlane/transport-http'
const lane = postgresHttpLane({
postgres: { connectionString: databaseUrl },
runHints: false,
http: {
lifetime: HttpLifetimeMode.InRequest,
queues: [jobs],
adapter: createDirectHttpAdapter({ url: deliveryUrl, secrets: { current: deliverySecret }, publishTimeout: '1m' }),
maxDuration: '50s',
},
})Use this lane in your runtime configuration, then mount its handler:
// runlane uses the explicit HttpLifetimeMode.InRequest lane above.
export const runtime = 'nodejs'
export const POST = runlane.createDeliveryHandler({ maxAttemptDuration: '45s' })Use postgresHttpLane() or redisHttpLane() to compose storage and HTTP. lifetime is required. in_request works on every supported host, but the sending request and await runlane.trigger() wait for the attempt. Set publishTimeout above maxDuration plus settlement. Nested child publication needs more outgoing maxConcurrentPublishes slots than concurrent in-request parents, plus spare incoming and queue capacity; otherwise avoid nested triggers. process replies 202 at claim and continues in the app process, so use it only on long-lived servers or with the host's after/waitUntil lifetime callback. The in-request example needs neither hook. See HTTP delivery for other hosts.
Schedule maintenance separately for SQS and HTTP push:
export const handler = runlane.createMaintenanceHandler()Set runHints: false on serverless runtimes to skip the realtime listener connection. 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.
Always-on
Run polling, Redis Streams, or SQS workers in containers and VMs. Use this path for tasks that outlive a function invocation. A long-running Hono or Express server can also receive HTTP push wakeups.
const worker = await runlane.createDeliveryWorker({ handleSignals: true })
try {
await worker.waitUntilClosed()
} finally {
await runlane.close()
}Maintenance moves due work forward and recovers interrupted runs. Keep it running with your workers. Postgres lanes keep run state and worker claims across restarts. Redis lanes follow their durability settings.
Use Node.js 22.18+ and give each host access to its lane's services. SQS producers also need AWS access.
Where Runlane runs · Run polling workers on a schedule
Feature tour
Trigger work on your terms
Delay a run with runAt, reuse a logical request with an idempotency key, or submit a batch. Batch results report acceptance or failure for each item.
await runlane.trigger(
runlane.tasks.greet,
{ name: 'Ada' },
{
runAt: new Date(Date.now() + 60_000),
idempotencyKey: 'welcome.ada',
},
)
const { outcomes } = await runlane.triggerBatch([
{ task: runlane.tasks.greet, payload: { name: 'Ada' } },
{ task: runlane.tasks.greet, payload: { name: 'Grace' } },
])
for (const item of outcomes) {
if (!item.ok) throw item.error
}Durable steps. Safe side effects.
Save a step's output and reuse it on replay. Use stable item IDs in step keys. Pass its stable token to an API that supports idempotency; a remote call can succeed before the result is saved, so non-idempotent APIs can still repeat.
const jobSchema = z.object({ id: z.string() })
const job = await context.step.run('submit-job', { output: jobSchema }, async ({ token }) => {
const response = await fetch(providerUrl, {
method: 'POST',
headers: { 'idempotency-key': token },
signal: context.signal,
})
if (!response.ok) throw new Error(`Provider returned ${response.status}`)
return jobSchema.parse(await response.json())
})Retry with a budget
Automatic retries are opt-in. Give temporary failures a bounded retry count and exponential backoff.
import { RetryBackoffType, task } from '@runlane/core'
import * as z from 'zod'
export const greet = task({
id: 'greet',
schema: z.object({ name: z.string() }),
output: z.string(),
retry: {
maxRetries: 3,
backoff: {
type: RetryBackoffType.Exponential,
delay: '30s',
maxDelay: '5m',
},
},
run: ({ name }) => `Hello, ${name}!`,
})Wait for time, a signal, or a person
Pause without counting a failure or holding a worker slot. Signals wake current waiters; wait tokens store a durable decision for human approval.
await context.step.sleep('pause', '1m')
await context.step
.waitForSignal('ready', 'account_123', {
timeout: '1h',
})
.unwrap()
const { token } = await context.wait.createToken({ timeout: '7d' })
const decision = await context.wait
.forToken(token.id, {
output: z.object({ approved: z.boolean() }),
})
.unwrap()Put recurring work on a schedule
Use cron, intervals, or a one-time date. Maintenance creates due runs; workers execute them.
await runlane.schedules.create(runlane.tasks.greet, {
cron: '0 9 * * 1-5',
timeZone: 'America/New_York',
payload: { name: 'Ada' },
externalId: 'weekday-greeting',
})Share capacity across workers
Queue limits apply across the environment. Bound total work and per-account work together; worker concurrency separately limits one process.
import { queue } from '@runlane/core'
export const jobs = queue({
name: 'jobs',
concurrency: { total: 20, perKey: 2 },
})Trigger a child. Wait for its result.
Named child steps reuse the same child on replay. Joining releases the parent's queue slot while it waits; cancelling a waiting parent cancels its unfinished awaited children unless another registered waiter or another parent's named binding protects them. See cancellation rules.
const child = await context.step.trigger('greet-child', greet, { name: 'Ada' })
const result = await context.join(greet, child)
if (result.ok) return result.output
throw new Error(result.error.message)Bring tasks into your app
Show status, metadata, saved streams, and typed output with React 19 hooks. Realtime reads durable state, so reconnecting clients can catch up; your server authorizes which runs and fields they can read.
'use client'
import { useRun } from '@runlane/react'
import type { greet } from './tasks/greet.js'
export function RunStatus({ runId }: { runId: string }) {
const { run, error } = useRun<typeof greet>(runId)
if (error) return <p>Could not load the run.</p>
if (!run) return <p>Loading…</p>
return (
<p>
{run.status}: {run.output}
</p>
)
}Everything else, in one place
Production
- Timeouts
- Cancellation
- Deduplication
- Safe deploys: keep task changes compatible with in-flight runs.
- Lifecycle hooks
- Pruning
Put your background work in motion
Bring your libraries, APIs, and business logic. Runlane coordinates when they run, retry, or wait.
AI streaming
Stream an AI answer to your app word by word, with no request timeouts.
AI agents
Search documentation and require approval for sensitive tools.
Media generation
Generate structured content and an accompanying image.
Email sequences
Send an onboarding sequence over several days.
Human approval
Pause for a decision, then publish or reject the result.
Explore all recipes for semantic search, browser automation, Python, media processing, marketing, schedules, concurrency, and retries.
Works with your existing tech stack
Trigger from any Node.js framework. Keep one shared runtime outside request handlers.
- Hono: return
202with a run ID from a route; read the Hono recipe. - Next.js: trigger from server code, run tasks in a route with HTTP push, and show live progress with realtime.
- AWS Lambda and Fargate: mix serverless tasks and long-running container workers in one deployment.
Other Node.js serverless hosts can trigger runs. To run tasks there, use HTTP push or a scheduled polling drain; see the support matrix.
Open source at v1
You can install and use the Runlane packages from npm today under the Apache 2.0 license. The source repository is private for now. We will make it public on GitHub with the v1 release.