An event-driven Go consumer that retired slow Postgres views and materialized views in favor of a Kafka-driven pipeline, keeping Elasticsearch in sync with Postgres for a legal-document platform — no HTTP API, just three topics in and a search index kept honest on the way out.
Search indexing used to run off a set of Postgres views and materialized views — some of them large, CTE-based queries that had accumulated years of special cases nobody fully trusted touching. Assembling a single document type could mean dozens of separate database round trips per record: fast individually, expensive multiplied across tens of thousands of them. And a multi-hour bulk reindex against a search index serving live traffic meant choosing between degraded search for hours or an outage — there wasn't a third option.
The rewrite moved one document type at a time, behind its own feature flag defaulting to off. A small diffing tool ran the same record through both the legacy view and the new Go processor and reported every field-level difference; legacy logic stayed the source of truth until that tool reported zero discrepancies against real data, not a handful of hand-picked examples. The clean-architecture layering shown above kept the migration's complexity contained — swapping the read path for one document type never touched the other ten.