DEV Community

Cover image for 178 songs were 404s: keeping a chart archive after songs leave the board
Xingyuan Charts
Xingyuan Charts

Posted on

178 songs were 404s: keeping a chart archive after songs leave the board

A chart page is a window. A song page is supposed to be an archive. Mix the two and you get a nasty failure mode: the song is real, people find it in search, and the page answers 404 — not because the data is wrong, but because the track dropped out of the window the site keeps.

This is the story of 178 of those pages, and the flat index that fixed them. The result is live here: https://xingyuan.beer/en?src=devto (English) and https://xingyuan.beer/?src=devto (Chinese).

What the pipeline actually keeps

Twice a day I take a read-only snapshot of 19 public Chinese music charts — NetEase Cloud Music, QQ Music, Kugou, Kuwo, Qishui, Douyin, Weibo, Bilibili, Apple Music. Each board is stored at its published depth (100 rows for most of them), so a full snapshot is about 1,700 rows.

Everything on the site is derived from that snapshot: rank deltas, "new this period", weekly movers, and one page per song. The song page is the part people link to and search for. For example, an archived one: https://xingyuan.beer/en/song/prettygirl%7Crescene?src=devto.

For a long time the song page was derived from the same snapshot too. That works until the song leaves the chart.

Why a window is not an archive

The board history keeps the last 14 periods — two snapshots a day, so one week. Across the boards that window holds 22,772 filled rank cells (4,277 distinct song keys, board by board); coverage grew from 2 to 19 boards during these periods, so the early ones are thinner. That is enough for "what moved this week", and it is not remotely enough for "every song we ever saw" in the 51 snapshots collected so far.

The gap showed up in two places:

  1. The board history pages (/board/<platform>/<board>/history) draw a row per song per period and link each row to /song/<key>. When I first built them, 1,653 linked rows produced 979 404s — songs that charted earlier in the week and were not in the latest snapshot.
  2. Sitemaps and old search results kept pointing at song keys that had no current row at all.

None of those keys were fake. They were songs that had been in the top 100, dropped out, and left nothing behind.

Three attempts, each with a smaller hole

Attempt 1 — per-period summaries. The trends archive stores four lists per snapshot: biggest risers, sustained climbers, new entries, cross-platform resonance. Those rows can be replayed as a minimal song page, so a song that left the chart but hit "biggest riser" once still gets a page.

It fixed the head of the distribution and nothing else. A song that entered at #95 and left two periods later never made any of the four lists.

Attempt 2 — the full board window. Store the whole top 100 per board per period instead of summaries. That is 249 board-periods and 22,772 filled rank cells from the same window. It covers everything that was on a board during the retained week, and it still misses songs that fell out earlier or only ever appeared briefly below the stored depth.

Attempt 3 — a flat index. One row per song key, forever:

"prettygirl|rescene": {
  "name": "Pretty Girl",
  "artists": ["RESCENE (리센느)"],
  "platform": "qq",
  "board": "62",
  "board_name": "飙升榜",
  "last_seen": "2026-11-06T09:40:02+08:00",
  "last_rank": 30,
  "best_rank": 30,
  "appearances": 2,
  "platforms": 1
}
Enter fullscreen mode Exit fullscreen mode

That is the whole row. No per-period ranks, no per-platform entries, no trajectory — those live in the board history. The index answers one question: did we ever see this song, and when was the last time?

At this snapshot it holds 4,628 song keys. 4,194 of them were seen in more than one snapshot; the busiest has 309 board-rows across all 51 snapshots, on 6 platforms. The file is a single static JSON asset, loaded once and cached by mtime, so a lookup is a dict access:

def find_evergreen_song(index, key):
    songs = index.get("songs") or {}
    row = songs.get(key) or next(
        (v for k, v in songs.items() if k.casefold() == key.casefold()), None)
    if not row:
        return None
    return {
        "name": row.get("name"),
        "entries": [{"platform": row["platform"], "rank": row["last_rank"],
                     "captured_at": row["last_seen"]}],
        "best_rank": row.get("best_rank"),
        "archived_at": row["last_seen"],
        "archived_section": "full index · %d appearances" % row.get("appearances", 0),
    }
Enter fullscreen mode Exit fullscreen mode

The rule that matters more than the index

The fallback chain is ordered: current snapshot → per-period summaries → board window → full index. The last three all replay exactly one appearance — the most recent one — and every one of them labels itself as an archive.

This is deliberate. It is tempting to build a richer page by combining the last rank from period A with the best rank from period B. Don't. Those ranks were observed at different times; putting them in one table invents a track record that never existed at any single moment. The archived page says, in both languages, "this track is not on any chart in the latest snapshot; the table below replays the last snapshot where it charted", shows the timestamp, and links to the current movers.

The same rule applies to the data file: the page exposes archived_at, so anything downstream can tell an archived rank from a live one instead of guessing from the number.

After shipping it on 2026-11-11, I re-tested 192 known-dead keys. 178 of them were real songs and now return 200 with the archive label. The other 14 stay 404 on purpose: 9 were delisted before collection started, so there is no snapshot to replay, and 5 were probe keys that never existed. A fake archive is worse than an honest 404.

The identity trap underneath

All of this assumes "the same song" is a stable identity. It is not.

Rows are matched across platforms by a normalized key: title plus sorted artists, with brackets and feat. tails stripped. That is what makes "one song on 6 of 9 platforms" computable at all, since the platforms share no IDs. It also merges 晴天, 晴天 (Live) and 晴天(剪辑版) into one key — on purpose, because a reader searching the song wants one page.

Then a platform does something the key cannot express: it charts a duet version and an original as two different tracks with two different platform IDs, under the same title and artist. The key says they are one song, and a naive rank delta says the song jumped 71 places overnight. It did not. That was one recording leaving the chart and another entering it.

The fix is to version the identity used for trajectories and deltas:

identity = row["track_id"] if row.get("track_id") else row["dedupe_key"]
Enter fullscreen mode Exit fullscreen mode

Use the platform's track_id when it exists; fall back to the text key only when it is missing. The dedupe key still decides which page a row belongs to. It just no longer decides what "previous rank" means.

What I would do differently

  • Treat the chart window as a cache, not a database. Decide up front what "we have seen this before" means, and store that separately from "what is on the chart now".
  • Make the fallback chain explicit and ordered, and make every level label itself. Readers forgive an archived page; they do not forgive an archived rank presented as current.
  • Never splice observations from different snapshots to make a nicer page.
  • Version your identity before you compute deltas. A normalized key is good for grouping pages and terrible for "up 71 this week".

The index is not clever and that is the point: one row per song, one fallback at the end of the chain, a file small enough to ship as a static asset. It turned 178 dead pages into honest archives without inventing a single number.

If you want to see the shape of the data — current charts, weekly movers, and the archived pages at the edges — it is all read-only here: https://xingyuan.beer/en/trends?src=devto. The methodology page is at https://xingyuan.beer/en/data?src=devto.

Top comments (6)

Collapse
 
userxnom profile image
Abdullah Naseer •

The framing is exactly right — a chart page is a window, a song page is an archive — and the numbers make it concrete. 1,653 linked rows producing 979 404s is a brutal failure mode for pages that were real songs people were searching for. I liked that the flat index deliberately stores no per-period ranks, just did we ever see this song, and when. When a song re-enters the chart after months away, does the archived page show the gap, or just the most recent appearance?

Collapse
 
gezhongjian profile image
Xingyuan Charts •

Good question. Right now the archived page replays exactly one capture — the most recent one — not a stitched timeline. Two reasons: ranks observed in different periods can't share one table without inventing a track record that never existed at any single moment, and the flat index keeps only last_seen / best_rank / appearances per key, not per-period ranks. The archived page labels the capture time, and index-backed pages also say how many times the song charted. The only time series we render is the per-board trajectory over the last 14 captures (~7 days); absences inside that window show as em dashes, but a months-long gap falls outside it. A proper "runs" view (each stint, gap lengths) would need the board history to carry explicit absent markers per period — worth doing, not built yet. Thanks for reading closely.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Versioning the identity before computing deltas is the part that stays with me. The dedupe key can group the page, but it should not decide what a previous rank means.

Collapse
 
gezhongjian profile image
Xingyuan Charts •

Exactly. The key groups the page; it shouldn't define what a previous rank meant. When the keyer changes we recompute history under the new version instead of subtracting across the boundary, and every aggregate carries the keyer version it was computed with.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

every aggregate carrying its keyer version is what keeps the history readable after a change. that is the detail most leaderboard code skips.

Thread Thread
 
gezhongjian profile image
Xingyuan Charts •

Thanks — that version stamp is the unglamorous part, but it is what keeps an old leaderboard readable after a migration. Appreciate the close read.