Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/smart-placement/README.md
1# Cloudflare Workers Smart Placement23Automatic workload placement optimization to minimize latency by running Workers closer to backend infrastructure rather than end users.45## Core Concept67Smart Placement automatically analyzes Worker request duration across Cloudflare's global network and intelligently routes requests to optimal data center locations. Instead of defaulting to the location closest to the end user, Smart Placement can forward requests to locations closer to backend infrastructure when this reduces overall request duration.89### When to Use1011**Enable Smart Placement when:**12- Worker makes multiple round trips to backend services/databases13- Backend infrastructure is geographically concentrated14- Request duration dominated by backend latency rather than network latency from user15- Running backend logic in Workers (APIs, data aggregation, SSR with DB calls)16- Worker uses `fetch` handler (not RPC methods)1718**Do NOT enable for:**19- Workers serving only static content or cached responses20- Workers without significant backend communication21- Pure edge logic (auth checks, redirects, simple transformations)22- Workers without fetch event handlers23- Workers with RPC methods or named entrypoints (only `fetch` handlers are affected)24- Pages/Assets Workers with `run_worker_first = true` (degrades asset serving)2526### Decision Tree2728```29Does your Worker have a fetch handler?30├─ No → Smart Placement won't work (skip)31└─ Yes32│33Does it make multiple backend calls (DB/API)?34├─ No → Don't enable (won't help)35└─ Yes36│37Is backend geographically concentrated?38├─ No (globally distributed) → Probably won't help39└─ Yes or uncertain40│41Does it serve static assets with run_worker_first=true?42├─ Yes → Don't enable (will hurt performance)43└─ No → Enable Smart Placement44│45After 15min, check placement_status46├─ SUCCESS → Monitor metrics47├─ INSUFFICIENT_INVOCATIONS → Need more traffic48└─ UNSUPPORTED_APPLICATION → Disable (hurting performance)49```5051### Key Architecture Pattern5253**Recommended:** Split full-stack applications into separate Workers:54```55User → Frontend Worker (at edge, close to user)56↓ Service Binding57Backend Worker (Smart Placement enabled, close to DB/API)58↓59Database/Backend Service60```6162This maintains fast, reactive frontends while optimizing backend latency.6364## Quick Start6566```jsonc67// wrangler.jsonc68{69"placement": {70"mode": "smart" // or "off" to explicitly disable71}72}73```7475Deploy and wait 15 minutes for analysis. Check status via API or dashboard metrics.7677**To disable:** Set `"mode": "off"` or remove `placement` field entirely (both equivalent).7879## Requirements8081- Wrangler 2.20.0+82- Analysis time: Up to 15 minutes after enabling83- Traffic requirements: Consistent traffic from multiple global locations84- Available on all Workers plans (Free, Paid, Enterprise)8586## Placement Status Values8788```typescript89type PlacementStatus =90| undefined // Not yet analyzed91| 'SUCCESS' // Successfully optimized92| 'INSUFFICIENT_INVOCATIONS' // Not enough traffic93| 'UNSUPPORTED_APPLICATION'; // Made Worker slower (reverted)94```9596## CLI Commands9798```bash99# Deploy with Smart Placement100wrangler deploy101102# Check placement status103curl -H "Authorization: Bearer $TOKEN" \104https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/services/$WORKER_NAME \105| jq .result.placement_status106107# Monitor108wrangler tail your-worker-name --header cf-placement109```110111## Reading Order112113**First time?** Start here:1141. This README - understand core concepts and when to use Smart Placement1152. [configuration.md](./configuration.md) - set up wrangler.jsonc and understand limitations1163. [patterns.md](./patterns.md) - see practical examples for your use case1174. [api.md](./api.md) - monitor and verify Smart Placement is working1185. [gotchas.md](./gotchas.md) - troubleshoot common issues119120**Quick lookup:**121- "Should I enable Smart Placement?" → See "When to Use" above122- "How do I configure it?" → [configuration.md](./configuration.md)123- "How do I split frontend/backend?" → [patterns.md](./patterns.md)124- "Why isn't it working?" → [gotchas.md](./gotchas.md)125126## In This Reference127128- [configuration.md](./configuration.md) - wrangler.jsonc setup, mode values, validation rules129- [api.md](./api.md) - Placement Status API, cf-placement header, monitoring130- [patterns.md](./patterns.md) - Frontend/backend split, database workers, SSR patterns131- [gotchas.md](./gotchas.md) - Troubleshooting INSUFFICIENT_INVOCATIONS, performance issues132133## See Also134135- [workers](../workers/) - Worker runtime and fetch handlers136- [d1](../d1/) - D1 database that benefits from Smart Placement137- [durable-objects](../durable-objects/) - Durable Objects with backend logic138- [bindings](../bindings/) - Service bindings for frontend/backend split139