# Cloudflare Workers

> The edge primitive. It sits between your users and your real backend, and it's very, very good at that.

- Verdict: My default
- Vendor: Cloudflare
- Layer: [Edge](https://cloudlesslabs.com/stack/layers/edge.md). Job: Edge primitive
- Last reviewed: 18 October 2026, by Nicolas Dao (Cloudless Labs, Sydney)
- Web page: https://cloudlesslabs.com/stack/cloudflare-workers/. The whole stack in one file: https://cloudlesslabs.com/stack/brief.md

I frame Workers as an infrastructure primitive, not a business-logic platform. My business logic sits next to Postgres in a VPC and reacts to AWS events, and a Worker can reach neither.

What Workers do brilliantly is everything between the user and that backend. The rule of thumb: if it takes a few milliseconds of CPU, doesn't need the VPC, native modules or AWS events, and sits in front of your backend, it's a Worker. Otherwise it's Lambda.

## Use it when

- LLM streaming proxy: hide your API key, check the user's budget, stream tokens back. Waiting on the model costs nothing.
- Sudden spikes: no ramp-up limit and no requests-per-second quota. Absorb a flash sale at the edge and pass only real orders to AWS.
- Edge front door: JWT checks, rate limits, bot and geo rules, redirects, A/B routing in front of an AWS origin.
- Webhook receivers (Stripe, GitHub) that must answer instantly, even if hit three times a month.
- Huge streamed downloads and uploads: no response size limit.
- The WebSocket entry point for Durable Objects.
- Small glue that must run untouched for years: old compatibility dates are supported forever, so there are no forced runtime upgrades.

## Don't use it when

- Business logic that needs your private Postgres, AWS events or IAM. Keep that on Lambda.
- Native modules (sharp, Chromium, Prisma's engine), child_process, worker_threads, or more than 128 MB of memory.
- Strict Australian data residency: Workers run wherever the request lands.
- Enterprise clients who need an SLA: the $5 plan has none.

## Pricing

$5 a month per account, including 10M requests and 30M CPU-ms. Then $0.30 per million requests and $0.02 per million CPU-ms. Billed on CPU time only: waiting is free. No egress charges.

## Gotchas, with fixes

- **Gotcha:** It's not full Node.js. Most pure-JavaScript npm packages work, but there are no native modules and child_process, worker_threads, cluster and vm are stubs.
  **Fix:** Treat Workers as the layer in front of your backend. If a Worker grows into business logic that needs these, move it to Lambda Web Functions.
- **Gotcha:** Memory is fixed at 128 MB per isolate.
  **Fix:** Stream instead of buffering. Anything heavy goes to Lambda.
- **Gotcha:** Calling AWS from a Worker means storing access keys: there's no IAM role.
  **Fix:** Use narrowly scoped keys in Workers secrets, or call an AWS endpoint (function URL with signed requests) instead of AWS APIs directly.
- **Gotcha:** Cron triggers are UTC only.
  **Fix:** Convert schedules to UTC, or schedule in AWS with EventBridge Scheduler.
- **Gotcha:** Workers Logs bills per log event until 30 November 2026 (20M included, then $0.60 per million). Five console.log lines per request multiplies the bill by five.
  **Fix:** Log one structured object per request. From 1 December 2026 billing moves to $0.25/GB, cheaper than CloudWatch in Sydney ($0.67/GB).

## Provisioning

Official Pulumi package · Official Terraform provider

@pulumi/cloudflare (WorkersScript, or the newer Worker / WorkerVersion / WorkersDeployment resources, beta). Pulumi doesn't bundle your code: build with Wrangler, deploy the output with Pulumi. Pick one owner per Worker.

## Instead, consider

- [AWS Lambda](https://cloudlesslabs.com/stack/aws-lambda/index.md): Anything touching the VPC, AWS events or heavy compute.
- [Lambda Web Functions](https://cloudlesslabs.com/stack/aws-lambda-web-functions/index.md): A Worker that grew into business logic and needs full Node.js or an IAM role.

## Worked examples

- [Lambda, Web Functions or Workers?](https://cloudlesslabs.com/stack/guides/compute-choice/index.md): Where should this piece of logic run?
- [The LLM streaming proxy](https://cloudlesslabs.com/stack/guides/llm-proxy/index.md): How do I add an AI chat feature without leaking my API key or paying for the model's thinking time?
- [The flash sale](https://cloudlesslabs.com/stack/guides/flash-sale/index.md): What happens when 50,000 people press "Buy" in the same ten seconds?
- [A live auction on Durable Objects](https://cloudlesslabs.com/stack/guides/live-auction/index.md): How do thousands of bidders share one live auction without races, and what happens when it ends?
- [Better Auth or Cognito?](https://cloudlesslabs.com/stack/guides/sign-in/index.md): Which sign-in should my app use, and what do I actually get for free?

## Where it fits

- [An API for my app](https://cloudlesslabs.com/stack/use-cases/api.md): pick 4. In front, if users are global or traffic is huge (auth, rate limits, caching).
- [An AI chat or LLM feature](https://cloudlesslabs.com/stack/use-cases/ai-chat.md): pick 1. The proxy. Hides your key, enforces per-user budgets, streams tokens. Waiting is free.
- [Something live that many people watch at once](https://cloudlesslabs.com/stack/use-cases/realtime.md): pick 1. The door. Checks the login and routes each socket.
- [A traffic spike I can see coming](https://cloudlesslabs.com/stack/use-cases/flash-sale.md): pick 1. The shock absorber. Workers start in milliseconds at any traffic, with no ramp-up and no concurrency quota, so 0 to 5,000 requests a second just works. Lambda scales fast but in steps: at most 1,000 new instances per 10 seconds per function, capped by the account default of 1,000, each one cold-starting. Junk is rejected at the edge.
- [Logs without a shocking bill](https://cloudlesslabs.com/stack/use-cases/logging.md): pick 4. Workers Logs moves to $0.25/GB on 1 December 2026.
- [Sign-in and identity](https://cloudlesslabs.com/stack/use-cases/sign-in.md): pick 4. Verifies the tokens at the edge, from either one.

## Sources

- [Workers pricing](https://developers.cloudflare.com/workers/platform/pricing/)
- [Workers limits](https://developers.cloudflare.com/workers/platform/limits/)
- [Node.js compatibility](https://developers.cloudflare.com/workers/runtime-apis/nodejs/)

## Related

- [Edge](https://cloudlesslabs.com/stack/layers/edge.md): every tool in this layer, with its verdict
- [The whole stack in one file](https://cloudlesslabs.com/stack/brief.md): every use case and tool, for questions that span many
- [Map of every Markdown file on cloudlesslabs.com, with what each one answers](https://ask.cloudlesslabs.com)
