As the lead retiring a zone's Page Rules, how do you decide what belongs in Cloudflare Rules, in Snippets, or in a Worker?
answer
- declarative first, code last
- quotas and plan boundaries
- 5 ms, 2 MB, 32 KB
- no CLI, versions or logs
- who may edit the zone
basics
~20 sDefault to declarative Rules: no code, no per-request cost, visible in Cloudflare Trace. Use a Snippet on a paid plan for small stateless JavaScript, and a Worker when you need bindings, state, logs, versioned rollouts or more than 5 ms.
solid answer
~40 sI start from the declarative products: Single and Bulk Redirects, Transform Rules, Origin Rules and Configuration Rules cover redirects, rewrites, headers, routing and feature switches with no code and no per-request bill, inside per-plan quotas and with plan gates such as regex on Business and Host overrides on Enterprise. When the logic needs code but no state, such as reacting to the origin's response, checking a JWT or setting `x-real-ip` on the origin request, I allow a Snippet on Pro and above, within 5 ms, 2 MB and 32 KB, accepting no Wrangler deploys, no versions and no logs. Anything needing bindings, secrets, heavier compute, observability or gradual rollout becomes a Worker. Then I set governance: role-scoped edit rights, Terraform or API changes with `dry_run=true` validation, and Cloudflare Trace checks before release.
go deeper
Know the three places edge logic can live, declarative Rules, Snippets and Workers, and that Snippets need a paid plan.
Explain what each tier can do: rule actions and their plan gates, Snippet limits of 5 ms, 2 MB and 32 KB with no bindings, and what only a Worker offers.
Recognise the cases rules cannot handle, such as response-dependent routing or protected IP headers, and the operational gaps of Snippets when one fails in production.
Own the default and the escalation path, plus the governance around them: who edits rules, how changes are reviewed and validated, and when moving to code is worth its operating cost.
## The decision Retiring Page Rules forces a choice for every behaviour they carried: express it as a declarative rule, as a **Snippet**, or as a **Worker**. All three run on Cloudflare's network in front of the origin. They differ in what they can do, what they cost, who can change them and how a mistake is caught. The lead's job is to set a default and the conditions for leaving it, so that a team does not end up with one Worker per header, or with a redirect map nobody can review. ## Three tiers | | Rules products | Snippets | Workers | |---|---|---|---| | What you write | An expression and a fixed action | JavaScript with a `fetch` handler | A full application, in several languages | | Plans | All plans, rule quotas per plan | Pro, Business and Enterprise | All plans, usage-based pricing with a free tier | | Run cost | Included in the plan | No additional cost | Billed by usage | | Limits | Rule counts per product | 5 ms, 2 MB memory, 32 KB package, 2 to 5 subrequests by plan | Workers platform limits | | State and bindings | None | None | KV, D1, Durable Objects, secrets | | Release | Dashboard, API, Terraform | Dashboard, API, Terraform | Wrangler, API, Terraform; versions and gradual rollout | | Debugging | Cloudflare Trace | Cloudflare Trace | Logs, live tail, traces | ## When a rule is enough Default to the declarative products, because they are the easiest to read, review and debug, and there is no code to break: - redirects that follow a pattern (Single Redirects) or a list (Bulk Redirects); - path and query rewrites, and setting or removing headers (Transform Rules); - another origin port, or on Enterprise another host (Origin Rules); - turning a feature on or off for some requests (Configuration Rules). Watch the edges of this tier: regular expressions need Business or Enterprise, Host and DNS record overrides need Enterprise, and the per-product rule counts (10, 25, 50 and 300 by plan) can run out on a busy zone. ## When a Snippet earns its place Snippets extend Rules with short JavaScript. Each one is tied to a snippet rule expression, runs late in the request phases and inherits the changes that earlier rule phases made. Snippets fit logic a rule cannot express but that needs no state: - decisions that depend on the origin's response, such as retrying another origin after an error; - validating a JWT or signing a request before it goes on; - setting a header Transform Rules refuse to touch, such as `x-real-ip`, on the subrequest to the origin. The price is operational. Snippets have no Wrangler deploy, no Version Management, no gradual rollout and no execution logs, and a Snippet that overruns its limits answers the visitor with an error, such as 1203 for CPU time or 1204 for memory. ## When it has to be a Worker Choose a Worker when the logic needs bindings or stored state, environment variables or secrets, heavier compute, logs and traces, or staged rollouts with rollback. Unlike Page Rules, modern Rules products keep running for requests a Worker handles, so rules and Workers can be layered: rules do the routing and headers, the Worker does the application logic. ## Governance a lead must set 1. **Ownership.** Decide who may edit zone rules. Transform Rules require the Firewall role or one of the Administrator roles, so map roles to teams on purpose instead of handing out Administrator. 2. **Change control.** Keep rules and Snippets in Terraform or behind the API so changes are reviewed. The Rulesets API's `dry_run=true` option checks expressions, action parameters, permissions and quotas without publishing anything. 3. **Testing.** Require a Cloudflare Trace check for every rule that touches paths another rule matches. 4. **Escalation path.** Write down when a rule becomes a Snippet and when a Snippet becomes a Worker, so each move is a decision rather than drift. ## The costs you carry Rules cost nothing to run but scatter one behaviour across several products. Snippets keep the logic in code without per-request billing but give up observability and safe rollout. Workers give the most power and the most to operate. No answer suits every zone: a marketing site may never need a Worker, and an API platform may outgrow Snippets within a quarter.
- Your origin needs X-Real-IP set to the visitor's address. Why can't a Request Header Transform Rule do it, and what can?Transform Rules cannot modify headers used to identify the visitor's IP or protocol, such as x-forwarded-for, true-client-ip, x-real-ip and x-forwarded-proto. A Snippet or Worker can set x-real-ip on its fetch() subrequest, to a valid IP address, though not on cross-zone subrequests. Often the simpler answer is to read the CF-Connecting-IP header Cloudflare already sends.
- What does choosing a Snippet over a Worker cost you operationally?You lose Wrangler deploys, Version Management, gradual rollouts, rollback to earlier versions and execution logs, and a Snippet that exceeds its limits fails the request with an error such as 1203 or 1204. You still get Terraform or API management and Cloudflare Trace to see which Snippets ran.
- How do you keep a broken rule expression from reaching production when several teams edit one zone?Manage rules through Terraform or the API with review, validate each change with the Rulesets API dry_run=true option, which runs the same authorization and validation checks without publishing, test affected paths in Cloudflare Trace, and scope roles so only owning teams can edit.
- Snippets are available on every plan, Free included.
- A Snippet can read a KV namespace or a secret just as a Worker does.
- Putting logic in a Worker switches off the zone's Origin and Configuration Rules for those requests.
- A Request Header Transform Rule can set X-Forwarded-For for the origin.
- Snippets can be rolled out gradually and rolled back like Worker versions.
Assumes Cloudflare as of 2026-10-10: Page Rules deprecated, Snippets generally available since April 2025 on Pro, Business and Enterprise only, and the Rulesets API dry_run option added in September 2026.