Does setInterval keep a worker alive? Observing if durable object is alive

I want to be able to observe if a given durable object ID is currently active (if it’s websocket connection is still active).

The issue is that I cannot send it a request to find out, as the system will boot another instance if it is not active. I also do not want to generate a lot of needless requests to keep costs low.

How can I observe this?

I am thinking I can use a setInterval to store a “heartbeat” timestamp in D1, so when the durable object instance stops the heartbeat will be the last timestamp it was active.

Will the setInterval keep the durable object alive?

What is the write throughput limit for D1?

The short answer is if you want to know something about the state of a Durable Object, the easiest thing to do is send it a message.

It appears from Durable Objects improvements that one of your concerns about starting a Durable Object is geographic. Location of a Durable Object instance is currently determined based on the very first request to it, and after that may move based on hardware failures, but not in response to incoming requests. So as long as your admin calls are being made only to existing objects, not creating them for the first time, you shouldn’t have to worry. If geographic migration of Durable Objects based on location of incoming requests was implemented in the future, then you similarly shouldn’t have to worry about it unless your administrative calls were the majority of requests.

Regarding pricing, there’s a per-request cost for incoming http requests or websocket messages Pricing · Cloudflare Workers docs but that pricing is cheaper than writing to storage Pricing · Cloudflare Workers docs

If you were mentioning D1 because it’s currently in unpaid alpha, I wouldn’t suggest relying on that being true indefinitely.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.