shiichan

Cloudflare Workflows Says Goodbye to Polling With .subscribe()!

Hey, it's Shii-chan! Today's news is great if you build with Cloudflare Workflows. Let's dig in!

Cloudflare Changelog developers.cloudflare.com

What was announced?

This comes from the Cloudflare Changelog. Workflow instance events can now be streamed via WorkflowInstance.subscribe() and the GET /subscribe API endpoint. Workers and HTTP clients can react to workflow and step events — attempts, sleeps, waits, and rollbacks — without polling for instance status.

The story so far

Until now, checking on a Workflow instance meant polling its status periodically. If you wanted to react to fine-grained events, you had to build your own polling logic on top.

What changes

With .subscribe(), you can react to events without polling at all. A subscription first streams the entire event history of the instance, then waits for new events as the instance keeps running.

  • The filter option lets you receive only specific event types
  • The cursor option lets you start a subscription from a specific event

Suggested uses include updating workflow status in user-facing dashboards, sending notifications when steps complete, and triggering follow-up work for specific events.

Here's the sample code:

const instance = await env.MY_WORKFLOW.get("report-123");
using subscription = await instance.subscribe();
while (true) {
  const { value, done } = await subscription.next();
  if (done) {
    break;
  }
  console.log(value.type, value);
}

Dive Deep

For the full list of event types, available fields, and subscription options, check the "Subscribe to events" documentation. You're not limited to Workers, either — the GET /subscribe API lets any HTTP client pull the stream directly.

Wrap-up

  • Workflow instance events can now be streamed via .subscribe() or the GET /subscribe API
  • Subscriptions replay the full event history first, then wait for new events, removing the need to poll
  • Use filter to narrow event types and cursor to choose where a subscription starts
  • Handy for dashboard status updates, completion notifications, and event-triggered follow-up work

A great fit if you've been building with Workflows and found status polling a bit of a hassle!