How Cloudlfalare utilizing V8 to save billions of Dollars

Cloudflare Workers are a serverless computing feature.
Cloudflare is one of the most popular CDNs in the world, but users of Cloudflare wanted to have some feature which allows them to
add some logic that can be executed on certain events.
Workers can be middle logic and decision makers in routing

Features of Cloudflare Workers

Cloudflare Workers are serverless; once you deploy, they will be available on more than 300 global data centers of Cloudflare
They are low-latency code that gives good performance
But to provide this feature, Cloudflare has to do a lot of coding and also invest a lot of money in infrastructure that will run
their feature. Huge infra cost is needed because any code registered as serverless must be run in isolation. If you are running a cloud
business, then you have one big challenge, and that is security; your code should not access or disturb others’ code which are on some network
and sometimes on the same machine
let’s see what are competitiors of cloudlfare did to provide such feature and how cloudlfare applied revolutionary way
to save billions of dollars in infra by keeping the same performance as AWS Lambda and even surpassing the performance of Lambda and others
features of other cloud service providers like Azure

AWS Lambda.

AWS uses a Linux virtual machine to isolate the code; this Linux micro-VM is called Firecracker
For every instance of AWS Lambda code, it takes 5 to 10 MB of RAM; this micro VM runs on the guest machine’s system calls

In short, for each Lambda request, AWS has to create such a container to execute the code securely

Azure Functions

In Azure, there are 2 types of isolation

Process-level isolation: not heavy; it uses the w3wp.exe process and is used for lightweight APIs

Container-level isolation: Here, Azure uses the same strategy as AWS and uses microVM, it is used for critical code execution; it requires
5 to 20 MB of RAM per instance

Cloudflare solution to save costs

MicroVMs will cost companies more; for RAM and CPU, they are costly. Any company that wants to provide serverless computing will require
more servers for executing code in isolation.
Cloudflare uses PoP servers; running VMs would have resulted in a memory crash

Cloudflare wanted to save this money; they did not have deep pockets like AWS or Azure, and they came up with the revolutionary idea

They decided to use the V8 engine to provide the code execution engine

What is V8 (in short)

V8 is an open-source, high-performance JavaScript and WebAssembly engine developed by Google. Written in C++, it compiles JavaScript directly into native machine code before executing it, which makes it extremely fast.

It powers Google Chrome and server-side runtimes like Node.js, Deno, and Cloudflare Workers.

Cloudflare team thinks in this way: “When you open a new tab in Chrome, it does not create a VM for each tab but it creates lightweight isolates”

Subscribe to us for lifetime free content.

The form can be filled in the actual .

V8, Master of Isolation

V8 has a dedicated garbage collector per instance, and when it converts JavaScript into C++, it provides a strict boundary that no developer
can access that code in any way; this setup was perfect for Cloudflare

Node.js was already popular among developers, so Cloudflare started working on the idea, but there were challenges; they could not just use V8 as it is
V8 has to transform from a browser engine to Edge Serverless Engine

Cloudflare has many challenges: in Chrome, V8 clears memory when users close a tab, but in edge computing, millions of workers may get executed and destroyed
An aggressive garbage collector may require 100 percent of CPU usage; this has to be fixed

Another challenge was that Cloudflare offers worker plans; every plan has different CPU time, and V8 did not have the ability to count
cpu usage
To overcome this, Cloudflare uses the following strategy

When a request arrives, the V8 Isolate starts running the user’s JavaScript on the Main Worker Thread. At that exact millisecond, the C++ host process registers a thread-specific timer using Linux POSIX signals (timer_create with CLOCK_THREAD_CPUTIME_ID).

Crucial Detail: CLOCK_THREAD_CPUTIME_ID tracks active CPU cycles consumed by that specific thread, ignoring time spent waiting for network I/O or async responses.

2. Asynchronous Monitoring
While the Main Worker Thread executes the JavaScript, the background Watchdog Thread listens for signal events from the OS kernel.

Scenario A (Normal Code): The code completes within the 10ms–50ms CPU limit. The timer is canceled, and the response is sent back.

Scenario B (Infinite Loop / CPU Hog): The JavaScript code consumes its entire allocated CPU budget.

3. Signal Triggering & The Kill Switch
If the CPU budget expires, the OS kernel fires an interrupt signal directly to the Watchdog Thread.

Because the Watchdog Thread runs asynchronously outside the V8 execution thread, it remains completely unblocked even if the JavaScript code is stuck in an infinite while(true) loop.

4. Safe Termination
The Watchdog Thread calls V8’s native C++ API method:

Here is how Cloudflare turned this structural V8 architecture into a massive financial, operational, and competitive advantage over traditional MicroVM providers like AWS Lambda.

1. Massive Savings on Server Hardware (Hyper-Density)
In data center operations, RAM is one of the most expensive resources to scale.

The AWS Model (MicroVMs): Because AWS forces a 128 MB minimum allocation per function instance, a standard bare-metal server with 64 GB of RAM can host at most ~500 to 1,000 active functions.

The Cloudflare Model (V8 Isolates): Because a V8 Isolate requires only ~2 MB to 3 MB of baseline memory, the exact same 64 GB RAM server can comfortably host 20,000+ active Workers.

Financial Impact: Cloudflare needs roughly 90% less physical hardware than AWS to execute the same volume of workloads. This drastically cuts capital expenditure (CapEx) on servers, power, cooling, and rack space.

2. Zero-Cost Infrastructure Repurposing (Edge Expansion)
Cloudflare already had 300+ edge data centers worldwide running CDN reverse proxies.

Traditional VM Approach: To run AWS Lambda-style VMs at the edge, Cloudflare would have needed to install massive, expensive server clusters in every single city.

V8 Isolate Approach: V8 Isolates are so lightweight that Cloudflare simply installed the V8 runtime (workerd) directly onto their existing CDN servers.

Financial Impact: They launched a global edge computing network with near-zero additional infrastructure deployment costs by utilizing hardware they already owned.

3. Elimination of “Wasted” Compute Cycles
In traditional MicroVMs, every cold start spends CPU cycles on non-billable system tasks:

Initializing the OS kernel.

Setting up the virtual filesystem.

Booting language runtimes (Node.js/Python).

These CPU cycles consume power and generate heat without doing any actual work for the user. In contrast, V8 Isolates boot from pre-baked memory snapshots in < 5 milliseconds. Almost 100% of Cloudflare’s CPU power goes directly into executing user code.

4. Market Disruption Through Aggressive Pricing

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论