Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 36 ยท Projects and Practice

Practice: Cloudflare Scenarios, Exercises and Review

Test your Cloudflare skills with realistic scenarios: Worker design, storage choices, Zero Trust, troubleshooting and cost questions, runnable exercises and a self-scoring review quiz.

You now know the platform's main parts: Workers, KV, R2, D1, Access, Tunnel, Gateway and the tools to observe and automate them. This last lesson turns that knowledge into judgment. Each scenario is a short, realistic problem. Think first, then compare with the discussion. After the scenarios there are three small coding exercises and a review quiz.

As with the rest of the chapter, nothing here needs a Cloudflare account. The code exercises run on this page.

How to use this lesson

  1. Read each scenario and decide your answer before opening the discussion.
  2. Write down which product you would use and why, in one sentence.
  3. Look for what could go wrong: consistency, cost, security, limits.

Scenario 1: the feature flag that took a minute

A team stores feature flags in KV. After they flip a flag, some users see the old behavior for about a minute and support complains.

Discussion. That is KV's eventual consistency and cache TTL working as designed (reads may be cached for at least 60 seconds). Options: accept the delay for flags that can tolerate it, version the key (flags:v42) so a deploy points at the new one, or move flags that need instant, consistent changes into a Durable Object or D1 and cache them for a few seconds.

Scenario 2: the 10 GB upload

Users upload large videos through your Worker, which streams them into R2. Uploads over a certain size fail, and Worker CPU is high.

Discussion. The proxy limits request body size on lower plans, and passing bytes through your code wastes CPU. Have the Worker create a presigned URL (or use multipart upload) so the browser uploads directly to R2. Store metadata in D1.

Scenario 3: the SQL bill

A D1-backed blog's bill jumps 50 times after launch even though traffic only doubled.

Discussion. D1 bills rows read. A query without an index on the filter column scans the table, so every request reads thousands of rows. Add indexes (check EXPLAIN QUERY PLAN), cache popular reads in KV or the Cache API, and fetch only the columns you need. See D1.

Scenario 4: the admin panel on the internet

An internal admin panel is reachable at admin.example.com with a username and password. A security review wants SSO and no public origin.

Discussion. Put the app behind Access with SSO, MFA and a group rule, and connect the origin through a Tunnel so inbound ports can be closed. Verify the JWT in the app. Remove the old direct DNS record and firewall rule.

Scenario 5: the redirect loop

After enabling HTTPS redirection at the origin, a site shows "too many redirects" behind Cloudflare.

Discussion. Typical cause: SSL mode Flexible (Cloudflare connects to the origin over HTTP), while the origin redirects HTTP to HTTPS, so the request loops. Install an origin certificate and switch to Full (strict). See troubleshooting.

Scenario 6: the Worker that throws 1101

A new deployment makes some URLs return Cloudflare error 1101.

Discussion. An unhandled exception in the Worker. Run wrangler tail --status error, read the stack trace and fix, or wrangler rollback first if customers are affected. Wrap the handler in try/catch so errors return a controlled 500. See Workers Wrangler.

Exercise 1: choose the storage

Write a function that picks a storage product from a description. Extend the rules so that "counter that must be exact" picks Durable Objects and "audit log you will query by date" picks D1.

JS Exercise: storage chooser

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Exercise 2: a cache key function

A Worker caches API responses. Query parameters like utm_source change the URL but not the content, which wastes the cache. Write a function that builds a cache key by dropping tracking parameters and sorting the rest.

JS Exercise: normalize a cache key

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Try adding a new ignored parameter, then think about what must not be ignored: anything that changes the response (language, page, user-specific values).

Exercise 3: score an Access policy set

Write checks for a list of policies and report risky ones: Bypass on /*, Allow with no Require, sessions over 24 hours.

JS Exercise: policy risk score

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Review quiz

Quick check ยท 7 questions

of 7 answered You scored / 7 ยท perfect!

  1. 1. You need to store 40 million product photos and serve them cheaply worldwide. Which product is the natural base?

    R2 is object storage without egress fees, and a custom domain lets the edge cache serve popular files.
  2. 2. A page shows data that is 50 seconds old after you updated KV. Which explanation fits?

    KV favors fast, cached reads; changes can take at least about a minute to be seen everywhere.
  3. 3. Which Wrangler command tails live errors from production?

    wrangler tail streams logs and exceptions from the deployed Worker, with filters such as --status.
  4. 4. Which two controls together best protect an internal web app?

    Access controls who may enter; Tunnel removes the public attack surface. Add JWT verification in the app.
  5. 5. A browser sends If-None-Match with the file's current ETag. What should the gateway return?

    A matching ETag means the cached copy is valid, so 304 saves the bandwidth.
  6. 6. What is the best response to HTTP 429 from the Cloudflare API?

    Respect rate limits with exponential backoff and a cap on retries.
  7. 7. Which is the safest place for an API key used by a Worker?

    Secrets are encrypted and not stored in source control.

Where to go next

  • Build all three projects from this chapter for real on a free account; nothing teaches like a deploy.
  • Explore products this course only touched: Queues, Durable Objects, Workers AI, Vectorize, Hyperdrive, Images and Stream.
  • Read the official Limits and Pricing pages once a quarter, because both change.
  • Put your configuration in Terraform and your Workers in Git with CI deploys.

Summary

  • Match the product to the shape of the data: KV (read-mostly config), R2 (files), D1 (relations), Durable Objects (coordination).
  • Diagnose problems by locating the failure (edge or origin), recording the Ray ID and checking recent changes.
  • Layer security: Tunnel plus Access plus verification in the app, scoped tokens everywhere.
  • Control cost with caching, indexes and usage alerts.

Next: Back to the Cloudflare track