A serverless invocation runs inside a provider-defined resource envelope. CPU time, elapsed duration, memory, request size, outbound connections, and subrequests may have separate ceilings. A handler that waits on a database can use little CPU while consuming its entire wall-clock budget; a busy serialization loop can hit a CPU ceiling before the caller's timeout. The contract must name the caller deadline, function budget, dependency timeout, and fallback behavior. Provider limits change, so record the effective environment and tier alongside the release.
Serverless invocation budgets: separate CPU, elapsed time, and I/O
Operational decision
An invoice-preview endpoint has a 4.5-second client budget. Assign 350 milliseconds to edge routing, 900 to authentication, 1,600 to ledger lookup, 800 to rendering, and 850 to residual network and retry margin. Pass the remaining deadline to each dependency; do not give every call its own full 4.5 seconds. Return a bounded failure when the ledger cannot answer rather than allowing the platform to terminate the invocation after a partial response. In a disposable test, inject a slow ledger and a CPU-heavy rendering payload separately. Capture elapsed time, CPU time, subrequest count, response code, and the version handling the request. A timeout that leaves a downstream write uncertain requires reconciliation before retry.
Invoice preview deadline: 4500 ms
Edge and routing: 350 ms
Authentication: 900 ms
Ledger lookup: 1600 ms
Rendering: 800 ms
Residual margin: 850 ms
Failure: no partial invoice is publishedCost and verification
One request that makes D sequential dependency calls has O(D) network waits even if local CPU work is small. Parallel calls can reduce latency but increase concurrency and connection demand. Measure duration and CPU independently at p95 and p99; a cheaper execution tier can fail a workload that previously met its deadline. Keep a margin for queueing and client transit, not just handler code.
Common Mistakes
- Do not confuse CPU time with elapsed time.
- Do not assign the full caller deadline to every nested call.
- Do not retry an uncertain write without checking its result.
Connected lessons
- DevOps: delivery, infrastructure, and reliable operations
- Retries and timeouts: bound the cost of a failed request
- gRPC deadlines: spend one request budget across every downstream call
- Observability: join metrics, logs, and traces
