Runtime capabilities, queues, and schedules

Choose how work is delivered and trace it from the initial write to the worker that runs it.

Access infrastructure in a handler

Handlers obtain capabilities through the application context. For example, await app.cache() returns the cache interface. Platform selects the driver for the runtime. Registered capabilities include databases, object storage, cache, email, translation, AI, queues, and scheduling. Each initializes on first use, and concurrent calls on the same app instance share initialization.

const cache = await app.cache();
const value = await cache.get(key);

Decide what should happen after a save

Say an editor saves an article that needs a translation. Define what “saved” means for the editor, then track the job and check the translated content separately. The business write, enqueue operation, and handler execution can each fail at different points.

Mechanism Use it for Where to look when it fails
Persistent job Work that needs tracking or recovery Inspect the record and dispatch and consumer logs. The heartbeat can recover eligible dispatch failures
Direct job Work that can tolerate a single dispatch attempt Trace enqueue errors and consumer logs
Schedule Work that should start at a specified time or recur Check the scheduling trigger and downstream consumption

A persistent job using an idempotencyKey also requires a stable intentFingerprint. Reusing the key for a different intent causes a conflict. To commit a job record with business writes, use queue prepare, commit the batch, and call dispatch.

flowchart LR
  accTitle: From saving a business record to executing the job handler
  A["Save the business record"]
  B["Dispatch the job"]
  C["Consumer runs the handler"]
  D["Check the result"]
  A --> B --> C --> D

Match the queue to the deployment

A single Node development process can use an in-memory queue. A Node deployment that separates dispatch from consumption requires Redis. Workers uses Cloudflare Queues, so verify producer bindings and consumer configuration. After deployment, exercise a real handler and check the result it writes. See deployment options and platform capabilities.

For a cache or upload integration, continue with cache and object storage.