Member-only story

Cloudflare workers DX: the struggle of state management

quisi.do
2 min readDec 17, 2024

--

This article is a brief summary of one problem solved by quisi.do workers 1.0.

Cloudflare Workers State Management

Cloudflare workers execute their native event handlers as simple functions, e.g. fetch and queue. This is a blessing and a curse. It’s great for comprehension and velocity: function takes input, function provides output. You can go from zero to production in a matter of moments. However, asynchronous and code-split applications struggle with a lack of support for state management. Larger applications will want to abstract/reuse modules and split their features by domain. Passing application state across modules can lead to a lot of redundant or difficult-to-manage code, such as “Did I already authorize the user for this request?” or “Have I already verified this binding is the correct interface?” Omitting these checks can lead to difficult-to-diagnose bugs due to difficult-to-cover code paths.

This is a problem that is well-tackled by the Async Context Variable proposal for JavaScript, which was used by quisi.do workers during testing. The Async Context API comes with a major DX caveat. Requiring snapshots for asynchronous calls creates unintuitively complex code, especially when crossing file boundaries. On some lines, your variable exists. On others, it does not. Why isn’t it defined, when did it lose its definition, and how do you even test…

--

--

quisi.do
quisi.do

No responses yet