MostViewed Today

Since September 2025 · mostviewed.today ↗

MostViewed Today is a leaderboard of what YouTube is watching right now. It captures YouTube’s trending chart every hour and keeps the history, so you can see how a video climbed, how long it stayed and when it fell off. YouTube only shows you the chart as it is this minute. The history is the product.

I started it in September 2025. Most of what I learned from it is about data that grows every hour, on a budget that doesn’t: a surprise database bill, a free plan with hard daily limits, and a move to Postgres that made the whole thing simpler.

The home page: today’s #1, the day in numbers and what changed since yesterday.
The home page: today’s #1, the day in numbers and what changed since yesterday.

Re-ranked every hour

Rankings cover videos, Shorts and creators, by category and country. The order changes all day, so rows move to their new place rather than redraw, and a small arrow says how far they went.

Top 5 · global · 09:00views / hr
  1. 3Night market food tour in TaipeiWanderplate52.0K
  2. 1I built a cabin in 30 daysNorthwood Builds55.6K
  3. 4Lowtide, official trailerArcfilm Studios43.3K
  4. 5Derby day: a 3–2 thrillerMatchday Central43.1K
  5. 2Speedrun world record attemptPixelwarp53.4K
Rows trading places as the hourly numbers come in. A faux demo, with made-up videos.

Tap a row and it opens to show its peak, days on the chart, views per hour and its rank through the day. Creators can paste a link and check whether their video is on any chart, in any country tracked.

A row opened up, with its rank through the day.
A row opened up, with its rank through the day.

Collecting the chart

A small Node collector calls the YouTube Data API on a schedule and writes one “tick” per chart: every video’s rank and view count at that moment. Each chart is fetched once and split into videos and Shorts; the first version fetched it twice.

collector/collect.mjs
async function videos(sql, yt, at) {  const chart = await yt.chart({ positions: 200 });  const kept = await yt.hydrate(chart.filter((i) => !isShort(i)));  const n = await writeTick(sql, "global:videos", at, kept);  log({ msg: "tick", chart: "global:videos", videos: n, of: chart.length });  // every 6 hours, also the 12 category charts  if (at.getUTCHours() % 6 === 0) await categories(sql, yt, at);}
JobWhen (UTC)What it writes
videosevery hour at :00The global chart, plus 12 category charts every 6 hours
shortsevery hour at :30The global Shorts chart
countriesdaily, 04:05Videos and Shorts for 7 countries
creators00:10 and 12:10Channel profiles for creators on the charts
daily00:12Rebuilds the day-level views
watchdogevery 15 minutesChecks freshness, disk, memory and failed jobs

All of it costs about 630 YouTube API requests a day. The watchdog messages me on Telegram, but only when the set of problems changes, so one stuck job is one message, not one every 15 minutes.

The D1 bill

The first version ran entirely on Cloudflare: a Worker for the site and the collectors, D1 for the data. In October 2026 the D1 bill started climbing fast. In one day the database recorded 5.66 million billed row writes, while the app had only added about 105,000 rows of real data.

D1 bills every index and trigger that a write touches, not just the row. I rebuilt the collector’s exact statements against a local copy with the same tables, indexes and triggers to count what one video really cost:

One collected videoBilled rows
Video already on the chart, hourly tick18
Brand-new video29
Same tick delivered twice, after the fix0
Planned schema, redundant indexes dropped8

The other half was repetition. A category job ran 191 times in a day instead of 48, because scheduled runs can be delivered more than once and nothing stopped a repeat. Writes used INSERT OR REPLACE, so a repeat rewrote every rank and refreshed every summary again.

The fixes were dull, and they worked: claim each scheduled run once before doing any work, use ON CONFLICT DO NOTHING so a repeat writes nothing, keep recent history in D1 and archive the rest to R2, and put the automation endpoints behind auth, since some of them had been publicly callable.

Moving to Postgres

The account then moved to the Workers Free plan, which allows 100,000 written rows a day for every database combined. The hourly global chart alone used about 76,000. On November 6 the database also passed the free plan’s 500 MB cap, and collection stopped.

Four days later the collectors were running again, this time as systemd timers on a small VPS in Singapore, writing to Postgres on the same machine. The site still runs on Cloudflare Workers and reaches the database through a Cloudflare tunnel and Hyperdrive.

data path
  1. YouTube API~630 calls / day
  2. Collectorssystemd timers
  3. Postgresviews refresh per tick
  4. Hyperdrivevia tunnel
  5. Workeredge cache first
Writes stay on the server. Pages read through Hyperdrive, and most reads never reach it.

The schema has one rule: never aggregate history on a request. The collector writes raw ranks, then calls one procedure per tick that updates each video’s running totals in place, peak rank and days on chart included. Calling it twice for the same tick does nothing.

db/postgres/schema.sql
CREATE OR REPLACE PROCEDURE apply_capture(p_chart text, p_at timestamptz)LANGUAGE plpgsql AS $$BEGIN  IF EXISTS (SELECT 1 FROM captures             WHERE chart = p_chart AND captured_at = p_at) THEN    RETURN; -- this tick is already counted  END IF;   INSERT INTO video_summary AS s (video_id, peak_rank, days_on_chart, ...)  SELECT ... FROM rank_history r  WHERE r.chart = p_chart AND r.captured_at = p_at  ON CONFLICT (video_id) DO UPDATE SET    -- the best (lowest) rank so far    peak_rank = LEAST(s.peak_rank, excluded.peak_rank),    ...END $$;

Chart-wide numbers, like today’s top 100 or a creator’s month, come from materialized views that refresh after each tick or once a day. Every view has a unique index, so it refreshes without locking out readers. The tests run the real schema and procedures on PGlite, an in-process Postgres.

Reading on a budget

Every page read goes through three layers: the Worker’s own memory, then Cloudflare’s edge cache, then the database once per data window. The windows follow the collectors, so a page asks for the global chart once after :05 and then serves it from cache until the next tick.

The read path was built for D1’s daily limits and kept: if a limit hits, the site stops calling the database until midnight UTC and serves the last good copy from the edge cache, up to 48 hours old. “Overloaded” errors retry three times with jittered backoff, then back off for 30 seconds. A page render is capped at 45 queries, retries included.

Rebuilt for search

The first version rendered its charts in the browser, so a search engine saw an empty table. v2 rebuilds the site page by page as React Server Components, so every chart row is in the HTML. Each page is ported with a short checklist: same query, same title, description and canonical as the live page, every difference listed in the pull request.

PageWhat it ranks
/globalYouTube's own global chart, every hour
/category/[slug]YouTube's category charts, same 13 slugs and titles as before
/trending/[country]The chart for each of 7 countries
/breaking-videosViews per hour since publishing
/weekly-chartsViews gained in the window, not lifetime views
/video/[id]One page per video; old title-and-id URLs 308 to it

Two bugs only showed up when I fetched pages the way a crawler does:

  • Pages whose metadata reads data were streaming their title and canonical into the body instead of the head. Next.js has a setting that sends metadata up front to every visitor; turning it on fixed it, and curl -A Googlebot now checks for exactly one title and one canonical.
  • A loading screen wraps its route in Suspense, so the response starts streaming with a 200 before the page decides it’s a 404 or a redirect. Routes that can 404 or redirect don’t get a loading screen.

Chart pages emit ItemList JSON-LD. The llms.txt and the plain-text page summaries for AI tools are generated from the same page list, and a test fails if someone adds a page without regenerating them.

Decisions and trade-offs

ChoiceTrade-off
Self-hosted Postgres, not a bigger D1No daily caps and room to grow, but I run the server, the backups and the watchdog
Rollups updated per tickMore logic in the write path, but no page ever scans history
Hyperdrive into the serverPages stay on Workers at the edge; every read crosses a tunnel, so the cache does the heavy lifting
v2 read-only against the old databaseTwo codebases for a while, but the rebuild could never damage live data
Every page ships every stateReady, empty, loading and error for each route, forced in dev with ?state=empty|error|slow

The free plan shaped a lot of small rules too. It allows five scheduled triggers for the whole account, so one dispatcher per cadence routes the work. It allows 1,000 KV writes a day, so nothing hot uses KV. And cache writes are never allowed to fail the request that triggered them.

How it's built

  • Pages: React Server Components on Cloudflare Workers, so the chart rows are in the HTML search engines read.
  • Data: Postgres on the VPS, materialized views per tick and per day, read-only role for the site.
  • Collection: Node and systemd timers on the same server, with a watchdog.
  • Design: one design system with tokens in code, shared by every page.
See what YouTube is watching on mostviewed.today

Built with React Server Components, Cloudflare Workers, Postgres, Hyperdrive.