Edge runtimes trade a nearby execution location for a constrained per-request environment. They may cap CPU, memory, request duration, body size, concurrent outbound connections, or subrequests; exact limits vary by platform and plan. Moving an endpoint to the edge does not move its database nearby. A function that fans out to several distant services can be slower than a regional origin, especially when it repeats the same calls for every cache miss. Decide what belongs at the edge by total path cost: parse, compute, upstream round trips, retries, and failure handling, not only the first network hop from browser to edge.
Edge Compute Budgets and Upstream Fanout
Working case
A case overview page receives 47 requests per second from several regions. An edge handler calls identity, assignment, history, and thumbnail services independently, then waits for all four. Each upstream has a 400-millisecond tail, and a failed thumbnail makes the whole page fail. The new handler returns only the public shell and an authorized case summary from one regional service; optional thumbnails load separately with a clear fallback. The edge enforces an overall deadline and a per-upstream budget. It does not retry a slow identity lookup twice while the browser abandons the request.
Implementation boundary
function withinEdgeBudget(attemptedCalls, bufferedBytes, elapsedMs) {
return attemptedCalls <= 3 && bufferedBytes <= 47000 && elapsedMs < 900;
}
console.log(withinEdgeBudget(4, 29000, 620));
// Output: falseWrite an explicit dependency graph for each edge route. Set a request deadline and pass shorter cancellation budgets to upstream calls. Cap parallel fanout, response bytes, and decoded memory. A failed optional dependency should degrade only its own task; a failed authorization dependency must deny or return an unavailable state, never permit by default. Retry only when the operation is safe and within the remaining deadline; a mutation requires its own idempotency contract. Avoid using per-request global memory as durable state because isolates can be evicted or reused unpredictably. Stream large bodies when the runtime and origin support it rather than buffering them entirely. Measure tail latency from browser through every upstream, not just edge execution time.
Cost and boundaries
With F independent upstream calls, request cost is at least O(F) subrequests; parallel execution can reduce ideal elapsed time to the slowest call but raises load on all dependencies. If every dependency retries R times, worst-case attempts approach O(F × R). Large JSON transforms add O(B) CPU and memory for B bytes when fully buffered. A nearby edge cannot hide a 400-millisecond distant database round trip. Record p95 and p99 complete response time, subrequests per route, cancellation rates, bytes buffered, limit failures, and origin load. Compare the result with a regional server baseline before moving more work.
Failure trace
Throttle the assignment service while thumbnail and history still respond. The private case must not be returned without its authorization decision. Make the thumbnail time out; the case summary should remain usable with a missing-image label. Send a payload larger than the buffering budget and require streaming or controlled rejection. Cancel the browser request and verify upstream fetches stop where supported. Force a platform CPU or subrequest limit in staging and make the route fail with a bounded error rather than an incomplete success. Repeat at 47 simultaneous requests to expose multiplied fanout.
Verification
- Every edge route has explicit subrequest, memory, and deadline budgets.
- Authorization failure never becomes a permissive fallback.
- End-to-end latency is compared with a regional baseline.
Practice drill
Give the overview route a 900-millisecond total deadline, a 300-millisecond assignment budget, and a maximum of three upstream calls. Simulate identity success, assignment timeout, and thumbnail failure in different orders. Record upstream attempt count, response status, bytes buffered, and total latency. Then compare the edge route with a single regional origin endpoint under the same cases. Keep the architecture that meets the task budget and denial contract, even if it runs farther from the browser.
Decision note
Move only bounded work to the edge; total dependency path determines latency and correctness.
Common Mistakes
- Assuming nearby execution makes distant data access fast.
- Retrying every upstream independently without a total budget.
- Using isolate memory as durable workflow state.
Related lessons
Edge Runtime and Origin Boundaries; Edge Request Normalization and Origin Trust; Edge Cache Locality, Invalidation, and Private Scope; Edge-to-Origin Write Routing and Consistency; Rate Limits and Request Budgets; Load Tests and Capacity Budgets.
Apply and check
Build Project: edge permit case delivery and review Web Development: edge and origin contracts quiz.
