Cloudflare Workers: Limits, Pricing & Optimization Guide
Cloudflare Workers run JavaScript and WebAssembly at 300+ global edge locations with near-zero cold starts. Understanding the limits — CPU time, memory, storage quotas, and subrequest counts — is essential for production deployments.
Workers Plans: Free vs Paid Limits
| Limit | Free Plan | Paid Plan ($5/mo) |
|---|---|---|
| Requests/day | 100,000 | 10M/month included |
| CPU time/request | 10ms | 50ms (30ms free, then $0.02/M CPU-ms) |
| Memory/Worker | 128MB | 128MB |
| Script size | 1MB compressed | 10MB compressed |
| Subrequests/request | 50 | 1,000 |
| KV reads/day | 100,000 | 10M/month |
| KV writes/day | 1,000 | 1M/month |
| Cron triggers | Not available | Included |
Storage Options: KV vs R2 vs D1 vs Queue
| Service | Type | Max Value Size | Consistency | Best For |
|---|---|---|---|---|
| Workers KV | Key-Value | 25MB | Eventual | Config, feature flags |
| R2 | Object Storage | 5TB | Strong | Files, images, data |
| D1 | SQLite DB | 2GB/DB | Strong | Relational data |
| Queues | Message Queue | 128KB/msg | At-least-once | Background jobs |
A Basic Cloudflare Worker with KV and D1
// Worker with KV and D1 bindings (wrangler.toml)
// [[kv_namespaces]]
// binding = "CACHE"
// id = "abc123"
// [[d1_databases]]
// binding = "DB"
// database_id = "def456"
export interface Env {
CACHE: KVNamespace;
DB: D1Database;
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
const userId = url.searchParams.get('id');
// Check KV cache first (fast edge read)
const cached = await env.CACHE.get(`user:${userId}`);
if (cached) {
return Response.json(JSON.parse(cached), {
headers: { 'X-Cache': 'HIT' }
});
}
// Fall through to D1 (SQLite at edge)
const { results } = await env.DB.prepare(
'SELECT * FROM users WHERE id = ?'
).bind(userId).all();
if (results.length === 0) {
return new Response('Not found', { status: 404 });
}
// Cache result for 60 seconds
await env.CACHE.put(
`user:${userId}`,
JSON.stringify(results[0]),
{ expirationTtl: 60 }
);
return Response.json(results[0], {
headers: { 'X-Cache': 'MISS' }
});
}
}; Handling CPU-Intensive Work
If your workload exceeds the 50ms CPU limit, use these strategies:
// Strategy 1: Use waitUntil() for non-blocking background work
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
// Return response immediately
const response = new Response('Accepted', { status: 202 });
// Process asynchronously (does not block response)
ctx.waitUntil(processInBackground(request, env));
return response;
}
};
// Strategy 2: Offload heavy work to a Queue
ctx.waitUntil(
env.MY_QUEUE.send({
type: 'process-image',
url: imageUrl,
userId: userId,
})
);
// Queue consumer Worker handles the actual processing Related Products
on GumroadDevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →You Might Also Need
Neon DB Query Builder
Visual query builder for Neon serverless PostgreSQL. Generate raw SQL, @neondatabase/serverless TypeScript, and Drizzle ORM code for SELECT, INSERT, UPDATE, DELETE operations.
Open free tool →
Turso Edge DB Explorer
Browse @libsql/client TypeScript query templates for Turso. Covers SELECT, INSERT, batch transactions, interactive transactions, schema creation, and Drizzle ORM patterns.
Open free tool →
AWS Lambda Cost Calculator
Estimate monthly AWS Lambda costs. Input invocations, duration, memory, and data transfer to get compute cost, request cost, and total with EC2 comparison.
Open free tool →
More Free Tools
Related Articles
Cloudflare Workers vs Vercel Edge Functions: 2026 Comparison
Deep comparison of Cloudflare Workers vs Vercel Edge Functions in 2026: runtime differences, limits, pricing, storage options, developer experience, and when to choose each.
Cloudflare Workers + D1: Build a Full-Stack Edge App in 2026
Complete guide to Cloudflare Workers with D1 SQLite database. Learn Worker setup, D1 schema migrations, SQL queries, REST API patterns, and deployment — all running at the edge with zero cold starts.
Cloudflare Workers & Serverless Edge Computing: Complete Guide for 2026
Learn how to build and deploy serverless APIs with Cloudflare Workers. Covers Worker syntax, KV storage, D1 database, Durable Objects, and R2 — with TypeScript examples you can use today.
CDN and Edge Caching 2026: Complete Guide to Content Delivery Networks and Edge Computing
Comprehensive guide to CDN and edge caching strategies for 2026. Covers Cloudflare, Fastly, Akamai, AWS CloudFront, edge functions, cache invalidation, real-time synchronization, and multi-CDN strategies with code examples.
Edge Computing Architecture: Deploy Closer to Users 2026
Edge computing architecture 2026: edge vs CDN vs serverless, Cloudflare vs Vercel vs Fastly, data consistency patterns, and edge-native design guide.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →Frequently Asked Questions
What is the CPU time limit for Cloudflare Workers?▼
On the Free plan, Workers have a 10ms CPU time limit per request. On the Paid plan ($5/month), the limit increases to 50ms CPU time. Note that CPU time is wall-clock time minus I/O wait time — if your Worker spends most of its time waiting for fetch() calls, that does not count against your CPU budget. Workers that exceed their CPU limit receive an error response.
What is the difference between Workers, Pages Functions, and Durable Objects?▼
Cloudflare Workers are standalone serverless functions deployed to the edge. Pages Functions are Workers deployed alongside a Cloudflare Pages site (same runtime, co-located). Durable Objects provide stateful Workers with consistent identity — each Durable Object instance has a single-threaded execution guarantee and persistent storage, making them suitable for real-time collaboration, game servers, and coordination tasks.
What are the storage limits for Workers KV?▼
Workers KV has a 25MB value size limit per key and 512-byte key size limit. KV is eventually consistent (reads may lag writes by seconds across PoPs). For the Free plan, you get 100,000 KV reads/day and 1,000 writes/day. The Paid plan includes 10M reads/month and 1M writes/month. KV is optimized for read-heavy workloads — for write-heavy use cases, consider Workers D1 or R2.
What is the request size limit for Cloudflare Workers?▼
Workers can receive request bodies up to 100MB in size. Response bodies have no explicit size limit but are streamed. For the subrequest limit (fetch() calls from within a Worker), you can make up to 50 subrequests per Worker invocation on the Free plan and 1,000 on the Paid plan. Recursive Workers (Workers calling Workers) count toward this limit.
How does Workers Paid plan pricing work?▼
The Workers Paid plan costs $5/month and includes 10 million requests/month. Beyond that, additional requests cost $0.30 per million. CPU time beyond 30ms per request is charged at $0.02 per million CPU-ms. Compared to AWS Lambda, Workers pricing is often lower for high-throughput, short-duration workloads because there is no per-GB-second memory charge.
Can Cloudflare Workers connect to external databases?▼
Workers cannot make TCP connections (no traditional database drivers). For databases, use HTTP-compatible options: Cloudflare D1 (SQLite via Workers binding), Neon PostgreSQL (HTTP driver), PlanetScale (HTTP driver), Upstash Redis (HTTP), or Turso (libSQL over HTTP). For workers that must access a private database, use Cloudflare Tunnel with a Hyperdrive binding to proxy TCP connections.