skip to content

Which function platform would you pick for an image-resizing API, and which for a geography-based redirect, and why?

level: middleimportance: should knowfreq 45%

answer

  1. where does the data live
  2. latency-bound versus compute-bound
  3. what the isolate cannot run
  4. edge in front, region behind

basics

~20 s

An edge isolate runtime such as Cloudflare Workers suits the geography redirect, which needs only request metadata. Image resizing suits a regional platform such as Cloud Run or AWS Lambda, near the stored images and able to run native libraries.

solid answer

~50 s

The redirect is tiny and latency-bound: it reads the country the edge network attaches to each request and returns a redirect, touching no regional data, so an edge isolate runtime like Cloudflare Workers answers it closest to the user. Image resizing is compute-bound, usually needs a native image library and reads originals from object storage in one region, so a regional platform fits: Cloud Run with a container image, AWS Lambda with an image or archive, or Azure Functions. The edge gives up two things the resizer needs: **data locality**, because every call back to the region crosses a long path, and a **full runtime surface**, because an isolate cannot load native code and enforces a tight CPU-time limit. A common final shape puts the edge in front for routing and caching, with the regional resizer behind it.

go deeper

for a junior

Recall that edge runtimes run near users and regional platforms run near data, and that an isolate cannot load native libraries.

for a middle

Explain the choice from three questions: where the data lives, what bounds latency, and what the code needs from the runtime.

for a senior

Show the production shape: an edge function for routing and caching in front of a regional resizer, and the slowdown from sequential edge-to-region calls.

for a principal

Weigh whether running two platform types is worth the extra tooling, on-call knowledge and security review, or whether one regional platform plus a CDN rule is enough.

## Two workloads with opposite shapes A **geography-based redirect** sends a visitor to a country-specific site or blocks a region. Its work is a lookup on request metadata and a redirect response. An **image-resizing API** fetches an original image, decodes it, scales it and encodes a new one. Choosing among **AWS Lambda**, **Azure Functions**, **Cloud Run** and **Cloudflare Workers** for each starts from three questions: - **Where is the data?** The redirect needs only what arrives with the request. The resizer needs originals that live in object storage in one region. - **What bounds the latency?** The redirect is dominated by network distance to the user. The resizer is dominated by CPU time spent decoding and encoding. - **What does the code need from the runtime?** The redirect needs a few lines of logic. The resizer usually needs a mature native image library. ## The redirect belongs at the edge An **edge runtime** runs your code in many locations close to users. Cloudflare Workers does this with **V8 isolates**, which start quickly and run in whichever edge location receives the request. The edge network attaches the client's approximate location (country, sometimes region) to each request, so the function can answer without calling anything. The whole round trip happens near the user, which is the entire point of the workload. The regional platforms could do it too, but every visitor's request would travel to one region and back before being redirected elsewhere. That is the wrong trade for logic that needs no regional data. An edge rule in a CDN configuration might even be enough; a function earns its place when the rules involve logic such as consent checks, A/B splits or allow-lists. ## The resizer belongs in a region **Image resizing** fits a regional platform for three reasons: 1. **Data locality**: the originals sit in a regional bucket. A function in the same region reads them over a short path; an edge location may be far away and pays that distance on every fetch. 2. **Native code**: the fastest image libraries are native. Cloud Run takes them inside a container image, AWS Lambda inside an image or an architecture-specific archive or layer, and Azure Functions inside its package or container on plans that accept one. An isolate cannot load native code; only a WebAssembly build of a library would run there. 3. **CPU and memory**: decoding a large image needs real CPU time and memory. Isolate runtimes cap CPU time per request and give each isolate a modest fixed memory allowance; the regional platforms generally offer more memory, and most of them let you size memory, and in some cases CPU, per function. Among the regional options, Cloud Run suits a team that already ships container images, and AWS Lambda or Azure Functions suits one that wants the platform to wire up object-storage or queue triggers, for example resizing on upload instead of on request. ## What the edge gives up | Concern | Edge isolate runtime | Regional function platform | |---|---|---| | Distance to the user | short, the nearest location | one region away | | Distance to regional data | long, unless the data is replicated to the edge | short | | Runtime surface | web-standard APIs, no native code, no persistent disk | full operating system in a microVM or container | | CPU limit shape | tight CPU time per request | a wall-clock time limit, usually minutes | | Good fit | routing, headers, auth checks, cached responses | compute, native libraries, data-heavy work | An edge function that makes several sequential calls to a regional database can be *slower* than the same function in the region, because each call pays the long path. Edge key-value stores and caches exist to bring read-mostly data close, and some edge runtimes can be asked to run near the backend instead of near the user, but both are workarounds for the same locality cost. ## The usual final shape Real systems often combine the two: - An edge function handles the redirect and also fronts the image URLs, checking signatures and serving cached resized variants. - On a cache miss it forwards to the regional resizer, which reads the original, resizes it and returns a response the CDN caches. - Resized variants can also be produced ahead of time by a regional function triggered when an original is uploaded. ## What an interviewer listens for The weak answer picks one platform for both because "serverless is serverless". The strong answer names the data each workload touches, what bounds its latency, and what the isolate cannot run, then lands on edge for the redirect, region for the resizer, and a cache between them.

  • The redirect now needs each user's saved region preference from a regional database; does it still belong at the edge?
    Only if that data can come close. A per-request call back to the regional database erases the edge's latency advantage. Replicating preferences into an edge key-value store or a signed cookie keeps the decision at the edge; otherwise a regional function, or an edge function that redirects only on request metadata and defers the rest, is simpler.
  • Could the resizer run on Cloudflare Workers at all?
    Sometimes: a WebAssembly build of an image library can run in an isolate, but it must fit the per-request CPU-time limit and the isolate's fixed memory allowance, and it still reads originals across a long path. Large images or heavy formats usually push it back to a region, with the edge caching the results.

  • Running every function at the edge is always faster for users.
  • An edge isolate can run the same native image library a container can.
  • Data locality does not matter because function platforms are stateless.
  • A geography redirect needs a regional database call to find the user's country.
  • Choosing a platform is about price alone, not about where data and users are.