Skip to Content
Runlane
Run in production

Deploy with Redis Streams

Store run state in Redis or Valkey and use Streams to wake long-running workers.

Choose this lane when you want Redis or Valkey to hold both run state and delivery wakeups. Use Redis polling for direct storage acquisition, or Redis and SQS for SQS-triggered Lambda workers.

Deployment shape

producer --> Redis (run + outbox)
                 |
                 v
publisher --> Redis Streams --> worker
                                 |
                                 v
                            Redis storage

maintenance --> due work, outbox publishing, and recovery

Runlane stores the run and pending wakeup together. The publisher sends the wakeup to a Stream. Workers read current storage before claiming or executing a run. A duplicate or late wakeup does not create another run.

Prepare Redis

Storage and transport support standalone, Sentinel, and Cluster. Each namespace lives on one primary. Cluster does not divide one namespace's workload among primaries.

Use noeviction; an observed allkeys-* policy fails storage startup. Review startup checks, durability, and deployment requirements. Streams also needs consumer-group, pending-entry, claim, acknowledgment, and deletion commands.

Choose storage and transport namespaces explicitly. The example uses one endpoint with separate namespaces. transport.connection can select another deployment; both deployments need suitable settings and capacity. Storage startup creates its marker in an empty namespace. There is no Redis migration CLI.

Install the packages

npm install @runlane/core @runlane/lane-redis-streams zod

Use Node.js 22.18 or later and set REDIS_URL before loading the runtime module. Reuse the task module from the polling guide as src/tasks/count-items.ts.

Create one runtime module

src/runlane.ts
import { createRunlane, RunRetention, queue } from '@runlane/core'
import { redisStreamsLane } from '@runlane/lane-redis-streams'
import * as z from 'zod'

import { countItems } from './tasks/count-items.js'

const { REDIS_URL } = z.object({ REDIS_URL: z.url() }).parse(process.env)
export const jobs = queue({ name: 'jobs', default: true })

export const runlane = createRunlane({
  retention: {
    succeeded: RunRetention.deleteAfter('7d'),
    cancelled: RunRetention.deleteAfter('7d'),
    failed: RunRetention.deleteAfter('30d'),
    expired: RunRetention.deleteAfter('7d'),
  },
  lane: redisStreamsLane({
    redis: { url: REDIS_URL, namespace: 'billing-jobs' },
    transport: { namespace: 'billing-wakeups', queues: [jobs] },
  }),
  queues: [jobs],
  tasks: { countItems },
})

The same queue definition belongs to the runtime and transport. All producers, workers, and publishers must agree on those bindings. See Streams lane options for a separate connection and delivery settings.

Start a worker

Run this entry point as a long-running Node.js service. The Streams lane supplies createDeliveryWorker(); it has no native Lambda event handler.

src/worker.ts
import { runlane } from './runlane.js'

const worker = await runlane.createDeliveryWorker({ concurrency: 8, handleSignals: true })
try {
  await worker.waitUntilClosed()
} finally {
  await runlane.close()
}

Close stops acquisition and gives active attempts their shutdown grace. Keep the process alive until close finishes. A supervisor should restart failed workers. Each worker uses separate acquisition and settlement connections; Cluster may open connections to discovered nodes. Run-progress readers can also open the storage driver's shared pub/sub listener.

Bound the delivery backlog

Each logical queue has one Stream and one fixed consumer group, shared by all workers. Do not add another group or trim these Streams yourself. Successful terminal settlement acknowledges and deletes the entry together, after checking the current consumer and delivery generation. A stale worker cannot delete its successor's receipt.

maxBacklog bounds unread plus pending entries in each queue. A full queue rejects new wakeups with a retryable publish failure, so the outbox can try later. It does not discard old entries. Set an alert on growing backlog and outbox age; increase worker capacity or correct the failing handler before increasing the ceiling.

Multi-queue workers check for existing unread entries in the selected streams together, then claim messages only within free worker capacity. Queue order rotates, and fresh and pending work alternate first use of capacity. A busy worker leaves other messages available for idle peers. blockMs controls the pause between multi-queue idle checks; close interrupts that pause. Single-queue workers instead block on that stream for up to blockMs, so new work wakes them immediately. Close observes the bounded read and drains any acquired messages through shutdown grace.

Receipt renewal runs every third of the visibility duration, measured from request send times so reply latency does not move the retry cadence. A connection error is recorded and retried without immediately aborting delivery. The local safety deadline is the last confirmed acquisition or renewal’s monotonic send time, plus visibility duration, minus one renewal interval. Proven ownership loss stops delivery immediately; continued failures stop it after that deadline. A renewal whose planned slot is at or before the deadline is sent even if its timer wakes late. Its reply may arrive after that deadline. It must confirm before the hard bound: the last confirmed send plus the full visibility duration. At that bound, Runlane gives up even if the request is still in flight. A late success cannot restore ownership. Immediate renewal after a late blocking receive uses the same send-anchored visibility bound and stops on worker cancellation. A stalled request cannot hold delivery capacity past that bound.

Active receipts renew their visibility. Abandoned receipts become eligible for reclamation after visibilityTimeoutMs. Reclaim scans follow that interval. These settings are separate from the run's storage lease. See transport options.

The transport reports best_effort publish durability and none ordering. It offers no native delay or publish deduplication. Core keeps future wakeups in storage until due and checks every delivery against stored state. See delivery values.

Keep maintenance running

Maintenance must publish due outbox work and recover missed wakeups. The worker above runs it. To use a separate service, set maintenance: false on createDeliveryWorker() and give that service start({ maintenance: true }). For scheduled maintenance, export runlane.createMaintenanceHandler().

Keep the DeliveryRecovery and OutboxFlush phases enabled. A live Streams consumer alone cannot replace them. See run maintenance.

runHints uses the shared realtime default. Disable it on producers or readers that should not use pub/sub. It does not disable Streams delivery. Streams delivers work, so the lane forces storage workHints: false and rejects that option at the top level or inside redis. See Redis hints.

Check the deployment

Use an isolated storage namespace and transport namespace:

  1. Start the worker and its maintenance owner.
  2. Trigger countItems with two items and confirm stored output 2.
  3. Stop a worker during delivery and confirm another worker reclaims the receipt and recovers the run.
  4. Fill a small test backlog and confirm new wakeups remain retryable without losing accepted runs.
  5. Check task and queue compatibility before a rolling deployment. All consumers of one queue must understand its task catalog.

Make external effects safe to repeat and follow change tasks safely.

On this page