skip to content

How do AWS Lambda, Cloud Run and Cloudflare Workers differ in limit and billing shape for a function that mostly waits on network calls?

level: middleimportance: should knowfreq 38%

answer

  1. which clock is running
  2. wall-clock versus CPU time
  3. who shares the billed instance
  4. waiting is free on one of them

basics

~20 s

AWS Lambda bills and limits wall-clock duration per invocation, so waiting is paid per request; Cloud Run bills instance time that concurrent requests share; Cloudflare Workers bills and limits CPU time, so waiting on the network costs almost nothing.

solid answer

~40 s

The question is which clock each platform runs. AWS Lambda bills per request plus duration times configured memory, and its time limit is wall-clock, so an invocation waiting on a slow partner API pays for every second it waits, once per request, since by default one environment serves one invocation. Cloud Run bills `vCPU` and memory for instance time, either only while requests are in flight or for the instance's whole life, and several concurrent requests share that billed time, so waiting is amortised. Cloudflare Workers bills per request plus CPU time, and its limit is on CPU time, so time spent awaiting a `fetch` neither counts against the limit nor shows on the bill. Azure Functions depends on the plan: memory-time per execution on consumption plans, instance time on pre-warmed or dedicated ones.

go deeper

for a junior

Recall the three clocks: wall-clock per invocation on AWS Lambda, instance time on Cloud Run, CPU time on Cloudflare Workers.

for a middle

Explain why a handler waiting on a slow call is billed fully per request on one platform, shared on another and nearly free on a third.

for a senior

Show you check limits on the same clock as billing: a wait-heavy handler safe under a CPU-time limit can still die under a wall-clock limit when a partner hangs.

for a principal

Use clock shapes to steer workload placement across platforms, while recognising that migration, tooling and data locality often outweigh the per-request difference.

## Same function, three different clocks Picture an API handler that receives a request, calls a slow partner service, waits most of the time for its answer, and returns a small response. On paper the work is the same everywhere. On the bill and against the limits it is not, because each platform measures a different clock: - **Wall-clock duration**: elapsed time from the start of the invocation to its end, waiting included. - **Instance time**: how long a sandboxed instance exists or is busy, no matter how many requests it holds. - **CPU time**: time the processor actually spends running your code; waiting on the network does not count. Knowing which clock a platform runs is what lets you predict cost and failure before a migration, not after. ## AWS Lambda: wall-clock per invocation - **Billing**: a charge per request plus **duration multiplied by the configured memory**. Duration is wall-clock, so the seconds spent waiting on the partner are billed in full. - **Limit**: a hard per-invocation **wall-clock time limit measured in minutes**; a call that hangs long enough ends the invocation. - **Sharing**: by default each execution environment serves one invocation at a time, so ten requests waiting in parallel are ten billed durations. - **Other shapes**: request and response payload sizes are capped for synchronous calls, so large uploads go straight to object storage through a signed URL. ## Cloud Run: instance time, shared by concurrent requests - **Billing**: `vCPU` and memory for **instance time**. With request-based billing, an instance is billed while at least one request is in flight, plus a per-request fee; with instance-based billing, it is billed for its whole lifetime with CPU always allocated. - **Limit**: a **per-request timeout** you configure, wall-clock, with a higher ceiling than most function platforms. - **Sharing**: one instance can serve many requests at once, so many requests waiting on the same partner share one instance's billed time. The waiting is still paid for, but amortised. - **Other shapes**: CPU and memory are sized per instance, separately from each other. ## Cloudflare Workers: CPU time per request - **Billing**: a charge per request plus **CPU time**. Time spent awaiting a network response is not CPU time, so it is not billed. - **Limit**: a **CPU-time limit** per request rather than a wall-clock one; a handler that waits a long time on the network while using little CPU stays within it. - **Other shapes**: each isolate has a **fixed memory allowance** you cannot raise, and there are caps on how many outbound requests one invocation may make. - **The catch**: CPU-heavy work such as parsing a large document or resizing an image hits the CPU limit quickly, and the code runs at the edge, often far from the partner. ## Azure Functions: it depends on the plan - **Consumption-billed plans**: per execution plus **memory multiplied by execution time**, a wall-clock shape similar to AWS Lambda, though one instance may run several executions at once. - **Pre-warmed and dedicated plans**: billed for **instance time** whether busy or idle, closer to an always-on instance. - **Limits**: a function time limit that differs by plan, and an HTTP-triggered function must answer within the front end's idle timeout whatever the function's own limit is. ## Side by side | Platform | Billed clock | Limit clock | Who shares the bill | I/O wait costs | |---|---|---|---|---| | AWS Lambda | wall-clock × memory, per invocation | wall-clock, minutes | nobody by default | full, per request | | Cloud Run | instance time (vCPU, memory) | wall-clock per request | concurrent requests | shared | | Cloudflare Workers | CPU time, plus requests | CPU time per request | n/a | almost nothing | | Azure Functions | memory-time or instance time, by plan | by plan | concurrent executions | depends on plan | ## How to use this in a decision 1. **Profile the workload first**: measure the share of wall time spent waiting versus computing for a typical request. 2. **Map it onto each clock**: a wait-heavy handler is cheapest on a CPU-time model and most expensive on a per-invocation wall-clock model. 3. **Check the limits on the same clock**: a wait-heavy handler that is safe under a CPU-time limit can still be killed by a wall-clock limit when the partner hangs. 4. **Read current numbers from the price lists**: every provider changes figures; the shapes are what stay stable enough to reason about. ## What interviewers listen for A strong answer says *which clock* each platform bills and limits before reaching for any price, and notices that the same slow dependency is a cost problem on one platform and almost free on another.

  • Why can a wait-heavy handler that is cheap on Cloudflare Workers still fail there?
    Waiting is cheap but not unlimited in every way: the code runs at the edge, so a distant partner adds latency to every call, outbound requests per invocation are capped, and any CPU-heavy step such as parsing a large response counts against the CPU-time limit. Cheap waiting does not make heavy computation safe.
  • How does per-instance concurrency change the cost of waiting on Cloud Run compared with AWS Lambda?
    On Cloud Run, requests waiting at the same time can share one billed instance, so the wait is paid once per instance rather than once per request. On AWS Lambda's default model each waiting invocation holds its own environment and its own billed duration, so the same wait is paid once per request.

  • Every function platform bills only for the time your code is computing.
  • A CPU-time limit means a handler can never run longer than that limit in wall time.
  • Cloud Run bills each concurrent request its own full duration, as AWS Lambda does.
  • Pricing shapes can be compared by looking up one headline price per platform.
  • Azure Functions has one billing model regardless of hosting plan.