Matthew Kong

Case studies/Yelp, 2017 to 2018

Search and analytics change feed reliability

A version-aware Kafka consumer with checkpoints, replay and a dead-letter queue, so search never regresses to stale state.

Close-up of code declaring a color palette
  1. Source API and MySQL
  2. Change producer
  3. Kafka topic
  4. Index consumer
  5. Elasticsearch
  6. Replay operations

Why this work, at that time

Yelp's real-time data pipeline on Kafka was public by 2017, feeding more than a hundred data-owning services. Reliable event propagation into search was a real, bounded problem.

The problem

Business and review updates propagated asynchronously. Consumers restart, lag, and see duplicate or out-of-order events, which can leave stale results in search.

The team and my part

Five engineers: two platform and event, one search, one data pipeline, one lead. I owned event versioning and the consumer for the assigned entity topic.

Data and index design

entity_change(entity_id, entity_type, version, event_time, payload); index_state(entity_id, last_version); checkpoint(topic, partition, offset); dlq(event_id, failure_reason). Partitioned by entity_id.

API and event contract

Event business.changed v1 {entity_id, version, changed_fields, event_id}. Index upserts carry the version; the replay command consumes an offset range and keeps the version check.

Core logic

An at-least-once consumer validates the schema, compares the source version with index_state, performs an idempotent upsert and commits the checkpoint only after success. Poison records go to the dead-letter queue with replay metadata.

Implementation sequence

  1. Define the event contract and backward compatibility with the source and search teams.
  2. Backfill a snapshot to an isolated index, then switch on the change stream and compare counts and diffs.
  3. Implement the partitioned consumer, version-aware upsert, retry and dead-letter handling.
  4. Instrument consumer lag, event age, index write errors and source-to-index parity.
  5. Shadow-read search results, cut over selected entity cohorts and retain the old feed until parity holds.

Environments and release

Dockerized Python workers with a Kafka test topic and local Elasticsearch; staging replay of anonymized traffic; rolling production deploy with consumer-group monitoring.

Failure drill

business.updated version 103 arrives after 104. The version check rejects the stale update. For a multi-hour Kafka lag, backfill from snapshot and recheck parity.

Scale and targets

Modeled scale

  • 500K entity updates per day on assigned topics, 5.8 events per second average
  • Roughly 120 events per second peak with seven-day replay retention
  • About 5M indexed documents in the downstream slice

Acceptance targets

  • End-to-end freshness p95 under five minutes
  • Sampled source-to-index parity at or above 99.99%

Scale figures are the sizing model behind the design. Targets are acceptance criteria, not measured results.

The trade-off I would defend

Do not demand global ordering. Partition by entity, compare monotonic versions, and document the eventual-consistency window instead of pretending it away.