Alarms API: Scheduled Handlers, Retries, and Storage Cleanup
How Cloudflare Durable Object alarms schedule future work, retry on failure, compare to Cron Triggers, and clear storage with deleteAll.
This page summarises Cloudflare documentation on Durable Object alarms: waking a single object at a future time without an HTTP or RPC request, running an alarm() handler, and tying alarms to the Storage API for cleanup and billing. The cluster also includes Chrome extension browser.alarms; that API solves a different problem (periodic tasks in an extension service worker) and is noted only where the ideas overlap.
Durable Object alarms: what they are and when to use them
Section titled “Durable Object alarms: what they are and when to use them”Durable Object alarms let you schedule the object to run code later. Alarms are not the only entry point—a Durable Object can still receive HTTP, RPC, or WebSocket traffic—but they are how you keep work moving when no request arrives.
Durable Objects alarms allow you to schedule the Durable Object to be woken up at a time in the future. When the alarm’s scheduled time comes, the alarm() handler method will be called. Alarms are modified using the Storage API, and alarm operations follow the same rules as other storage operations.
— Cloudflare, Alarms
Use alarms when you need per-instance timing: end a game session, renew a subscription, batch requests, implement a TTL, or finish work after a delay. Cloudflare Agents document the same pattern: schedule with this.ctx.storage.setAlarm(), then implement alarm().
Alarms differ from Worker Cron Triggers in granularity and control:
| Durable Object alarms | Cron Triggers | |
|---|---|---|
| Scope | One alarm per Durable Object instance; unlimited objects | Up to three crons per Worker script |
| Scheduling | setAlarm() from inside the object |
Dashboard or API schedule only |
| Typical use | Per-entity deadlines, queues, batching | Fixed wall-clock jobs on the Worker |
Alarms are more fine grained than Cron Triggers… Alarms are directly scheduled from within your Durable Object. Cron Triggers, on the other hand, are not programmatic.
— Cloudflare, Alarms
setAlarm, getAlarm, and deleteAlarm: one alarm per object
Section titled “setAlarm, getAlarm, and deleteAlarm: one alarm per object”Each Durable Object may have only one alarm scheduled at a time. You schedule it through the Storage API on DurableObjectState (ctx.storage).
setAlarm: schedule or replace the next run
Section titled “setAlarm: schedule or replace the next run”setAlarm(scheduledTimeMs) takes milliseconds since the UNIX epoch. A new call overrides any existing alarm.
Set the time for the alarm to run. Specify the time as the number of milliseconds elapsed since the UNIX epoch. If you call setAlarm when there is already one scheduled, it will override the existing alarm.
— Cloudflare, Alarms — setAlarm
On SQLite-backed and legacy KV-backed storage, if the time is at or before Date.now(), the alarm runs asynchronously “in the immediate future.” Execution is usually within milliseconds but can be delayed up to about a minute during maintenance or failover.
Alarms do not repeat by themselves. After alarm() runs, call setAlarm() again if you need another fire—see Rules of Durable Objects.
getAlarm: read the pending time
Section titled “getAlarm: read the pending time”getAlarm() returns the scheduled time in ms, or null if none is set. While an alarm handler is already running, getAlarm() returns null unless setAlarm was called again since the handler started—useful when deciding whether to arm a batching window in fetch().
deleteAlarm: cancel a pending alarm
Section titled “deleteAlarm: cancel a pending alarm”deleteAlarm() unsets a scheduled alarm. Calling it inside alarm() may prevent retries on a best-effort basis but is not guaranteed. Prefer handling retries explicitly in the handler (below).
The alarm() handler: execution, retries, and alarmInfo
Section titled “The alarm() handler: execution, retries, and alarmInfo”When the scheduled time is reached, the runtime invokes your class’s alarm() method (see Durable Object base class).
Only one instance of alarm() will ever run at a given time per Durable Object instance.
— Cloudflare, Alarms — alarm
Delivery is at-least-once. Uncaught exceptions trigger automatic retries with exponential backoff starting at 2 seconds, up to 6 retries, and only for the most recent setAlarm() call.
The alarm() handler has guaranteed at-least-once execution and will be retried upon failure using exponential backoff, starting at 2 second delays for up to 6 retries.
— Cloudflare, Alarms — alarm
The optional alarmInfo argument (also typed as AlarmInvocationInfo on the base class) exposes retryCount and isRetry. Use it to log retries or, near the retry limit, schedule a fresh alarm so work is not abandoned after six failures.
Make handlers idempotent: rare duplicate deliveries should not double-charge or double-send. Check storage state before mutating, as in the subscription example in Rules of Durable Objects.
Multiple scheduled events with a single alarm
Section titled “Multiple scheduled events with a single alarm”You cannot stack several independent setAlarm times on one object. The usual pattern is to store many logical events in storage (for example keys prefixed event:), run due items in alarm(), then setAlarm for the earliest future event. Cloudflare’s Alarms page includes a full AgentServer example that reschedules after processing due events and supports optional repeatMs.
For request batching, see Use the Alarms API: the first request in a quiet period sets a 10-second alarm; further requests join the batch until alarm() flushes storage.
Calling setAlarm in the constructor
Section titled “Calling setAlarm in the constructor”If the object wakes from hibernation for an alarm, the constructor runs before alarm(). Blind setAlarm in the constructor can wipe the pending alarm you intended to fire.
If you wish to call setAlarm inside the constructor of a Durable Object, ensure that you are first checking whether an alarm has already been set.
— Cloudflare, Alarms — Calling setAlarm inside the constructor
The Durable Object TTL example extends lifetime on each fetch() instead of naively resetting TTL in the constructor—same underlying rule.
Storage cleanup: deleteAlarm, deleteAll, and billing
Section titled “Storage cleanup: deleteAlarm, deleteAll, and billing”Writing to storage—including setting an alarm—means the object is not “empty.” To remove the instance’s persisted footprint you must clear all storage metadata, not only user keys.
However if you ever write using Storage API, including setting alarms, then you must explicitly call storage.deleteAll() to empty storage and storage.deleteAlarm() if you’ve configured an alarm. It is not sufficient to simply delete the specific data that you wrote… The only way to remove all storage is to call deleteAll().
— Cloudflare, Access Durable Objects Storage
A Durable Object fully ceases to exist after shutdown only when storage is empty; deleteAll() also stops storage billing for that object.
Compatibility date 2026-02-24 and later (or compatibility flag delete_all_deletes_alarm): deleteAll() also clears the active alarm, so one call replaces the older two-step sequence.
deleteAll() now deletes a Durable Object alarm in addition to stored data for Workers with a compatibility date of 2026-02-24 or later.
— Cloudflare, deleteAll() now deletes Durable Object alarm
On earlier dates, call deleteAlarm() before deleteAll(), or enable delete_all_deletes_alarm. KV-backed deleteAll() can theoretically leave partial data on failure; SQLite-backed deleteAll() is atomic (legacy KV storage API, SQLite storage API).
TTL-style cleanup often ends with alarm() calling deleteAll(); pair with ctx.abort(..., { retryAlarm: false }) when you reset the object and must not retry the alarm (next section).
ctx.abort() and retryAlarm
Section titled “ctx.abort() and retryAlarm”ctx.abort() immediately resets the Durable Object. By default, an alarm interrupted by abort retries after reset—which is usually what you want so an unrelated abort does not permanently cancel scheduled work.
Pass { retryAlarm: false } when the alarm should stop after abort (typical cleanup + self-destruct):
By default, an alarm interrupted by ctx.abort() retries after the Durable Object resets. Pass
{ retryAlarm: false }when the alarm should stop instead.— Cloudflare, Prevent Durable Object alarm retries when using ctx.abort()
Alarms can run concurrently with other requests; any abort on those paths should set retryAlarm: false when you intend to cancel an in-flight alarm. Details: Durable Object State — abort. Local testing of retryAlarm needs Wrangler 4.126.0 or later per the same changelog.
Costs, limits, and operational pitfalls
Section titled “Costs, limits, and operational pitfalls”- Cost: Rules of Durable Objects warn against waking every object on short intervals—each alarm invocation has cost; schedule only when there is work.
- Local dev: After a hot reload in
npx wrangler dev, alarm methods may fail until you restart Wrangler (Known issues). - SQLite history: Alarms were briefly disabled in beta SQLite classes in 2024 and re-enabled after a fix (Release notes).
- deleteAll in alarm: A 2024 Workers changelog notes a fix for exceptions when calling
deleteAll()during a SQLite alarm handler (Workers platform changelog).
Chrome extension alarms (different platform)
Section titled “Chrome extension alarms (different platform)”If you are building a Manifest V3 extension, browser.alarms schedules work in the service worker when setTimeout would be killed on termination—see Migrate to a service worker and Handle events with service workers. Chrome allows many named alarms (limit 500 active), enforces roughly once per second minimum spacing, and uses onAlarm listeners (browser.alarms). That model does not share state with Cloudflare Durable Objects; only the idea—“persist scheduled callbacks across restarts”—is analogous.
How to check this on your site
Section titled “How to check this on your site”-
Deploy or run locally with Wrangler and confirm your Worker’s compatibility date relative to
2026-02-24so you know whetherdeleteAll()alone clears alarms (compatibility flags, changelog). -
Exercise the object (HTTP/RPC), then call
getAlarm()or inspect logic that mirrors the Alarms API example to verify an alarm is set when expected and not duplicated from the constructor. -
Use
runDurableObjectAlarm()fromcloudflare:testin a Vitest test to runalarm()immediately and assert storage side effects without waiting on wall-clock time. -
After a cleanup path, confirm storage is empty (and alarm cleared per your compatibility settings) so the object can shut down without continued storage billing, following Access Durable Objects Storage.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about so it can be corrected quickly.