Skip to content

Durability

Durability is an open-source toolkit for SQLite-backed Cloudflare Durable Objects. Its main package persists operations and logical alarms, retries failures, deduplicates stable IDs, and exposes typed results while sharing the Durable Object’s single physical alarm safely.

Terminal window
npm install durability

Durable operations

Register work and its earliest wake-up in one storage transaction.

Named alarms

Schedule independent logical alarms through one physical Durable Object alarm.

Typed RPC transforms

Compose caller and callee behavior around Durable Object and Worker RPC.

Safety tooling

Enforce alarm ownership and reversible SQLite migrations with Oxlint.
import { DurableObject } from 'cloudflare:workers';
import { createDurability, type DurableHandler } from 'durability';
type ResizeInput = { imageId: string };
export class ImageJobs extends DurableObject<Env> {
private readonly durability = createDurability(this.ctx, {
resizeImage: (async ({ id, payload, signal }) => {
return this.env.IMAGES.resize(payload.imageId, {
idempotencyKey: id,
signal,
});
}) satisfies DurableHandler<ResizeInput, string>,
});
resize(imageId: string) {
return this.durability.resizeImage({
id: `resize:${imageId}`,
payload: { imageId },
});
}
alarm(info?: AlarmInvocationInfo) {
return this.durability.alarm(info);
}
}

The generated operation method resolves after registration commits. It does not wait for the handler result.

  • Cloudflare Workers and a SQLite-backed Durable Object.
  • JSON-serializable operation payloads and results.
  • Direct delegation of the class alarm() method to Durability.
  • Stable operation IDs and idempotent external effects.

Continue with the quickstart, named alarms, or package map.