Skip to main content

Workers

Workers is the big powerhouse of Cloudflare, their "big idea" that sets them apart from other cloud service providers.

The short introduction, if you've not heard it yet, is this: instead of spinning up a whole VM to handle an HTTP request or execute code, a Worker executes as a V8 Isolate. The image they share to explain why that matters is this one (taken from the Cloudflare blog post):

Virtual machine versus V8 isolates

What this means to you as a software architect is that the dollar-cost to execute your code is significantly lower, and in theory the code can execute much faster. When you couple this with the wide distribution of Cloudflare exit nodes, it means your code executes nearer to the actual HTTP request, generally executes faster, and can therefore return responses faster.

In practice, things are much more complicated: if your code needs access to a database, execution nearer to the requestor doesn't always have a real benefit, and can even slow down the response. Other concerns are mostly about the limitation of the runtime environment--it doesn't have filesystem access, and has other limitations--but Workers are a great tool for most of the API endpoints that are effectively a thin layer over a database.

Important Things

You can look at the Cloudflare documentation to dig in more, but these are the main things to know:

  • Runtime API - Although backed by V8 it's not NodeJS. Very similar to the browsers Serviceworker runtime, but with different limitations and a slightly different feature set.
  • Bindings - Like any container service, you'll want to make variables available to the runtime. Since the Worker runtime is JavaScript, the bound variables aren't limited to strings, they actually add functionality. This is how KV, Durable Objects, and others work.

Sign up to get updates as the Plainflare project matures.
No spam, no affiliates, not a paid newsletter.