<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ran Yu</title>
    <description>The latest articles on DEV Community by Ran Yu (@ran_yu_2c285ce35253397bc4).</description>
    <link>https://dev.to/ran_yu_2c285ce35253397bc4</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4270271%2Fc561e6ef-55d4-4b22-a7c2-8d72c71e5bbd.png</url>
      <title>DEV Community: Ran Yu</title>
      <link>https://dev.to/ran_yu_2c285ce35253397bc4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ran_yu_2c285ce35253397bc4"/>
    <language>en</language>
    <item>
      <title>How I Built a 70,000-Title Media Aggregator with Go, PostgreSQL pg_trgm Deduplication, and Next.js 16</title>
      <dc:creator>Ran Yu</dc:creator>
      <pubDate>Sat, 28 Nov 2026 07:26:27 +0000</pubDate>
      <link>https://dev.to/ran_yu_2c285ce35253397bc4/how-i-built-a-70000-title-media-aggregator-with-go-postgresql-pgtrgm-deduplication-and-nextjs-4igf</link>
      <guid>https://dev.to/ran_yu_2c285ce35253397bc4/how-i-built-a-70000-title-media-aggregator-with-go-postgresql-pgtrgm-deduplication-and-nextjs-4igf</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: 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.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can see the live system running at &lt;strong&gt;&lt;a href="https://wanyingku.com/" rel="noopener noreferrer"&gt;WanYingKu (wanyingku.com)&lt;/a&gt;&lt;/strong&gt; — along with its companion &lt;strong&gt;&lt;a href="https://github.com/ranyu696/wanyingku-releases" rel="noopener noreferrer"&gt;Android &amp;amp; Android TV client releases on GitHub&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://ranyu696.github.io/wanyingku-releases/" rel="noopener noreferrer"&gt;static release portal&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The Core Data Problem: Noisy Multi-Source Feeds
&lt;/h2&gt;

&lt;p&gt;When you aggregate media catalogs from multiple upstream providers, the same movie or TV series shows up under wildly inconsistent names:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Dune: Part Two (2024) HD Mandarin&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Dune 2 4K Uncut&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;沙丘2 (国语中字)&lt;/code&gt; vs &lt;code&gt;沙丘：第二部&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;
  
  
  The 4-Stage Entity Resolution Funnel in Go + PostgreSQL
&lt;/h3&gt;

&lt;p&gt;Instead of running an expensive LLM call on every incoming item, the ingestion worker runs a cheap-to-expensive funnel:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic Title Normalization (&lt;code&gt;pkg/textutil&lt;/code&gt;)&lt;/strong&gt;
Strip resolution tags (&lt;code&gt;4K&lt;/code&gt;, &lt;code&gt;1080P&lt;/code&gt;, &lt;code&gt;HD&lt;/code&gt;), language/edition noise (&lt;code&gt;Mandarin&lt;/code&gt;, &lt;code&gt;Cantonese&lt;/code&gt;, &lt;code&gt;Uncut&lt;/code&gt;, &lt;code&gt;Director's Cut&lt;/code&gt;), punctuation, and trailing year tokens. Crucially, we also run a &lt;strong&gt;different-installment guard&lt;/strong&gt; so &lt;em&gt;Season 1&lt;/em&gt; and &lt;em&gt;Season 2&lt;/em&gt;—or &lt;em&gt;Part 1&lt;/em&gt; and &lt;em&gt;Part 2&lt;/em&gt;—never collapse into one record.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authoritative External IDs (TMDB / Douban)&lt;/strong&gt;
When metadata enrichment resolves a canonical &lt;code&gt;tmdb_id&lt;/code&gt; + &lt;code&gt;kind&lt;/code&gt; pair, a PostgreSQL partial unique index (&lt;code&gt;UNIQUE (tmdb_id, kind) WHERE tmdb_id IS NOT NULL&lt;/code&gt;) guarantees cross-language aliases automatically converge on one canonical title.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Indexed Fuzzy Recall (&lt;code&gt;pg_trgm&lt;/code&gt; + Anchor Pre-Filtering)&lt;/strong&gt;
Early on, our fuzzy candidate query scanned &lt;code&gt;LIMIT 2000&lt;/code&gt; rows per title—which started missing duplicates once the catalog passed 50,000 rows. Pre-filtering candidates by a 2-character normalized prefix anchor with GIN &lt;code&gt;gin_trgm_ops&lt;/code&gt; indexes made fuzzy recall both faster and far more accurate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stream URL Overlap Guard&lt;/strong&gt;
Two catalog entries sharing multiple identical HLS stream URLs are usually duplicates—&lt;em&gt;except&lt;/em&gt; when a broken upstream feed accidentally attaches the same stream to completely unrelated short dramas. Adding a &lt;code&gt;name_similarity &amp;gt;= 0.35&lt;/code&gt; and &lt;code&gt;same (kind, season, adult)&lt;/code&gt; guard prevented false merges during historical cleanup (safely merging 48 verified duplicate pairs while skipping 21 upstream-corrupted pairs).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. Cutting List Query Latency from 720ms to ~15ms
&lt;/h2&gt;

&lt;p&gt;At ~73,000 rows, our default catalog listing query (&lt;code&gt;DISTINCT ON&lt;/code&gt; + &lt;code&gt;SELECT COUNT(*)&lt;/code&gt;) showed up in production logs taking &lt;strong&gt;~720ms&lt;/strong&gt; on a small Postgres instance—enough to cause sporadic 5xx timeouts during crawler bursts.&lt;/p&gt;

&lt;p&gt;Three simple changes fixed it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Added a &lt;strong&gt;partial composite index&lt;/strong&gt; matching the active storefront filter (&lt;code&gt;WHERE status = 1 AND adult = false&lt;/code&gt;), ordered by &lt;code&gt;(indexable DESC, popularity DESC, id DESC)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Cached &lt;code&gt;COUNT(*)&lt;/code&gt; totals for short windows instead of recounting 73k rows on every paginated request.&lt;/li&gt;
&lt;li&gt;Switched episode updates during sync from delete-and-reinsert to &lt;strong&gt;incremental diffing&lt;/strong&gt;, dramatically lowering WAL churn and table bloat.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Migrating from MUI + Emotion to Tailwind CSS v4 on Next.js 16
&lt;/h2&gt;

&lt;p&gt;The original user-facing storefront used Material UI + Emotion runtime CSS-in-JS. Moving to &lt;strong&gt;Next.js 16 (App Router + Cache Components)&lt;/strong&gt; with &lt;strong&gt;Tailwind CSS v4&lt;/strong&gt; paid off immediately:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Zero runtime style injection overhead on SSR/streaming pages.&lt;/li&gt;
&lt;li&gt;Smaller client JavaScript bundles and cleaner dark-cinema visual polish (&lt;code&gt;1px&lt;/code&gt; subtle inner border rings on posters, tabular numerals for ratings/episode counts, BlurHash placeholders).&lt;/li&gt;
&lt;li&gt;Build times dropped to under 1 second with Turbopack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Real-World SEO &amp;amp; Core Web Vitals Bugs I Caught in Production
&lt;/h2&gt;

&lt;p&gt;Reading &lt;a href="https://developers.google.com/search/docs" rel="noopener noreferrer"&gt;Google Search Central's documentation&lt;/a&gt; side-by-side with our live HTML and Search Console reports surfaced several bugs that are easy to miss in local dev:&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug 1: &lt;code&gt;opacity-0&lt;/code&gt; on Priority Hero Images Hurts LCP
&lt;/h3&gt;

&lt;p&gt;Our &lt;code&gt;&amp;lt;PosterImage&amp;gt;&lt;/code&gt; component initialized &lt;code&gt;const [loaded, setLoaded] = useState(false)&lt;/code&gt; and rendered &lt;code&gt;opacity-0&lt;/code&gt; until &lt;code&gt;onLoad&lt;/code&gt; fired on the client. Even with &lt;code&gt;priority&lt;/code&gt; and &lt;code&gt;fetchPriority="high"&lt;/code&gt;, SSR HTML shipped an invisible hero image—delaying &lt;strong&gt;Largest Contentful Paint (LCP)&lt;/strong&gt; until React hydration finished. Initializing &lt;code&gt;useState(priority)&lt;/code&gt; immediately painted the above-the-fold poster on first byte.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug 2: Client-Fetched Sections Hide Internal Links from Crawlers
&lt;/h3&gt;

&lt;p&gt;Our homepage curated collections bar (&lt;code&gt;Collections.tsx&lt;/code&gt;) originally fetched &lt;code&gt;/collections&lt;/code&gt; inside a client hook. Inspecting the raw SSR HTML revealed &lt;code&gt;collection_links = 0&lt;/code&gt;—search crawlers saw 70 individual title links, but zero links to our 18 highest-value thematic landing pages (&lt;code&gt;/collection/2026-movie&lt;/code&gt;, &lt;code&gt;/collection/scifi-movie&lt;/code&gt;, etc.). Moving that fetch into a cached server call (&lt;code&gt;"use cache"&lt;/code&gt; + &lt;code&gt;cacheLife("minutes")&lt;/code&gt;) made the entire homepage compile as a &lt;strong&gt;1-minute ISR static route&lt;/strong&gt; with all 18 collection links present in raw HTML.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug 3: Thin Pages &amp;amp; Crawl Budget Bloat
&lt;/h3&gt;

&lt;p&gt;Exposing all 73,000 raw scraped records in sitemaps—including entries with no synopsis, plus tens of thousands of &lt;code&gt;/person/*&lt;/code&gt; actor pages—starved crawl budget. Adding a PostgreSQL generated column &lt;code&gt;indexable&lt;/code&gt; (requiring active status, non-adult, and a real synopsis) narrowed our sitemap to &lt;strong&gt;~17,000 high-signal pages&lt;/strong&gt; served via a standard &lt;code&gt;/sitemap.xml&lt;/code&gt; Sitemap Index, while &lt;code&gt;robots.txt&lt;/code&gt; blocks &lt;code&gt;/person/&lt;/code&gt;, &lt;code&gt;/watch/&lt;/code&gt;, and &lt;code&gt;/search?&lt;/code&gt; parameter traps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug 4: Structured Data Alignment
&lt;/h3&gt;

&lt;p&gt;Upgrading listing pages to Google's &lt;strong&gt;Movie Carousel&lt;/strong&gt; spec (&lt;code&gt;ItemList&lt;/code&gt; with nested &lt;code&gt;Movie&lt;/code&gt; objects containing &lt;code&gt;image&lt;/code&gt;, &lt;code&gt;dateCreated&lt;/code&gt;, &lt;code&gt;director&lt;/code&gt;, and &lt;code&gt;aggregateRating&lt;/code&gt;), adding &lt;code&gt;BreadcrumbList&lt;/code&gt; to curated collection pages, and updating homepage &lt;code&gt;WebSite&lt;/code&gt; JSON-LD with &lt;code&gt;alternateName&lt;/code&gt; made the rich-result markup clean and standards-compliant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Building a large catalog site today isn't just about scraping and rendering cards—it's about &lt;strong&gt;entity cleanliness, predictable database latency, zero-hydration-delay SSR, and strict crawl-budget hygiene&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you'd like to explore the live site or test the Android / Android TV clients:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Web App&lt;/strong&gt;: &lt;a href="https://wanyingku.com/" rel="noopener noreferrer"&gt;https://wanyingku.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Android &amp;amp; Android TV Releases&lt;/strong&gt;: &lt;a href="https://github.com/ranyu696/wanyingku-releases" rel="noopener noreferrer"&gt;github.com/ranyu696/wanyingku-releases&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Permanent Release Portal&lt;/strong&gt;: &lt;a href="https://ranyu696.github.io/wanyingku-releases/" rel="noopener noreferrer"&gt;ranyu696.github.io/wanyingku-releases&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Telegram Updates&lt;/strong&gt;: &lt;a href="https://t.me/wanyingku" rel="noopener noreferrer"&gt;@wanyingku&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy to answer questions in the comments about the &lt;code&gt;pg_trgm&lt;/code&gt; deduplication heuristics or Next.js 16 Cache Components!&lt;/p&gt;

</description>
      <category>backend</category>
      <category>database</category>
      <category>go</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
