The Nearest Edge May Not Be Nearest to Your Data
A team ships an order-history API on Workers and gets a support ticket from Sydney: the page takes over a second. The dashboard looks healthy—about 4 ms of CPU, no error spike, no 1102—and the Worker runs in the region nearest the user. A day of caching JSON and shaving allocations barely moves p95.
Then someone reads a trace. The handler runs in Sydney and makes six sequential queries to a Postgres primary in Frankfurt. The fix is not faster JavaScript; it is moving execution or state so those six round trips stop crossing an ocean.
A useful analogy is a restaurant. The diner is the request location; the pantry is the state location; the kitchen is placement. Putting the kitchen beside the diner is sensible until every ingredient is flown in from another continent. Sometimes the answer is to move the kitchen next to the pantry and accept a longer walk for the diner; sometimes it is to split the job—greet at the door, cook near the pantry.
Three terms are often blurred together:
- Request location is the Cloudflare data center that accepts the connection. It follows network routing, so it is usually near the user but not necessarily in the user's city.
- State location is where the data lives: a regional Postgres primary, a Durable Object's home location, an R2 bucket's jurisdiction, or a centralized authoritative store.
- Placement is the configuration choice that decides which data center executes the Worker's
fetchhandler. Left unset, it follows the request location.
The mental model is a sum:
total ≈ entry leg + queueing + execution + (round trips × state RTT) + response leg
At the edge, the entry leg is short and execution is usually a few milliseconds. The round-trip term is the one that grows unnoticed, because it is spent waiting rather than computing.
The round trip is the expensive term
A Worker with 4 ms of CPU and six illustrative 250 ms database round trips is a 1.5-second request wearing a 4 ms costume.
Figure 1 shows the two paths for the same code: default placement, where execution sits with the user and every query crosses to the database, and placed execution, where the Worker moves next to the state and the entry leg becomes the long one.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
U["User in Sydney
request location"] --> E{"Placement choice"}
E -->|"default: nearest to request"| W1["Worker runs in SYD"]
E -->|"region or smart placement"| W2["Worker runs in FRA"]
W1 -->|"6 sequential queries
long RTT each"| DB[("Postgres primary
state location: FRA")]
W2 -->|"6 sequential queries
1-3 ms each"| DB
W1 --> R1["p95 dominated by round trips"]
W2 --> R2["p95 dominated by entry leg"]
DB --> R3["Same data, same schema,
same query plan"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class R3 primary;
class U,E,W1,W2,R1,R2 secondary;
Figure 2 draws the same relationship as three planes. The request crosses from the user network into the Cloudflare network once; the expensive part is the repeated crossing from the Cloudflare network into the origin infrastructure. Placement changes which side of that boundary the Worker sits on, and it does not move the data.
Workers run in a data center closest to where the request was received unless you say otherwise. Placement is configured per Worker and the options are mutually exclusive; the placement documentation groups them into three shapes.
| Shape | Configuration | Choose it when | Boundaries |
|---|---|---|---|
| Smart | placement.mode = "smart" | Multiple back ends, or infrastructure whose location you do not know | Analyzes request duration across locations and forwards when a candidate is significantly faster. Only considers locations where the Worker has already run, needs consistent traffic from multiple locations, and can take up to 15 minutes to analyze a deployment. By default, 1% of requests stay unplaced as a baseline. Statuses include SUCCESS, INSUFFICIENT_INVOCATIONS, and UNSUPPORTED_APPLICATION. Available on all plans. |
| Region | placement.region, written provider:region such as aws:us-east-1 or gcp:europe-west1 | A single back end in a known AWS, GCP, or Azure region | Cloudflare maps the region to the data center with the lowest latency to it. The Worker still runs on Cloudflare's network, not inside the cloud provider's region. At very high volume, instances may spread more widely. |
| Host | placement.host for a layer 4 probe, placement.hostname for layer 7 | Single-homed infrastructure outside the major clouds | Documented as experimental. Probes do not work for anycast, multicast, broadcast, or replicated resources. |
The table is the decision; the configuration file is where it lands. One choice per Worker, written as JSON:
Two boundaries matter more than the syntax. Placement moves execution, not data, and it does not reach every surface:
| Surface | Does placement change it? | What decides the location |
|---|---|---|
fetch handler | Yes — this is what placement moves | The placement mode, region, or host probe |
| RPC methods and named entrypoints | No — documented as unaffected | Wherever the invocation lands; Workers without a fetch handler are ignored |
| Static assets | Not by default | Served from the location nearest the request; the static assets binding serves from where the Worker runs |
| Durable Objects | Already placed | The object's home location, further constrained by a jurisdiction such as eu, us, or fedramp |
| Hyperdrive | No — it changes the connection path | Pooling and query caching remove per-request connection setup |
Decide in this order
Locate the state, count the round trips, then decide whether to move compute, reduce round trips, or move state. CPU tuning comes last, because it cannot fix a request that is mostly waiting.
CPU Time and Elapsed Time Tell Different Stories
Two endpoints can report 900 ms of latency while failing for different reasons.
Endpoint A spends 7 ms of CPU and 880 ms waiting on four sequential fetch() calls. Endpoint B spends 310 ms of CPU parsing and reserializing a 4 MB JSON payload and 20 ms on one subrequest. On a latency chart they are twins; against limits they are opposites. On Workers Free, B is 31 times over the 10 ms CPU budget and cannot run there at all, while A sits comfortably inside it. On Workers Paid, both run, but B consumes roughly 44 times more CPU and reaches the 5-minute maximum first when a payload grows.
CPU time measures how long the CPU spends executing your code; waiting on network requests, KV reads, or database queries does not count. Wall time, also called elapsed time, runs from invocation start to finish and includes all that waiting.
The documented limits at the verification date are worth memorizing as a shape rather than as trivia:
| Dimension | What it measures | Workers Free | Workers Paid | Where you see it |
|---|---|---|---|---|
| CPU time | Time the runtime spends executing your code; waiting on I/O does not count | 10 ms per request | 5 min maximum, 30 s default | Invocation log; exceededCpu in analytics |
| Wall time | Elapsed time from invocation start to finish, including I/O and streaming | Unlimited while the client stays connected | Same | Invocation log; request duration when Smart Placement is on |
| Subrequests | Every fetch(), redirect hop, and call to KV, R2, D1, or the Cache API | 50 per invocation | 10,000 per invocation, configurable up to 10M | Runtime exception; invocation status |
| Memory | JavaScript heap plus WebAssembly allocations, per isolate | 128 MB | 128 MB | exceededMemory; "Memory limit would be exceeded before EOF" |
| Startup | Time to parse and run global scope before the first request | 1 s | 1 s | Deploy error 10021; startup_time_ms |
| Open connections | Outbound sockets still waiting for response headers | 6 | 6 | Silent queueing, visible only as added latency |
Figure 3 follows one request through both budgets. The failures are not interchangeable: one returns a resource-limit error, one throws, and one merely gets slower.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
sequenceDiagram
autonumber
participant C as Client
participant W as Worker
participant D as Database
participant U as Upstream API
C->>W: GET /report
W->>D: query 1
D-->>W: rows
W->>D: query 2
D-->>W: rows
W->>U: fetch() x 6
alt CPU budget exhausted
W-->>C: 1102 Worker exceeded resource limits
else Subrequest budget exhausted
W-->>C: exception, too many subrequests
else More than 6 awaiting headers
Note over W,U: 7th fetch is queued, not failed
U-->>W: response headers arrive
W-->>C: 200 with streamed body
end
Streaming does not reduce CPU time. It reduces memory pressure and improves time to first byte, because you stop buffering the whole payload. A streamed response can stay alive far longer than a CPU-bound one, since incoming HTTP wall time has no hard limit while the client remains connected. Memory is capped per isolate at 128 MB, not per request, and one isolate serves many concurrent requests, so buffering several large bodies is a shared risk.
Subrequests are counted per invocation, and redirect chains count, so network operations can exceed the number of fetch() calls in your source. Cache API calls share the quota; internal service calls have a separate ceiling of 1,000 on Free and, on Paid, the configured subrequest limit.
Six simultaneous connections is the quiet one. Only connections still waiting for response headers count, so a Worker can hold many sockets open as long as no more than six are in that phase. A seventh is queued, not rejected. Twelve parallel calls to a 100 ms endpoint can therefore take about 200 ms instead of 100 ms, with no error; service-binding callers share the same budget.
ctx.waitUntil() can extend execution for up to 30 seconds after the response completes or the client disconnects. Cron Triggers, Queue consumers, and Durable Object alarm handlers have a 15-minute wall-time ceiling, and Cron CPU limits differ from HTTP limits: 30 seconds for schedules more frequent than one hour, 15 minutes for hourly or less frequent schedules.
Cold starts are smaller than on container platforms because isolates start quickly, but they are not free: a Worker must parse and run its global scope within 1 second, and expensive module-level initialization shows up as first-request latency on a fresh isolate.
Plan boundaries are real. Free's 10 ms CPU and 50 subrequests are not a trial version of Paid, and the Bundled plan differs again at 50 ms and 50 subrequests.
Plan limits are not a trial version
The documented baseline. Cloudflare documents the average Worker at roughly 2.2 ms of CPU per request and heavier workloads at 10–20 ms — documentation figures, not measurements from this article.
CPU. Exceeding the budget returns 1102 with the message "Worker exceeded resource limits" and an exceededCpu outcome.
Memory and the daily cap. Memory exhaustion reports exceededMemory; the Free daily request cap returns 1027, which is a separate limit.
Errors name the budget that ran out. CPU and memory limits are different failures from a subrequest exception, and none of them is the daily request cap.
Streams, Bindings, and Runtime Compatibility
A compatibility date is not a version number for your code. It is a snapshot of runtime defaults: the set of backwards-incompatible fixes that were enabled on or before that date. Cloudflare supports old dates forever, and a new date takes effect on the next deploy. That guarantee is generous, but it creates a specific trap: the runtime is not frozen, only the defaults your Worker sees are.
Streams are a good place to see why this matters, because their failure modes are quiet. Three flags in the current compatibility flags history make the point:
encoder_stream_spec_compliant_backpressure, default as of 2026-03-24, makesTextEncoderStreamandTextDecoderStreamstart with a readable-side high water mark of 0; the previous default of 1 firedpull()at startup and cleared backpressure before any write.writable_stream_spec_compliant_writer, also default as of 2026-03-24, fixes writer lock and release behavior to match the WHATWG standard.pipe_to_backward_propagation, default as of 2026-11-17, makespipeTo()andpipeThrough()propagate destination errors and closure back to the source. Without it, the pipe still cancels the source but its promise resolves instead of rejecting.
That last date is twelve days after this article's verification date. A Worker pinned to 2026-11-01 keeps the old resolving behavior; one on 2026-11-17 or later gets a rejection, with identical source code. A try/catch around a pipe that never fired may start firing, or an unhandled rejection may surface where a silent truncation used to be.
Bindings inherit the date too
Zone routing. global_fetch_strictly_public decides whether a request to the Worker's own zone goes to the zone's origin or loops through the front door, where it may reach the same Worker again. Without it, Workers mapped to the URL and security settings are bypassed; fetching another Worker on the same zone without the flag is documented as error 1042.
Startup cost. The behavior behind nodejs_compat and nodejs_compat_v2 becomes the default for dates from 2026-08-04, increasing bundle size and startup time for projects that opted in manually.
A date bump is a behavior change
Bumping compatibility_date is not a feature switch. It also changes defaults and failure semantics, so a green test run on the old date proves nothing about the new one. Treat the date change as a behavior change and test the exact date you intend to deploy.
Figure 4 separates the assumptions that a compatibility test actually covers. The same source code crosses two different runtime gates, and a staging environment pinned to the old date exercises only the upper path. That is why a preview can pass while production fails after a date bump: the preview was never running the runtime that production will run.
A Controlled Upgrade for a Changing Runtime
The safe way to move a compatibility date is to treat it like a code release with a measurable gate. The mechanics are unglamorous, but they convert an argument about release notes into evidence.
1. Freeze a baseline. Record the compatibility date and flags, the version ID, and a window of p50/p95 wall time, CPU time, 1102 rate, subrequest counts, and response byte counts, long enough to survive a daily traffic cycle. A version captures code, assets, bindings, and compatibility settings, so the version ID is a meaningful reference; storage state is explicitly not versioned.
2. Read the flag diff, not the marketing summary. Diff the flags whose default moved between the two dates. For each, write down the old behavior, the new behavior, and the observable symptom.
3. Upload without deploying. Upload a version that serves no traffic, so you can inspect it before any user sees it.
4. Canary a small slice. Split traffic between the previous version and the new one. Start small and compare the same hours of the day, because latency and traffic mix move together.
5. Gate on evidence, then promote or roll back. If the canary's CPU p95, wall p95, resource-limit rate, and response sizes stay inside tolerance, promote to 100%. If not, roll back. Figure 5 shows the path, including the branch most teams forget: rollback restores code and configuration, not data.
Two boundaries matter. Rollback restores the previously deployed version but does not undo a D1 migration, a Durable Object schema change, or data written in a new format; if compatibility behavior changed your serialization, the rollback plan needs a data plan. Old compatibility dates are supported indefinitely, so there is no forced deadline — upgrade for new features and documentation that describes current behavior.
Rollback restores code, not data
The timing of an upgrade is optional, but the risk is cumulative: the longer you defer, the larger the flag diff and the harder the canary is to interpret.
Failure in this kind of upgrade is rarely a clean exception. A changed stream default may truncate a response after headers are sent, so the client sees a 200 with a short body. A backpressure change may turn a fast producer into a stalled one, which looks like latency. A CPU increase may appear only at the p99, where a small canary has too few samples to separate it from noise. The gate therefore needs resource-limit counts and response-size checks, and a canary large enough to produce a usable sample.
Compare Two Small Workload Shapes
This exercise makes the CPU-versus-wall distinction visible in your own logs and shows how placement changes the story without changing code. It compares a CPU-shaped handler against an I/O-shaped handler under identical configuration. It is design-only: it has not been executed and no measured values are reported.
Compare Two Small Workload Shapes
Status: design-only, not executed. The steps and expected observations are a plan. Record your own numbers.
Prerequisites. A Cloudflare account, Node.js 20 or later, Wrangler 4.x, and a scratch hostname you can delete. Workers Free is sufficient, and the CPU-shaped handler is expected to hit the Free ceiling, which is part of the lesson. Smart Placement is available on all plans but needs traffic from multiple locations, so it is an optional observation, not a reliable local test.
Minimal setup. The widget above defines two routes. The CPU route repeats SHA-256 hashing over a generated buffer and returns a small JSON body. The I/O route makes five sequential fetch() calls to an endpoint that delays before responding, then returns the status codes. Deploy once with no placement block and once with smart mode, keeping everything else identical.
Actions.
- Deploy with no placement configuration and confirm the Worker is live.
- Send 20 sequential requests to each route, spaced far enough apart that you are not measuring your own client.
- In Workers Logs, record CPU time, wall time, and invocation status. Note which handler shows a large gap.
- Repeat with Smart Placement. Echo the placement header and record whether it reports
local-orremote-. - Query placement status through the API and note success, insufficient invocations, or absence.
- Raise the CPU limit only on Workers Paid, then repeat step 2 and compare status distribution rather than raw latency.
Expected observations (predicted, not measured). The CPU route should show wall time close to CPU time, and on Free it should produce 1102 once the work exceeds 10 ms. The I/O route should show much larger wall time than CPU time and stay within the CPU budget.
Reading the header. A local- header means the request was not forwarded; an insufficient-invocations status means the account lacked traffic from enough locations. High wall time, low CPU time, and no forwarding is the Sydney-to-Frankfurt signature.
Failure checks.
- If every request returns
1102, the CPU work is too large for the plan; reduce the iteration count rather than concluding Workers cannot compute. - A subrequest exception on the I/O route means you exceeded 50 subrequests on Free or a configured limit.
- If wall time is high but CPU time is near zero and placement never forwards, confirm the handler is a
fetchhandler, that static assets are not answering, and that the route reaches the Worker.
Cost dimensions. Request volume and log ingestion dominate, not compute. Twenty requests per handler is negligible against the Free daily allowance of 100,000, but retained logs and any Paid subscription needed to raise the CPU ceiling are billable. Check current pricing before scaling up.
Cleanup. Delete the scratch Worker with wrangler delete, remove any custom route or hostname, and clear log queries or dashboards from the comparison. If you enabled a Paid plan only for the CPU ceiling, confirm whether you still need it.
Report Latency and Compatibility Evidence With Environment Details
A claim about Workers performance is only useful if it names the environment. "The Worker is fast" is not evidence. "On Workers Paid, compatibility date 2026-11-05, deployed in the Frankfurt edge with placement.region = "aws:eu-central-1", p95 wall time was X and CPU p95 was Y over a 24-hour window" is evidence, provided X and Y were measured.
Verification status. Verified against official Cloudflare documentation on 2026-11-05; planning baseline 2026-11-02. No lab was executed: the exercise is design-only and the worked-comparison numbers are illustrative arithmetic, not measurements. No Wrangler version was run, so no startup_time_ms or invocation-log values are reported. Re-check every limit and availability statement at reading time.
Pass/fail evidence for a real upgrade. Use these as gates, not a score:
- Pass — placement.
cf-placementshowsremote-for the placed path, placement status isSUCCESS, and request-duration analytics show the placed cohort at or below the unplaced baseline over the same hours. - Fail — placement. Status is
INSUFFICIENT_INVOCATIONSafter a representative traffic window, orcf-placementstayslocal-while the state is demonstrably remote. The change is then unproven, not necessarily wrong. - Pass — CPU. CPU p95 and the
1102rate stay within the baseline tolerance at the canary percentage, and no newexceededCpuoutcomes appear. - Fail — CPU. A new
1102cluster appears at the canary, or CPU p95 rises without a corresponding change in work performed. - Pass — wall time and memory. Wall p95 is stable, response byte counts match the baseline, and no
exceededMemoryor "Memory limit would be exceeded before EOF" appears. - Fail — compatibility. Response bodies are shorter than the baseline, a previously resolved promise now rejects, or a stream stalls after headers. These are compatibility symptoms even at status 200.
Self-check.
- A Worker in Sydney makes six sequential queries to a Frankfurt primary. CPU time is 5 ms and wall time is 1.6 s. What do you change first? Placement or round-trip count, not CPU. The request is overwhelmingly waiting, so execute near the state, reduce trips, or move the state; confirm with
cf-placementand request duration. - Why can a Worker pass staging on compatibility date 2026-01-15 and fail on 2026-11-17 with unchanged code? The date changes runtime defaults. For example,
pipe_to_backward_propagationbecomes the default on 2026-11-17, so a pipe that used to resolve when the destination closed may now reject. Staging on the old date tested the old contract. - Which problem does streaming actually solve? It reduces memory pressure and improves time to first byte by not buffering the full body. It does not reduce CPU time or create an unbounded compute budget; wall time stays open only while the client remains connected.
Unresolved limitations. Smart Placement cannot be validated from a laptop: it needs consistent traffic from multiple locations and may take up to 15 minutes to analyze a deployment. cf-placement may be removed before Smart Placement exits beta, and host-based placement is experimental. The placement page says placement does not affect RPC methods or named entrypoints, while its own example describes a placed back end invoked over RPC; verify your call path rather than assuming either reading. Region latency depends on network conditions, and limits and flag dates change; the values here are dated 2026-11-05.
References.
- Cloudflare, Placement, last updated 2026-10-12.
- Cloudflare, Limits, last updated 2026-10-29.
- Cloudflare, Compatibility dates, last updated 2026-04-23.
- Cloudflare, Compatibility flags, last updated 2026-09-18.
- Cloudflare, Metrics and analytics, last updated 2026-07-01.
- Cloudflare, Workers Logs, last updated 2026-10-12.
- Cloudflare, Versions and deployments, last updated 2026-09-22.
- Cloudflare, Gradual deployments, last updated 2026-10-18.
- Cloudflare, How Workers works, last updated 2026-09-18.
- Cloudflare, Errors.
- Cloudflare, Hyperdrive, last updated 2026-10-21.
- Cloudflare, Durable Objects data location, last updated 2026-06-26.
- Cloudflare, New placement hints for Workers, 2026-01-22.