Workers
Write a function, deploy with one command, and it instantly runs in 330+ cities worldwide — no servers to manage.
What is Workers?
Cloudflare Workers lets you run small pieces of code (called "functions") on Cloudflare's network without ever renting or maintaining a server. You just write the code; Cloudflare runs it for you, automatically, everywhere.
"Serverless" doesn't mean there are no servers — it means you don't have to think about them. There's no machine to set up, no operating system to patch, and no scaling to plan. Your code wakes up only when a request comes in, runs, and goes back to sleep.
Think of it like…
Renting a normal server is like buying a whole coffee machine, plugging it in 24/7, and paying for electricity even when nobody wants coffee. Workers is like a barista who appears the instant someone orders, makes exactly one cup, and disappears — you only pay per cup.
Because the code runs in the Cloudflare data center physically closest to each visitor ("the edge"), responses come back extremely fast. You can write Workers in JavaScript, TypeScript, Python, or Rust.
Why use it?
Traditional servers come with a long list of chores: provisioning machines, keeping them online, handling traffic spikes, and paying even when they sit idle. Workers removes that entire category of work.
No servers to manage
No machines to provision, patch, or restart at 3am. Cloudflare handles all the infrastructure.
Zero cold starts
Workers use lightweight V8 isolates instead of containers, so there's no slow "warming up" delay before your first request.
Global by default
One deploy puts your code in 330+ cities. Visitors are served from the location nearest them automatically.
Scales itself
One request or one million — Workers scales up and down on its own. You never configure auto-scaling.
Pay per request
You're billed for what runs, not for idle time. There's a generous free tier of 100,000 requests a day.
Connects to everything
Bind Workers to storage (KV, R2, D1), queues, AI models, and more with a few lines of config.
When should you use it?
Workers shines whenever you want code to run fast, globally, and on demand. Here are common real-world uses.
APIs & backends
Build the backend for a mobile or web app — handle requests, talk to a database, return JSON.
Full websites
Serve entire sites and frameworks like Next.js, Astro, or React directly from the edge.
Routing & redirects
Inspect incoming requests and redirect, rewrite, or A/B test them before they hit your origin.
Scheduled jobs
Run code on a timer with Cron Triggers — send daily emails, clean up data, fetch feeds.
Auth & middleware
Check tokens, add security headers, or rate-limit requests in front of any application.
AI at the edge
Call AI models and stream responses to users with very low latency using Workers AI.
How do you get started?
You build and deploy Workers with a free command-line tool called Wrangler. The steps below create a "Hello World" Worker, run it on your own computer, then publish it live to the internet.
Create a new Worker project
This command scaffolds a ready-to-run project. Choose the "Hello World" template, "Worker only", and JavaScript when prompted.
npm create cloudflare@latest -- my-first-worker cd my-first-workerRun it locally
Start a local development server. Open http://localhost:8787 in your browser to see your Worker respond.
npx wrangler devDeploy it live
Publish your Worker to Cloudflare's global network. You'll get a public URL like my-first-worker.<your-subdomain>.workers.dev.
npx wrangler deploy
export default {
// This fetch() handler runs on every incoming HTTP request
async fetch(request, env, ctx) {
return new Response("Hello World!");
},
};What is wrangler.toml?
Every project has a wrangler.toml (or wrangler.jsonc) config file. It holds your Worker's name and any "bindings" — connections to other Cloudflare services like databases or storage. Wrangler reads it when you deploy.
Key concepts
Handler
The function Cloudflare calls when something happens — fetch() for HTTP requests, scheduled() for cron jobs.
Isolate
A super-lightweight sandbox that runs your code. Thousands share one process, which is why there are no cold starts.
Binding
A secure connection from your Worker to another service (a database, storage bucket, queue). You access it via env.
The edge
Cloudflare's data centers spread across 330+ cities. Your code runs at the one nearest each visitor.
CPU time
How long your code actively computes. Free plan allows 10ms per request; paid defaults to 30s (up to 5 min).
Wrangler
Cloudflare's command-line tool for creating, testing, and deploying Workers. It's free and runs via npx.
Tips & pricing
Start free
The free plan gives you 100,000 requests per day — plenty to build, learn, and launch a small project before you ever pay a cent.
Good limits to remember
- Free plan: 100,000 requests/day; Paid plan: unlimited requests
- CPU time: 10ms per request on Free, 30s default (up to 5 min) on Paid
- Memory: 128 MB per Worker on both plans
- Worker size: 3 MB compressed on Free, 10 MB on Paid
- Subrequests: 50 per request on Free, 1,000+ on Paid
Watch your CPU time
CPU time counts only active computation, not time spent waiting for a network response. Heavy loops or large data processing can hit the limit — split big jobs into smaller pieces or use Queues.
Related products
menu_bookOfficial docsopen_in_new