overview of cloudflare workers - part 1

If you've got any questions feel free to DM on Twitter @reillyjodonnell
Search for a command to run...

If you've got any questions feel free to DM on Twitter @reillyjodonnell
No comments yet. Be the first to comment.
Someone shared this image above. At first glance, I wasn’t sure about the perf implications — so let’s break it down from first principles :D Let’s deconstruct this monster Here’s the code: // Function to flatten React Context Providers. const flatte...

Intro Hello it’s me from the future! I originally was going to go over file based routing but pivoted to going over important SSR concepts with React / how Bun makes it easy. It’s full of struggles with hydration (mismatches), React entry points, and...

Powered by bash and AppleScript!

Sockets can only transmit binary (text.) Imagine we have this data const message = {id: '123', name: 'Reilly', message: 'Hey'} Here's the problem: we want to send this data to the ui but we have hundreds of useEffects spread throughout the codebase....

Serverless is EVERYWHERE and for good reason: nearly infinite scalability, physically closer to users, and pay-for-what-you-use pricing. But not without tradeoffs — vendor lock-in, (potentially) higher costs, and the infamous cold-starts.
In response to the issues of cold starts, CF introduced Workers. Workers are v8 isolates running throughout their 300+ data centers. Users provide js code, and it runs as soon as the isolate is provisioned, eliminating the main annoying characteristic of serverless — cold starts. Contrasted to typical serverless functions which need to spin up an entire vm/container.
v8 — yeah that [one](https://v8.dev/) is an individual in-process js/wasm sandbox running in a single OS process. V8 isolates logically isolate their JavaScript heaps (variables, objects, etc.), meaning one isolate cannot directly access another’s memory. However, they run in the same OS process, sharing the same virtual memory space. Most importantly, they spin up fast (Cloudflare reported an avg speed of [5ms](https://blog.cloudflare.com/cloud-computing-without-containers/#:~:text=Because%20Workers%20don%E2%80%99t%20have%20to%20start%20a%20process%2C%20Isolates%20start%20in%205%20milliseconds%2C%20a%20duration%20which%20is%20imperceptible)
Ah fair. You should know by now nothing is without tradeoffs. While v8 isolates reduces cold starts to a nearly invisible 5ms, there are still intrinsic difficulties in scaling. With isolates sharing the total compute, what happens when one takes forever and blocks the main thread (this is js after all)? Or how do you manage the total memory so that you don’t get a OOM and linux kernel decides to kill any process it deems less valuable? Cloudflare’s employed some really cool engineering to address this plus extra security concerns. Stay tuned for part 2!
sauces
https://developers.cloudflare.com/workers/reference/security-model/
https://developers.cloudflare.com/workers/reference/how-workers-works/
.