Opens in a new tab
🚀 Your daily business tech & AI briefing — Subscribe free →

Cloudflare Workers CPU time costs: 8 steps that actually work

Zain A
Share this article

Introduction

Why Workers bill for CPU time, not waiting

On Workers, CPU time is the real bill, not bandwidth. If you shave work off the hot path—parsing less, caching more—you cut spend without touching traffic. Here’s the practical order of tweaks that move the needle.

Where the monthly bill grows

The paid plan includes 30 million CPU ms per month, then charges $0.02 per extra million. Heavy JSON parsing, regex backtracking and crypto drive most overages.

Cloudflare Workers CPU time costs: 8 steps that actually work

Profile CPU Use With Wrangler Tail Before Changing Anything

Profile first. Raising limits or changing plans before you know which code burns CPU just hides the problem.

Finding the expensive routes

Run Wrangler tail against my-worker to stream live logs. Watch which routes and request types show up most often.

  • Note routes that parse large JSON bodies.
  • Flag regex-heavy handlers.
  • Check any crypto work on the request path.

Reading error 1102 reports

Error 1102 means a Worker exceeded its CPU time limit. Match each failure to a route, then look at what that route computes.

A slow upstream is rarely the cause, since I/O waiting does not count. Fix the compute hot spot first.

Serve Repeat Requests From Workers Cache

Workers Cache lets Cloudflare return cached HTTP responses without running your Worker code. Every cache hit skips your script.

Setting Cache-Control headers

You control caching with standard Cache-Control directives on your responses. Cloudflare honors them per RFC 9111, and that is the whole configuration surface.

  • Zone settings such as Cache Rules and Page Rules have no effect on a Worker’s cache.
  • The cache key uses the request path, entrypoint, ctx.props and, by default, the Worker version, not the hostname.

Why cache hits cost no CPU time

CPU time is billed only when the Worker runs. A cache hit never starts it, so it adds nothing to your CPU total.

Caching covers any fetch invocation: browser requests, service bindings and loopback calls through ctx.exports.

Shrink Large JSON Payloads Before Parsing

Large JSON parsing is a common CPU hot spot. The less data your Worker parses, the less CPU time you pay for.

Requesting only the fields you need

Ask the upstream API for a smaller response. If api.example.com supports field selection or pagination, use it.

  • Request only the fields the route returns.
  • Page results instead of fetching everything at once.
  • Split divisible work into batches that finish well under the CPU limit.

Streaming instead of loading everything

Pass a response body through as a stream when you do not need to inspect it. Skipping the parse skips the CPU cost.

If you must transform a large payload, process it in pieces rather than building one huge object in memory.

Cloudflare Workers CPU time costs: 8 steps that actually work

FAQ

Does Cloudflare Workers charge for CPU time or wall-clock time?

CPU time. Waiting on I/O, such as an AI call or a slow upstream, does not count.

What uses the most CPU time in a Worker?

Large JSON parsing, regex backtracking and crypto.

How do I fix a Worker that exceeds the CPU time limit?

Profile first, then split heavy jobs into smaller batches or offload them to Queues so each invocation stays under the limit.

Conclusion

Lower CPU bills come from running less code, not from tuning plans. Measure first, then let cached responses skip your Worker and trim what it still parses.

References

Share this article

Stay in the Loop

Weekly tech insights, AI news and tools — straight to your inbox.

Newsletter Form (#4)

Contents