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.