How I Built a 70,000-Title Media Aggregator with Go, PostgreSQL pg_trgm Deduplication, and Next.js 16
TL;DR: Aggregating 70,000+ film and TV records from multiple inconsistent feeds breaks fast if you...
TL;DR: Aggregating 70,000+ film and TV records from multiple inconsistent feeds breaks fast if you treat it like a simple CRUD app. Here is how I solved cross-source entity deduplication in Go + PostgreSQL, migrated the frontend from MUI to Tailwind CSS v4 on Next.js 16, and fixed the subtle SEO/LCP traps that kept crawlers from indexing the right pages.
You can see the live system running at WanYingKu (wanyingku.com) — along with its companion Android & Android TV client releases on GitHub and static release portal.
1. The Core Data Problem: Noisy Multi-Source Feeds
When you aggregate media catalogs from multiple upstream providers, the same movie or TV series shows up under wildly inconsistent names:
Dune: Part Two (2024) HD MandarinDune 2 4K Uncut沙丘2 (国è¯ä¸å—)vs沙丘:第二部
If you key records by raw title string, your database quickly fills with duplicate pages competing for the same search queries—and users have to click through five identical cards just to find a working playback stream.
The 4-Stage Entity Resolution Funnel in Go + PostgreSQL
Instead of running an expensive LLM call on every incoming item, the ingestion worker runs a cheap-to-expensive funnel:
- Deterministic Title Normalization (
pkg/textutil) Strip resolution tags (4K,1080P,HD), language/edition noise (Mandarin,Cantonese,Uncut,Director's Cut), punctuation, and trailing year tokens. Crucially, we also run a different-installment guard so Season 1 and Season 2—or Part 1 and Part 2—never collapse into one record. - Authoritative External IDs (TMDB / Douban)
When metadata enrichment resolves a canonical
tmdb_id+kindpair, a PostgreSQL partial unique index (UNIQUE (tmdb_id, kind) WHERE tmdb_id IS NOT NULL) guarantees cross-language aliases automatically converge on one canonical title. - Indexed Fuzzy Recall (
pg_trgm+ Anchor Pre-Filtering) Early on, our fuzzy candidate query scannedLIMIT 2000rows per title—which started missing duplicates once the catalog passed 50,000 rows. Pre-filtering candidates by a 2-character normalized prefix anchor with GINgin_trgm_opsindexes made fuzzy recall both faster and far more accurate. - Stream URL Overlap Guard
Two catalog entries sharing multiple identical HLS stream URLs are usually duplicates—except when a broken upstream feed accidentally attaches the same stream to completely unrelated short dramas. Adding a
name_similarity >= 0.35andsame (kind, season, adult)guard prevented false merges during historical cleanup (safely merging 48 verified duplicate pairs while skipping 21 upstream-corrupted pairs).
2. Cutting List Query Latency from 720ms to ~15ms
At ~73,000 rows, our default catalog listing query (DISTINCT ON + SELECT COUNT(*)) showed up in production logs taking ~720ms on a small Postgres instance—enough to cause sporadic 5xx timeouts during crawler bursts.
Three simple changes fixed it:
- Added a partial composite index matching the active storefront filter (
WHERE status = 1 AND adult = false), ordered by(indexable DESC, popularity DESC, id DESC). - Cached
COUNT(*)totals for short windows instead of recounting 73k rows on every paginated request. - Switched episode updates during sync from delete-and-reinsert to incremental diffing, dramatically lowering WAL churn and table bloat.
3. Migrating from MUI + Emotion to Tailwind CSS v4 on Next.js 16
The original user-facing storefront used Material UI + Emotion runtime CSS-in-JS. Moving to Next.js 16 (App Router + Cache Components) with Tailwind CSS v4 paid off immediately:
- Zero runtime style injection overhead on SSR/streaming pages.
- Smaller client JavaScript bundles and cleaner dark-cinema visual polish (
1pxsubtle inner border rings on posters, tabular numerals for ratings/episode counts, BlurHash placeholders). - Build times dropped to under 1 second with Turbopack.
4. Real-World SEO & Core Web Vitals Bugs I Caught in Production
Reading Google Search Central's documentation side-by-side with our live HTML and Search Console reports surfaced several bugs that are easy to miss in local dev:
Bug 1: opacity-0 on Priority Hero Images Hurts LCP
Our <PosterImage> component initialized const [loaded, setLoaded] = useState(false) and rendered opacity-0 until onLoad fired on the client. Even with priority and fetchPriority="high", SSR HTML shipped an invisible hero image—delaying Largest Contentful Paint (LCP) until React hydration finished. Initializing useState(priority) immediately painted the above-the-fold poster on first byte.
Bug 2: Client-Fetched Sections Hide Internal Links from Crawlers
Our homepage curated collections bar (Collections.tsx) originally fetched /collections inside a client hook. Inspecting the raw SSR HTML revealed collection_links = 0—search crawlers saw 70 individual title links, but zero links to our 18 highest-value thematic landing pages (/collection/2026-movie, /collection/scifi-movie, etc.). Moving that fetch into a cached server call ("use cache" + cacheLife("minutes")) made the entire homepage compile as a 1-minute ISR static route with all 18 collection links present in raw HTML.
Bug 3: Thin Pages & Crawl Budget Bloat
Exposing all 73,000 raw scraped records in sitemaps—including entries with no synopsis, plus tens of thousands of /person/* actor pages—starved crawl budget. Adding a PostgreSQL generated column indexable (requiring active status, non-adult, and a real synopsis) narrowed our sitemap to ~17,000 high-signal pages served via a standard /sitemap.xml Sitemap Index, while robots.txt blocks /person/, /watch/, and /search? parameter traps.
Bug 4: Structured Data Alignment
Upgrading listing pages to Google's Movie Carousel spec (ItemList with nested Movie objects containing image, dateCreated, director, and aggregateRating), adding BreadcrumbList to curated collection pages, and updating homepage WebSite JSON-LD with alternateName made the rich-result markup clean and standards-compliant.
Wrapping Up
Building a large catalog site today isn't just about scraping and rendering cards—it's about entity cleanliness, predictable database latency, zero-hydration-delay SSR, and strict crawl-budget hygiene.
If you'd like to explore the live site or test the Android / Android TV clients:
- Web App: https://wanyingku.com/
- Android & Android TV Releases: github.com/ranyu696/wanyingku-releases
- Permanent Release Portal: ranyu696.github.io/wanyingku-releases
- Telegram Updates: @wanyingku
Happy to answer questions in the comments about the pg_trgm deduplication heuristics or Next.js 16 Cache Components!
Sumber artikel open-source oleh Ran Yu di DEV Community — Baca artikel asli. Topik:
#backend#database#go#nextjs

Komentar