The Workers Runtime — Code at the Edge
Throughout this course you will build Hoplink, a tiny link shortener: someone visits hop.example/cat and lands on a long URL about cats. A redirect like that should feel instant from Delhi, Lagos or Lima. If your code lives on one server in one country, half the planet waits for a round trip across an ocean. Cloudflare Workers take the opposite approach: your code runs in whichever Cloudflare data centre is nearest to the visitor.
The rule
Many tiny isolates, near every user, speaking web standards.
Unpack each part:
- Isolates. A Worker does not get its own virtual machine or container. It runs inside a V8 isolate — the same sandbox a browser tab uses to keep one site's JavaScript away from another's. Thousands of isolates share one process, so starting one takes milliseconds, not seconds. That is why Workers have almost no "cold start".
- Near every user. When you deploy, your code is copied to Cloudflare's whole network. A request is handled at the location that received it — the edge — rather than being forwarded to a central server.
- Serverless. You never choose a machine, patch an operating system or decide how many copies to run. You ship a function; the platform runs as many copies as traffic needs and bills by use.
- Web standards. Inside a Worker you use the APIs you already know from the browser:
fetch,Request,Response,URL,crypto, streams. Many Node.js APIs are available too once you turn on thenodejs_compatcompatibility flag, but the default world is the web platform.
The smallest Hoplink Worker looks like this:
export default {
async fetch(request, env, ctx) {
return new Response("Hoplink is alive");
},
};There is no listen(8080) and no server object. The runtime calls your fetch function once per request and sends back whatever Response you return.
The shortcut
When you meet any design question on Workers, run it through three checks: Is it short? Is it stateless? Is it standard? A Worker invocation should do a bounded amount of CPU work, keep nothing important in memory between requests, and use web APIs. Anything that fails a check belongs in a storage product (KV, R2, D1, Durable Objects) or a queue — which is exactly what the rest of this course covers.
Is it short?
Adding one to a number is tiny CPU work. This check passes.
The classic trap is treating a Worker like a long-running Node server: caching user data in a module-level Map and expecting every request to see it.
Drills
Answer fast — trust the rule.
Why do Workers start in milliseconds rather than seconds?
A visitor in Mumbai opens a Hoplink URL. Where does the Worker usually run?
Which API is available in a Worker without enabling any compatibility flag?
A developer stores signed-in users in a module-level Map inside a Worker. What goes wrong?
Remember
- Many tiny isolates, near every user, speaking web standards.
- Shortcut: short, stateless, standard — whatever fails goes to storage or a queue.
- Trap: treating a Worker like a long-lived server with durable global memory.
