Portfolio  /  Edge Computing

Membership File
Access Worker

A Cloudflare Worker that gates file downloads by membership tier. No origin server involved — access is checked and enforced at the edge in sub-milliseconds, with three distinct tiers and a clean fallback for non-members.

Cloudflare Workers Edge Computing Access Control Membership TypeScript
0ms
Origin hops
Edge
Only compute
3
Access tiers
The Problem

File downloads were gated at the application layer — which meant every request hit the origin server.

The membership site had three tiers — Free, Pro, and Elite — each with access to a different set of downloadable resources. Access control was handled by the WordPress backend: every download request went to the origin, authenticated against the database, and either served the file or returned a 403.

This added latency on every download, put unnecessary load on the origin server, and made the system fragile. Spikes in download activity directly affected the performance of the rest of the site. The access logic needed to move closer to the user.

What Was Built

All access logic moved to the edge.

Edge-Native Access Control

A Cloudflare Worker intercepts every file request before it reaches the origin. The worker verifies the JWT from the request header, reads the membership tier from Workers KV, checks the requested path against the tier's allowed paths, and either streams the file from R2 or returns the appropriate error — all at the edge.

Three-Tier Path Routing

Files are stored in an R2 bucket under tier-prefixed paths: /files/free/, /files/pro/, and /files/elite/. The worker maps each membership tier to its allowed path prefixes. Free members can only access /free/, Pro members access /free/ and /pro/, and Elite members access everything.

Typed in TypeScript

The entire worker is written in TypeScript with strict types on request context, KV bindings, R2 object responses, and error codes. This makes the tier logic explicit and auditable. Adding a new tier or changing path rules is a one-line config change, not a logic rewrite.

The Outcome

Origin server removed from the download path entirely.

Zero origin hops for file downloads

Every download request is now handled entirely by the Cloudflare Worker. The origin server receives no download traffic at all. Spikes in download activity no longer affect site performance, and there is no database query on each file request.

Correct responses for every access case

Allowed requests receive a direct file stream. Requests from members whose tier is too low receive a 402 with an upgrade prompt. Requests with an invalid or expired token receive a 401. No silent failures, no incorrect file exposure.

Runs in every Cloudflare edge location

Because the worker runs on Cloudflare's global network, file access is enforced and served from the edge location closest to the user. Response times are consistent regardless of where members are connecting from.

Start a project

Have something similar in mind?

We build edge computing solutions, Cloudflare Workers, and backend automation for teams who need fast, reliable, infrastructure-light systems.