:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(ingestion): key the feed-order sentinel on the Kafka message key (#90316)
José Sequeira6e08c0359a1d
diff --git a/nodejs/src/ingestion/api/feed-order-sentinel.test.ts b/nodejs/src/ingestion/api/feed-order-sentinel.test.tsindex 2a87c9b196f7..e9c641a01655 100644--- a/nodejs/src/ingestion/api/feed-order-sentinel.test.ts+++ b/nodejs/src/ingestion/api/feed-order-sentinel.test.ts@@ -7,9 +7,9 @@ function msg(offset: number, overrides: Partial<SerializedKafkaMessage> = {}): Spartition: 0,offset,timestamp: 0,- key: null,+ key: 't:a',value: null,- headers: { token: 't', distinct_id: 'a' },+ headers: {},...overrides,}}@@ -42,21 +42,18 @@ describe('FeedOrderSentinel', () => {expect(sentinel.check([msg(40)], 'c2', false)).toEqual({ outOfOrder: 1, replayed: 0 })})- it('tracks keys independently across partitions and distinct_ids', () => {+ it('tracks keys independently across partitions and Kafka keys', () => {const sentinel = new FeedOrderSentinel()- sentinel.check(- [msg(10), msg(10, { partition: 1 }), msg(10, { headers: { token: 't', distinct_id: 'b' } })],- 'c1',- false- )+ sentinel.check([msg(10), msg(10, { partition: 1 }), msg(10, { key: 't:b' })], 'c1', false)// Same offsets again on other keys don't interfere; only 'a' on partition 0 regresses.expect(sentinel.check([msg(9)], 'c1', false)).toEqual({ outOfOrder: 1, replayed: 0 })expect(sentinel.check([msg(11, { partition: 1 })], 'c1', false)).toEqual({ outOfOrder: 0, replayed: 0 })})- it('skips messages without routing headers', () => {+ it.each([null, ''])('skips unkeyed messages even when routing headers are present (key: %j)', (key) => {const sentinel = new FeedOrderSentinel()- const result = sentinel.check([msg(5, { headers: {} }), msg(1, { headers: {} })], 'c1', false)+ const headers = { token: 't', distinct_id: 'a' }+ const result = sentinel.check([msg(5, { key, headers }), msg(1, { key, headers })], 'c1', false)expect(result).toEqual({ outOfOrder: 0, replayed: 0 })expect(sentinel.size).toBe(0)})@@ -64,8 +61,8 @@ describe('FeedOrderSentinel', () => {it('evicts the least-recently-seen key at capacity and rebaselines it silently', () => {const sentinel = new FeedOrderSentinel(2)sentinel.check([msg(10)], 'c1', false)- sentinel.check([msg(10, { headers: { token: 't', distinct_id: 'b' } })], 'c1', false)- sentinel.check([msg(10, { headers: { token: 't', distinct_id: 'c' } })], 'c1', false)+ sentinel.check([msg(10, { key: 't:b' })], 'c1', false)+ sentinel.check([msg(10, { key: 't:c' })], 'c1', false)expect(sentinel.size).toBe(2)// 'a' was evicted: its regression rebaselines instead of firing.expect(sentinel.check([msg(5)], 'c1', false)).toEqual({ outOfOrder: 0, replayed: 0 })diff --git a/nodejs/src/ingestion/api/feed-order-sentinel.ts b/nodejs/src/ingestion/api/feed-order-sentinel.tsindex 9a1849134454..a9a6b4c918b0 100644--- a/nodejs/src/ingestion/api/feed-order-sentinel.ts+++ b/nodejs/src/ingestion/api/feed-order-sentinel.ts@@ -62,14 +62,12 @@ export class FeedOrderSentinel {const result: FeedOrderCheckResult = { outOfOrder: 0, replayed: 0 }for (const message of messages) {- const token = message.headers['token']- const distinctId = message.headers['distinct_id']- if (!token || !distinctId) {- // No routing key: the consumer routes these individually under a+ if (!message.key) {+ // Unkeyed: the consumer routes these individually under a// synthetic unique key, so there is no per-key order to check.continue}- const key = `${message.topic}/${message.partition}/${token}:${distinctId}`+ const key = `${message.topic}/${message.partition}/${message.key}`const entry = this.entries.get(key)if (entry && entry.consumerId === consumerId) {diff --git a/rust/ingestion-consumer/README.md b/rust/ingestion-consumer/README.mdindex 22e5d2209caf..28269cf8ad01 100644--- a/rust/ingestion-consumer/README.md+++ b/rust/ingestion-consumer/README.md@@ -25,7 +25,7 @@ The rebalance metrics from the consumer context stay on regardless, and the `conThe worker-side check lives in `nodejs/src/ingestion/api/feed-order-sentinel.ts`, fed by the `consumer_id` (process incarnation) and `replay` fields the transport stamps on every `/ingest` request.It measures the invariant at its end point: the worker's grouping stage processes each key strictly in feed order, so "fed in offset order per key" is "processed in order per key".Rebalances reset all baselines (`ingestion_consumer_rebalances_total{event}` counts them), so partition handoffs don't fire false positives.-Null-key messages (e.g. overflow rerouting) are excluded from the consumer-side key checks: the producer deliberately spreads such a routing key across partitions, forfeiting per-key order, so offsets from different partitions are not comparable and there is no invariant to check. The worker-side check is unaffected — it scopes keys per partition, an invariant that holds for all traffic.+Null-key messages (e.g. overflow rerouting) are excluded from both checks: the producer deliberately forfeits per-key order for them, and the consumer routes each one individually rather than pinning it, so there is no invariant to check on either side.## Debug API