Replies: 2 comments
-
|
You're basically already at the right shape — signed short-lived tokens + Worker-mediated access on a custom domain, with the Cache API doing the heavy lifting. But there are a few levers that make it noticeably cheaper and/or more correct than the obvious implementations. What actually belongs on each hopThink in three layers:
The rule: a segment URL, once minted, is a bearer credential for a short window, and the edge cache keys on it. So the same segment fetched by ten subscribers gets one R2 read + one cached response at the colo, regardless of who's watching. Concrete pattern
Where HLS encryption fits (and usually doesn't)AES-128 HLS encryption gives you "the key endpoint is the real gate, segments are useless without it." It's architecturally appealing, but:
Skip it for access control. Keep it only if you need DRM-adjacent obfuscation (and at that point you're looking at Widevine/FairPlay, not AES-128). Answering the literal question
Yes. With the two refinements above — (a) gate on the playlist, not each segment; (b) key the cache on the path, not the token — this is the pattern Cloudflare Stream itself uses internally. At 14.5k requests/day you're nowhere near any limit; the optimizations are more about protecting future growth than current cost.
The one I haven't mentioned: if your videos are <100 MB and you're comfortable with a warmer tail, consider pre-emitting segments through a custom domain in front of R2 with a single bucket-scoped Worker, and skip HLS for short content. A single |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Question
Is there a better way to achieve fine-grained per-video access control while minimizing Workers requests?
Options I've considered:
Requirements
Is the current time-window token + Worker + edge cache approach the recommended solution? Or is there a pattern I'm missing?
Usage: ~14,500 Workers requests/day (well under free tier), just want to confirm this is best practice.
Beta Was this translation helpful? Give feedback.
All reactions