skip to content

Edge Compute

Workers run JavaScript, TypeScript and WebAssembly in V8 isolates at every Cloudflare location, wired to resources through bindings. Interviewers ask what the isolate allows and costs.

on this pageshow

explore

questions

page 1 of 2

In Cloudflare Workers, how does a var differ from a secret, and how does each one reach the Worker's code?

level: juniorimportance: must knowfreq 72%

answer

  1. plaintext config versus encrypted value
  2. the vars block in the Wrangler file
  3. wrangler secret put deploys
  4. same kind of value on env

basics

~20 s

A var is plaintext configuration declared under vars in the Wrangler file or the dashboard; a secret is an encrypted value set with wrangler secret put and never displayed again. Both arrive on env as ordinary values.

solid answer

~50 s

Both are bindings on `env`, but they live in different places. A **var** sits in the `vars` block of `wrangler.jsonc` (or is added in the dashboard), is committed with the code and stays readable; it can be a string or a JSON value, so `"RETRY_LIMIT": 3` arrives as a number. A **secret** is set out of band with `npx wrangler secret put PROVIDER_API_KEY` (typed at a prompt or piped in), `wrangler secret bulk` for many at once, or the dashboard's Secret type; it is stored encrypted and its value is hidden in Wrangler and the dashboard afterwards. `wrangler secret put` creates a new version of the Worker and deploys it immediately. Inside the Worker there is no difference: `env.PROVIDER_API_KEY` is just a string. A `wrangler deploy` overwrites vars edited in the dashboard unless `keep_vars` is set, but it never deletes a secret; that takes `wrangler secret delete`.

code

json · 9 lines
json
{
  "name": "payments-webhook",
  "main": "src/index.js",
  "compatibility_date": "2026-10-01",
  "vars": {
    "REFUNDS_ENABLED": "false",
    "RETRY_LIMIT": 3
  }
}

go deeper

for a junior

Recall where each lives: vars in the vars block of the Wrangler file, secrets set with wrangler secret put, and both read as env.NAME in the handler.

for a middle

Explain that secret put deploys a new version at once, that vars can carry JSON types, and that a deploy overwrites dashboard vars unless keep_vars is set.

for a senior

Show the habits that keep credentials out of repositories and logs, and know that vars and secrets share one per-Worker count of 64 or 128.

for a principal

Frame where the line sits for a team: which values count as secrets, who may run secret commands, and when per-Worker secrets give way to account-level ones.

## Two kinds of value on `env` A Cloudflare Worker receives its configuration through **bindings**: named properties on the `env` object that the runtime passes to every handler, as in `fetch(request, env, ctx)`. Most bindings hand the Worker a resource such as a KV namespace or an R2 bucket. Two binding types carry plain values instead: - **Environment variables**, usually called **vars**: text or JSON values for ordinary configuration, such as a feature flag, a region or a retry limit. - **Secrets**: encrypted text values for credentials, such as a payment provider's API key or a webhook signing token. Cloudflare's documentation states the relationship directly: secrets *are* environment variables, with one difference. A secret's value is not visible in Wrangler or the dashboard after you define it. To the running Worker nothing distinguishes the two; the value is passed through exactly as it was defined. ## Vars: configuration that travels with the code A var is declared in the `vars` block of the Wrangler configuration file (`wrangler.jsonc` or `wrangler.toml`), so it is versioned and reviewed with the code: - **Values may be strings or JSON.** A JSON number, boolean or object arrives on `env` with that type, so `"RETRY_LIMIT": 3` is the number 3 and `"PROVIDER": { "region": "eu" }` is an object whose `region` can be read directly. A quoted `"false"` stays the string `"false"`, which is truthy in an `if`. - **They change only through a deploy.** A new value in the file reaches the Worker when the next version is deployed, which makes vars a poor fit for anything that must flip at run time without one. - **Everyone with the repository can read them.** That is the point for configuration and the reason a var must never hold a credential. - **The file is the source of truth.** Vars can also be added in the dashboard under **Settings > Variables and Secrets**, but the next `wrangler deploy` overwrites dashboard-edited vars with the file's values unless the file sets `keep_vars: true` (or the deploy passes `--keep-vars`). ## Secrets: set out of band, never shown again A secret never appears in the Wrangler file. It is created through one of these paths: 1. `npx wrangler secret put PROVIDER_API_KEY` prompts for the value, or reads it from piped standard input, so it never lands in a tracked file. 2. `npx wrangler secret bulk secrets.json` creates or updates many secrets in one request (up to 100 per command) from a JSON or `.env`-style file. 3. The dashboard's **Secret** type does the same through the UI; the value is hidden as soon as it is saved. `wrangler secret list` prints the names and the type `secret_text`, never the values. Each `wrangler secret put` or `wrangler secret delete` **creates a new version of the Worker and deploys it immediately**. A team that ships through gradual deployments uses `wrangler versions secret put` instead, which only creates a version for a later `wrangler versions deploy`. ## What a deploy does to each | | Var | Secret | |---|---|---| | Declared in | `vars` in the Wrangler file, or the dashboard | `wrangler secret put` or `bulk`, or the dashboard | | Readable after saving | Yes, in the file and the dashboard | No; only the name is listed | | Stored as | Plaintext | Encrypted | | Value types | String or JSON | String | | On `wrangler deploy` | Replaced by the file's `vars` unless `keep_vars` | Kept until `wrangler secret delete` | | In the Worker | `env.NAME` | `env.NAME` | ## Limits shared by both Vars and secrets draw on one count per Worker: **64 on Workers Free and 128 on Workers Paid**, each value up to **5 KB**. A credential that many Workers need is a reason to look at account-level secrets in Secrets Store, which reach the Worker as a different binding type with an asynchronous `get()`. ## A working rule - If a value would cause harm in a public repository, it is a secret. - If it differs between deployments but is harmless (a region, a timeout, a feature flag), it is a var. - Treat a secret in code like any string you must not print: the runtime hands the Worker the plain value, so a `console.log` of it ends up in logs like any other text. - Read flags explicitly (`env.REFUNDS_ENABLED === "true"`) or declare them as JSON booleans, so a quoted `"false"` cannot switch a feature on.

  • Why does `if (env.REFUNDS_ENABLED)` take the branch when the Wrangler file sets that var to "false"?
    A quoted value in `vars` arrives as the string `"false"`, and any non-empty string is truthy. Compare explicitly (`env.REFUNDS_ENABLED === "true"`) or declare the var as the JSON boolean `false`, which reaches `env` as a boolean. Numbers behave the same way: `3` arrives as a number, `"3"` as a string.
  • A teammate changed a var in the dashboard to fix production; what happens on the next `wrangler deploy`?
    Wrangler overwrites it with the value in the Wrangler file, because the file is treated as the source of truth for vars. Copy the change into the file, or set `keep_vars: true` so dashboard vars survive deploys. Secrets are unaffected either way: a deploy never deletes them, only `wrangler secret delete` does.

  • Putting an API key in vars because the repository is private.
  • Expecting wrangler deploy to delete a secret that the Wrangler file does not mention.
  • Believing secrets reach the Worker encrypted and must be decrypted in code.
  • Assuming wrangler secret put only stages the value until the next deploy.
  • Treating the quoted var "false" as a boolean false in an if check.
open as a page

In Cloudflare Workers, what does an ES module Worker export, and what do the fetch handler's request, env and ctx parameters carry?

level: juniorimportance: must knowfreq 75%

basics

~20 s

An ES module Worker's default export is an object of handlers such as fetch and scheduled. fetch(request, env, ctx) gets the Request, env with bindings, vars and secrets, and ctx with waitUntil() and passThroughOnException(), and returns a Response.

open as a page

In Cloudflare Workers, what is the difference between CPU time and wall time, and which one does the CPU limit count?

level: juniorimportance: must knowfreq 70%

basics

~20 s

CPU time counts only the Worker's code actually running; wall time also includes waiting on fetch(), KV or a database. The CPU limit counts CPU time: 10 ms on Workers Free, 30 seconds by default on Workers Paid, up to 5 minutes.

open as a page

How do you stream a deployed Cloudflare Worker's live logs with `wrangler tail`, and which filters narrow what it shows?

level: juniorimportance: must knowfreq 45%

basics

~20 s

wrangler tail streams a deployed Worker's invocations live to the terminal: request, outcome, console output and exceptions. Filters such as --status error, --search, --method, --header, --ip self and --version-id narrow the stream, and nothing is stored.

open as a page

In Cloudflare Workers, why does calling headers.set() on a Response returned by fetch() throw, and how do you change its headers?

level: juniorimportance: must knowfreq 60%

basics

~20 s

A Response returned by fetch(), like the incoming Request, has immutable headers, so set() throws a TypeError. Build a copy with new Response(upstream.body, upstream), which keeps status and headers and streams the body unread, then edit the copy.

open as a page

Why does a Cloudflare Worker reach its KV namespace and R2 bucket through bindings on env rather than through an API token?

level: middleimportance: must knowfreq 58%

basics

~20 s

A binding hands the Worker a ready-made object for one resource, such as env.RECEIPTS for an R2 bucket, with the permission built in. No token sits in code to leak, and no REST endpoint has to be called.

open as a page

In Cloudflare Workers, what does nodejs_compat turn on, and how does the compatibility date decide whether a Worker has it?

level: middleimportance: must knowfreq 48%

basics

~20 s

nodejs_compat lets a Worker import the Node.js built-ins workerd implements and, on newer dates, use Buffer and process globals plus Wrangler's unenv polyfills. It is on by default from compatibility date 2026-08-04; earlier dates opt in.

open as a page

In Cloudflare Workers, what does ctx.waitUntil() let a fetch handler do after returning its response, and what limits apply?

level: middleimportance: must knowfreq 68%

basics

~20 s

ctx.waitUntil(promise) lets a fetch handler return its response while the runtime keeps running that promise, for up to 30 seconds after the response is sent or the client disconnects, shared across every waitUntil() call in the request.

open as a page

In Cloudflare Workers, how do you proxy or transform a multi-gigabyte CSV download without buffering it, and why not call text()?

level: middleimportance: must knowfreq 50%

basics

~20 s

Return the origin's body stream, or pipe it through a TransformStream, so bytes flow to the client as they arrive. text() reads the whole body into the isolate's 128 MB of memory and consumes the one-use body stream.

open as a page

A Cloudflare Worker that redirects visitors by country sometimes sends one user to another country's site under load; how can module-scope state cause this?

level: seniorimportance: must knowfreq 60%

basics

~20 s

One Workers isolate serves many requests at once, and module-scope variables are shared by all of them. If the handler stores the visitor's country in one and then awaits, another request overwrites it before the first reads it back.

open as a page

A production Cloudflare Worker API returns intermittent 500s; how do you find the failing invocations and their cause with Workers Logs and `wrangler tail`, without redeploying?

level: seniorimportance: must knowfreq 40%

basics

~20 s

Query Workers Logs for $workers.outcome = "exception" and for a 5xx $workers.event.response.status, because a handled 500 finishes with outcome ok. Read the exception and structured console.error fields, then confirm live with wrangler tail --status error or --search.

open as a page

In Cloudflare Containers, how does a request from a Worker reach a container instance, and what must the Wrangler file declare?

level: juniorimportance: should knowfreq 32%

basics

~20 s

A Worker reaches a container only through a Durable Object: it gets a stub by name, and that object starts its container and forwards traffic. Wrangler declares a containers entry (class and image), the binding and the class.

open as a page

In Cloudflare Workers, what is request.cf, what do properties such as country, colo and asn tell you, and how far can you trust them?

level: juniorimportance: should knowfreq 30%

basics

~20 s

request.cf is a read-only, Workers-only object that Cloudflare's network attaches to an incoming request: country, colo (the data center's IATA code), asn, tlsVersion and more. Clients cannot set it, but values are IP-derived estimates that may be null or absent.

open as a page

In Cloudflare Workers, what is a service binding, how is it declared, and how does a fetch() call through it differ from an RPC call?

level: juniorimportance: should knowfreq 42%

basics

~20 s

A service binding lets one Worker call another on the same account without a public URL. The caller lists it under services in its Wrangler file, then forwards a Request with env.NAME.fetch() or calls a WorkerEntrypoint method as env.NAME.method().

open as a page

In Cloudflare Workers, what does `import { env } from "cloudflare:workers"` let module-level code do, and which binding calls still fail there?

level: middleimportance: should knowfreq 30%

basics

~20 s

It exposes the Worker's bindings at module level and in nested functions without passing env along. Top-level code may read vars and secrets, but I/O such as a KV get or a service binding call throws outside a handler.

open as a page

In a TypeScript Cloudflare Worker, what does `wrangler types` generate from the Wrangler file, and how does it type vars and secrets?

level: middleimportance: should knowfreq 28%

basics

~20 s

wrangler types writes worker-configuration.d.ts with an Env interface listing every binding's type, plus runtime types for the compatibility date. Vars get literal types by default; secrets are typed string, named from secrets.required when it is declared.

open as a page

In Cloudflare Workers, what does a Worker's compatibility_date pin, and how do compatibility_flags adjust what that date turns on?

level: middleimportance: should knowfreq 42%

basics

~20 s

A compatibility_date gives a Worker every gated runtime change dated on or before it, so its behaviour holds until the team changes the date and redeploys. compatibility_flags enable one change early or keep one off.

open as a page

In Cloudflare Containers, how do instance_type and max_instances size a service, and what happens when a start would exceed max_instances?

level: middleimportance: should knowfreq 25%

basics

~10 s

instance_type fixes each instance's vCPU, memory and disk, from lite (the default) up to standard-4 or a custom type. max_instances, default 20, caps concurrently running instances; a start beyond it errors instead of queueing.

open as a page

In Cloudflare Containers, what happens when a request reaches a stopped instance, and what keeps an instance running between requests?

level: middleimportance: should knowfreq 30%

basics

~20 s

A stopped instance cold-starts in seconds, and start() returns before its port is ready, so code polls first. It runs while its Durable Object is active, then for the inactivity timeout or sleepAfter, and restarts with a fresh disk.

open as a page

In Cloudflare Workers, how do Cron Triggers in triggers.crons invoke a scheduled() handler, and how does one handler serve several schedules?

level: middleimportance: should knowfreq 48%

basics

~10 s

Each expression in triggers.crons fires on UTC and calls the Worker's scheduled(controller, env, ctx) handler. One handler serves every schedule, so it branches on controller.cron, the exact expression string that fired.

open as a page

In Cloudflare Workers, what does the 1-second startup time limit measure, and how do you find what makes a Worker exceed it?

level: middleimportance: should knowfreq 35%

basics

~20 s

The limit caps the CPU time a Worker spends parsing and running its global scope, the code outside its handlers, when an isolate loads. Uploads over it fail with Script startup exceeded CPU time limit (10021); wrangler check startup profiles that phase.

open as a page

In Cloudflare Workers, what counts as a subrequest, and how many can one invocation make on each plan?

level: middleimportance: should knowfreq 40%

basics

~20 s

A subrequest is any outbound fetch() or binding call to a Cloudflare service such as KV, R2 or D1, and each redirect hop counts. Free allows 50 external and 1,000 Cloudflare-service subrequests per invocation; Paid defaults to 10,000, settable to 10 million.

open as a page

In Cloudflare Workers, what does the Wrangler `observability` block turn on, and what does `head_sampling_rate` keep or drop?

level: middleimportance: should knowfreq 40%

basics

~20 s

The observability block makes Cloudflare store a Worker's invocation logs, console output and uncaught exceptions in Workers Logs; traces need traces.enabled. head_sampling_rate (default 1) keeps that fraction of invocations whole and stores nothing from the rest.

open as a page

Why does a bundled Cloudflare Worker's production stack trace point at the wrong file and line, and what does `upload_source_maps` change?

level: middleimportance: should knowfreq 30%

basics

~20 s

Wrangler deploys bundled, often minified JavaScript, so runtime stack traces point into the bundle. With upload_source_maps: true the map is uploaded with the version, and Cloudflare remaps uncaught-exception traces in real-time logs, Tail Workers and Issues.

open as a page

What is a Cloudflare Tail Worker, how does a producer Worker attach one with `tail_consumers`, and what does its `tail()` handler receive?

level: middleimportance: should knowfreq 30%

basics

~20 s

A Tail Worker is a Worker with a tail() handler that Cloudflare invokes after each invocation of a producer Worker listing it in tail_consumers. It receives items with the outcome, request, response status, console logs and exceptions.

open as a page

In Cloudflare Workers RPC, how does a Worker expose methods with WorkerEntrypoint, which members can a caller reach, and what do named entrypoints add?

level: middleimportance: should knowfreq 30%

basics

~20 s

A Worker extends WorkerEntrypoint from cloudflare:workers and its public prototype methods and getters become RPC methods; private fields, instance properties and arrow-function fields stay hidden. Each named export is a separate entrypoint a binding selects with entrypoint.

open as a page

In Cloudflare Workers RPC over a service binding, what can a method accept and return, and what happens to functions, class instances, streams and errors?

level: middleimportance: should knowfreq 25%

basics

~20 s

Structured-clonable values are copied. Functions and RpcTarget instances become stubs that call back to their origin, other classes fail to serialize, byte streams, Request and Response stream with flow control, and errors arrive by name and fields, not class.

open as a page

When a team moves a payment provider key from per-Worker secrets into Cloudflare Secrets Store, what changes in configuration, permissions and Worker code?

level: seniorimportance: should knowfreq 20%

basics

~20 s

The key becomes one account-level secret bound into each Worker through secrets_store_secrets. Binding needs a role or token that can bind plus the workers scope, and code reads it with await env.PROVIDER_KEY.get() instead of a string.

open as a page

After `wrangler secret put` replaced a Cloudflare Worker's payment provider key, some requests kept using the old key; what in the code explains it?

level: seniorimportance: should knowfreq 36%

basics

~20 s

A provider client built in global scope from the old secret. A deploy that changes only bindings may reuse running isolates, so a module-level object keeps the value it was built with, while each request's env carries the new one.

open as a page

showing 1–30 of 45