Traditional server deployments mean picking a region. US-East, EU-West, AP-Southeast — your users in other regions deal with latency. Cloudflare Workers flip this model. Your code runs in over 300 cities worldwide, automatically routing each request to the nearest location.
What Are Workers?
Workers are lightweight JavaScript/TypeScript runtimes that execute at the edge. They use the V8 engine (not Node.js), which means cold starts are measured in milliseconds, not seconds. The programming model is based on the Service Worker API.
export default {
async fetch(request, env) {
const url = new URL(request.url);
if (url.pathname === "/api/hello") {
return new Response(JSON.stringify({ message: "Hello from the edge" }), {
headers: { "Content-Type": "application/json" },
});
}
return new Response("Not found", { status: 404 });
},
};
The Runtime
Workers don’t have access to the full Node.js API. Instead, they provide Web Standard APIs — fetch, Request, Response, URL, crypto, TextEncoder, and others. This is intentional: the runtime is designed for short-lived request handling, not long-running processes.
What you get:
- V8 isolates instead of containers. Much faster cold starts.
- 128MB memory per worker invocation.
- CPU time limits (10ms on free, 30s on paid) rather than wall-clock limits.
- Bindings to KV, R2, D1, Durable Objects, Queues, and more.
Storage at the Edge
The real power of Workers comes from the storage primitives:
- KV — Eventually-consistent key-value store. Good for read-heavy data.
- R2 — S3-compatible object storage with no egress fees.
- D1 — SQLite at the edge. Relational data without managing a database.
- Durable Objects — Strongly consistent, single-instance state. Essential for real-time coordination.
Each of these is accessible directly from your Worker code through environment bindings, with no network round-trip to a separate service.
When to Use Workers
Workers excel at:
- API gateways and routing
- Authentication and authorization at the edge
- A/B testing and feature flags
- Image and content transformation
- Server-side rendering for static-first sites
They’re less suited for CPU-intensive computation or tasks that need long execution times. Know the constraints and play to the strengths.