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
- Define the event contract and backward compatibility with the source and search teams.
- Backfill a snapshot to an isolated index, then switch on the change stream and compare counts and diffs.
- Implement the partitioned consumer, version-aware upsert, retry and dead-letter handling.
- Instrument consumer lag, event age, index write errors and source-to-index parity.
- 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%
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.
