Serving a content-heavy, multilingual web catalogue on serverless infrastructure usually runs into two predictable cost cliffs: database egress (paying per read or per gigabyte every time crawlers and users walk thousands of detail pages) and cold-start latency (watching TTFB spike whenever edge caches expire or a crawler hits long-tail routes).

At DiziLuma, we serve a trilingual (English, Turkish, and RTL Arabic) Turkish television catalogue indexing 374 series (1981–2026), 16,585 static catalogued episodes, plus live 6-hour R2 episode additions (+235 dynamic episodes) across 50,000+ localized sitemap URLs — all running on a single $5/month Cloudflare Workers Paid plan (@opennextjs/cloudflare 1.20.19) with $0 database egress on public catalogue reads and $0.00/month GCP/Firebase billing.

Here is the exact architecture we built in production, why naive edge caching wasn't enough, and the verified metrics we measured under full-site stress tests and authenticated PageSpeed Insights audits.

The Problem: 50,000+ Public URLs, 128 MiB Isolate RAM & Continuous Freshness

Our catalogue workload has four competing constraints:

  1. Large static footprint, tiny isolate memory budget: Across 374 series and 16,585 static episodes, the baseline episode archive weighs ~32.5 MiB across 64 JSON shards (episodes-00.json through episodes-63.json, averaging ~520 KiB per shard), alongside a ~1.1 MiB metadata index. Loading the whole dataset into a V8 Worker isolate would blow past Cloudflare Workers' 128 MiB memory ceiling during concurrent crawls.
  2. Continuous freshness without redeploys: Active Turkish dramas air new episodes every night of the week. Waiting for a full CI build and Worker redeploy every time a new episode publishes is too slow and burns build minutes.
  3. Aggressive crawler bursts: Full technical site crawls walk tens of thousands of URLs across all 64 shards in rapid succession. Any per-request database lookup immediately turns into thousands of Postgres queries and cold-connection overhead.
  4. Cloudflare's Cache API ignores stale-while-revalidate: Standard Next.js Cache-Control: public, max-age=0, s-maxage=600, stale-while-revalidate=3600 headers work on CDN pull zones, but when you call caches.default.match() programmatically inside a Cloudflare Worker, the Cache API drops expired entries at s-maxage instead of serving stale and revalidating asynchronously.

To solve all four together, we wrapped OpenNext (.open-next/worker.js) with a thin custom Cloudflare Worker entrypoint (wrangler.jsonc with limits.cpu_ms: 30000, ASSETS static binding, and two zero-egress R2 buckets: CATALOGUE_R2 and POSTERS_R2).

Layer 1: Zero-DB Static Assets + Bounded Per-Isolate LRU

Public catalogue traffic (/[locale], /[locale]/sources, /[locale]/sources/[slug], /[locale]/sources/[slug]/[episode], /[locale]/calendar, RSS feeds, and SVG badges) never queries our primary database.

At build time, the static baseline is compiled into Worker Static Assets (env.ASSETS):

  • /_catalogue/directory-summary.json — compact directory projection for home, browse, hub, and calendar pages
  • /_catalogue/series/<slug>.json — precomputed single-series bundles averaging ~35 KiB each
  • /_catalogue/episodes-00.json .. episodes-63.json — 64 fallback episode shards
  • /_sitemaps/*.xml.gz — pre-gzipped chunked XML sitemaps (<= 10,000 URLs / <= 15 MiB per chunk)

Inside each Worker isolate, we maintain a strictly bounded runtime cache on globalThis:

// Keep peak Worker isolate memory well below 128 MiB even under 25k-page crawls. const MAX_CACHED_SHARDS = 3; // Each per-series bundle averages ~35 KiB JSON (~1.7 MiB for 48 bundles), // eliminating warm-isolate LRU eviction thrash across stratified crawls. const MAX_CACHED_SERIES_BUNDLES = 48; 

Because untouched series read directly from env.ASSETS (which incurs 0 R2 Class B reads and 0 database queries), a warm isolate holds up to 48 parsed series bundles in roughly 1.7 MiB of RAM and serves repeat requests in sub-millisecond CPU time.

Layer 2: Atomic Cloudflare R2 Edge Deltas (Live Updates With Zero Redeploy)

Static assets handle the 374-series baseline, while a zero-egress Cloudflare R2 bucket (CATALOGUE_R2 -> diziluma-catalogue) handles everything published since the last deploy.

Three native Cloudflare Workers Cron Triggers in wrangler.jsonc run the entire update loop with zero external schedulers:

"triggers": { "crons": [ "0 */6 * * *", // 6-hour catalogue delta ingestion & atomic R2 publish "15 3 * * *", // Daily sitemap refresh "30 3 * * *" // Daily open-data, WebSub & search-engine syndication ] } 

Whenever the 6-hour cron discovers new episodes or newly added series, our atomic R2 delta publisher writes objects in strict dependency order:

  1. Poster auto-mirror (POSTERS_R2: <slug>.<ext>, magic-byte verified, <= 2 MiB, immutable cache headers)
  2. Per-series delta bundle (CATALOGUE_R2: delta/series/<slug>.json, identical shape to static WorkerSeriesBundle)
  3. Directory patch (CATALOGUE_R2: delta/directory-patch.json, slimmed metadata + updated episode counts)
  4. Pre-gzipped delta sitemaps (CATALOGUE_R2: delta/sitemaps/sitemap-pages-delta.xml.gz, sitemap-videos-delta.xml.gz, sitemap-index.xml.gz)
  5. Atomic commit manifest written LAST (CATALOGUE_R2: delta/manifest.json)

Writing delta/manifest.json last acts as a lock-free commit pointer: no Worker isolate can observe a partially written delta because every read is gated on the manifest's version, updatedSlugs, and newSlugs. Right after publishing, the scheduled() handler force-refreshes local isolate state, deletes affected entries from local caches.default, and issues batched global Cloudflare Zone Purge API requests (30 URLs per batch).

Layer 3: Split 1-RTT Parallel Cold Hydration & PoP-Warm 0-R2 Caching

An early latency trap we discovered: hydrating directory-summary.json and delta/directory-patch.json on every cold isolate penalizes single-episode detail pages that only need one series.

We split hydration by route shape:

  • Non-catalogue routes (/robots.txt, /terms, /privacy, /ads/*, redirects): 0 R2 reads, 0 JSON parses.
  • Directory, home, calendar, hub, and RSS routes: parallelize env.ASSETS (directory-summary.json) alongside delta/manifest.json and delta/directory-patch.json in 1 RTT on PoP-cold isolates.
  • Single-series & episode routes (/[locale]/sources/[slug]/...): never block TTFB on directory JSON.

Even better, we cache R2 delta JSON objects inside the local Cloudflare PoP's caches.default under a synthetic internal origin (delta/manifest.json for 60s, versioned bundles for 3600s):

// PoP-cold miss: fetch manifest + speculative R2 delta bundle + static ASSETS in 1 RTT! const [, deltaRaw, staticRaw] = await Promise.all([ ensureDeltaManifestOnlyHydrated(env, ctx, true), readR2Text(env, `delta/series/${slug}.json`), staticPromise, ]); // Strictly gate delta acceptance on the authoritative manifest just loaded if (isWorkerDeltaSlug(slug) && deltaRaw && tryCacheParsedSeriesBundle(deltaRaw, slug)) { writePopCachedR2Text(`delta/series/${slug}.json`, deltaRaw, 3600, ctx, rt.deltaVersion); bundleReady = true; } else if (staticRaw && tryCacheParsedSeriesBundle(staticRaw, slug)) { bundleReady = true; } 
  • Warm isolate: 0ms hydration if in the 48-series LRU; 0 R2 reads for untouched series.
  • PoP-warm cold isolate: reads manifest from local caches.default in parallel with env.ASSETS — 0 R2 reads (~3ms) for untouched series.
  • PoP-cold isolate: fires manifest, speculative delta bundle, and static asset in a single Promise.all — 1 RTT total.

Layer 4: True Worker-Level Stale-While-Revalidate (4200s)

Because Cloudflare's programmatic caches.default does not natively honor stale-while-revalidate, a page with s-maxage=600, stale-while-revalidate=3600 would normally go completely cold after 10 minutes.

We implemented true Worker-level SWR directly on caches.default:

  1. Extend storage TTL at write time: Store 200 OK responses with s-maxage=4200 (600 + 3600) and attach internal freshness & WORKER_BUILD_VERSION metadata headers.
  2. Instant HIT or STALE with non-blocking revalidation: Strip internal headers, restore clean client Cache-Control, check if rt.deltaVersion invalidated the slug, and if ageSeconds >= 600, return immediately with X-Edge-Cache: STALE while refreshing in ctx.waitUntil(...):
if (isStale && ctx && !inFlightEdgeRevalidations.has(cacheKey.url)) { inFlightEdgeRevalidations.add(cacheKey.url); ctx.waitUntil( revalidateEdgeCacheEntry(url, cacheKey, cfCaches, env, ctx).finally(() => { inFlightEdgeRevalidations.delete(cacheKey.url); }), ); } 
  1. Safety invariants built in: Never cache responses with Set-Cookie, private, no-store, Vary: *, auth headers, or Next.js RSC prefetch headers; never SWR-extend 404/410 responses; never overwrite a healthy cached 200 entry with a transient non-200 response.

Layer 5: Click-to-Play Poster Facade, Edge Posters & Zero-Copy Sitemaps

Three additional edge optimizations unlocked near-perfect Lighthouse scores across mobile and desktop:

  1. Click-to-Play Poster Facade: Episode and series pages render a lightweight localized poster facade instead of mounting third-party video embeds during initial SSR paint — dropping desktop Total Blocking Time (TBT) on heavy episode hubs from 2,250ms to 10ms (Perf 57 -> 98).
  2. Zero-Egress WebP Posters (/api/poster?slug=...): All 374/374 series posters are normalized to 480px-max WebP (~6.9 MiB total) in POSTERS_R2 with Cache-Control: public, max-age=31536000, s-maxage=31536000, stale-while-revalidate=86400, immutable.
  3. Zero-Copy Streaming Chunked Sitemaps: All 15 child sitemaps (6 page chunks, 5 video chunks, delta sitemaps, hubs, images — every file <= 10,000 URLs) are stored pre-gzipped and piped through Web Standards DecompressionStream("gzip"), keeping Worker RAM flat.
  4. WAF Bot Hygiene at $0 Worker Cost: Cloudflare WAF Custom Rules block abusive AI training crawlers and PHP/WordPress scanners at the edge (403, zero Worker invocations) while explicitly allowing Googlebot, Bingbot, and live citation search bots (OAI-SearchBot, PerplexityBot, Claude-SearchBot).

Verified Production Results

Every architectural claim above was validated against live production traffic on https://diziluma.com:

Metric / Verification Verified Production Result
Public Catalogue Database Egress $0 (0 DB reads on public browse, series, episode, calendar, sitemap & poster routes)
Hosting Infrastructure Cost $5/mo flat Cloudflare Workers Paid (30s CPU limit, 10M reqs/mo) + $0 R2 egress + $0 GCP
Desktop /en (Authenticated PSI) 100 Perf · 100 A11y · 100 Best Practices · 100 SEO
Desktop Series Hub /en/sources/ada-masali 98 Perf · 100 A11y · 100 Best Practices · 100 SEO (TBT 10ms)
Mobile /en/calendar (Authenticated PSI) 99 Perf · 96 A11y · 100 Best Practices · 100 SEO (CLS 0.033)
Mobile Episode Page /en/sources/uzak-sehir/75 98 Perf · 97 A11y · 100 Best Practices · 100 SEO
64-Shard Uncached Stress Test 384 / 384 HTTP 200 (0 503s)
Google Search Console Sitemaps 16 / 16 sitemaps Success (0 errors, 0 warnings)
Dynamic Freshness Live 6-hour Worker Cron -> atomic R2 delta -> global Zone purge, 0 redeploys

Open Metadata Dataset & Live Links

If you want to inspect the underlying structured metadata for all 374 Turkish series (16,585 static catalogued episodes, 1981–2026, 17 networks, 29 genres) or use it in your own benchmarks and data projects, we publish it openly under CC-BY-4.0 (strictly factual editorial metadata — titles, years, genres, networks, weekly air days, production studios, ratings, and episode counts):

If you are deploying Next.js on Cloudflare Workers and hitting database egress bills or Cache API cold-miss cliffs, moving your read-heavy catalogue baseline to env.ASSETS, layering atomic R2 deltas behind a last-write manifest.json, and adding a 90-line Worker-level SWR shim is one of the highest-leverage architecture upgrades you can make.