Skip to content

PATTERN Cited by 1 source

Durable Object as coordination counter

Use a Durable Object as a lightweight counter to coordinate parent-child fan-out when a parent workflow spawns an unbounded number of child workflows and must wait for all to complete.

Problem

A package with thousands of files spawns thousands of child processing workflows running in parallel. The parent needs to know when all children have finished before moving to the publish step. Polling is wasteful; a centralized database is overkill for a simple counter.

Solution

A small Durable Object holds a counter. The parent increments once per child spawned. Each child decrements when it finishes. When the counter reaches zero, the DO wakes the parent.

Properties

  • Single-writer semantics (DO is single-threaded) eliminate race conditions on the counter
  • Lightweight — a DO holding one integer is minimal resource usage
  • Durable — counter survives crashes and restarts
  • Composable with Workflows' hibernation — parent sleeps for free while waiting

Canonical instance

cdnjs ingestion pipeline: parent DownloadPackageWorkflow spawns N ProcessingWorkflow children (one per file). A DO counter tracks completions. Parent wakes on zero (Source: sources/2026-07-30-cloudflare-dogfooding-at-scale-migrating-cdnjs-to-cloudflares-developer-platform).

Seen in

Last updated · 604 distilled / 1,840 read