Skip to content

: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.

fix(clickhouse): pin kafka_flag_evaluations consumer settings (#102549)

Tommy Gilmore201b40179b9e
diff --git a/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl b/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl
index ffcbdab1910b..55e6452f4e6e 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl
@@ -150,7 +150,12 @@ database "posthog" {
topic_list = "clickhouse_flag_evaluations"
group_name = "clickhouse_flag_evaluations"
format = "JSONEachRow"
+ num_consumers = 1
+ max_block_size = 10000
skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ poll_max_batch_size = 10000
+ flush_interval_ms = 7500
}
}
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 36e8fe3e2b19..e6fca9d6b893 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -3183,7 +3183,12 @@ database "posthog" {
topic_list = "clickhouse_flag_evaluations"
group_name = "clickhouse_flag_evaluations"
format = "JSONEachRow"
+ num_consumers = 1
+ max_block_size = 10000
skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ poll_max_batch_size = 10000
+ flush_interval_ms = 7500
}
}
diff --git a/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl b/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl
index dad2028c9d2c..08ae49370994 100644
--- a/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl
@@ -150,7 +150,12 @@ database "posthog" {
topic_list = "clickhouse_flag_evaluations"
group_name = "clickhouse_flag_evaluations"
format = "JSONEachRow"
+ num_consumers = 1
+ max_block_size = 10000
skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ poll_max_batch_size = 10000
+ flush_interval_ms = 7500
}
}
diff --git a/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql b/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql
index f44ecd66a69d..3c00b6ef1fe5 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql
@@ -43,7 +43,7 @@ CREATE TABLE posthog.kafka_flag_evaluations (
created_at DateTime64(6, 'UTC'),
person_id UUID,
inserted_at DateTime64(6, 'UTC')
-) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_flag_evaluations', kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_flag_evaluations';
+) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_flush_interval_ms = 7500, kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_flag_evaluations', kafka_max_block_size = 10000, kafka_num_consumers = 1, kafka_poll_max_batch_size = 10000, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_flag_evaluations';
CREATE TABLE posthog.kafka_heatmaps (
session_id String,
team_id Int64,
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index c4a38acadc2f..0d3d9781c034 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -475,7 +475,7 @@ CREATE TABLE posthog.kafka_flag_evaluations (
created_at DateTime64(6, 'UTC'),
person_id UUID,
inserted_at DateTime64(6, 'UTC')
-) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_flag_evaluations', kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_flag_evaluations';
+) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_flush_interval_ms = 7500, kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_flag_evaluations', kafka_max_block_size = 10000, kafka_num_consumers = 1, kafka_poll_max_batch_size = 10000, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_flag_evaluations';
CREATE TABLE posthog.kafka_groups (
group_type_index UInt8,
group_key String,
diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
index 23af3a111092..c5d071beba12 100644
--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr
+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
@@ -327,7 +327,18 @@
inserted_at DateTime64(6, 'UTC')
)
ENGINE = Kafka(warpstream_ingestion, kafka_topic_list = 'clickhouse_flag_evaluations_test', kafka_group_name = 'clickhouse_flag_evaluations', kafka_format = 'JSONEachRow')
- SETTINGS kafka_skip_broken_messages = 100
+ -- The block and batch sizes are an order of magnitude below the precalculated
+ -- Kafka tables on this role: each row carries the full event-properties JSON, so
+ -- large blocks cost far more memory. The 10s poll timeout is deliberate: it is
+ -- in the range the other WarpStream consumers use, not the 1s the precalculated
+ -- tables set.
+ SETTINGS
+ kafka_max_block_size = 10000,
+ kafka_poll_max_batch_size = 10000,
+ kafka_poll_timeout_ms = 10000,
+ kafka_flush_interval_ms = 7500,
+ kafka_num_consumers = 1,
+ kafka_skip_broken_messages = 100
'''
# ---
@@ -2628,7 +2639,18 @@
inserted_at DateTime64(6, 'UTC')
)
ENGINE = Kafka(warpstream_ingestion, kafka_topic_list = 'clickhouse_flag_evaluations_test', kafka_group_name = 'clickhouse_flag_evaluations', kafka_format = 'JSONEachRow')
- SETTINGS kafka_skip_broken_messages = 100
+ -- The block and batch sizes are an order of magnitude below the precalculated
+ -- Kafka tables on this role: each row carries the full event-properties JSON, so
+ -- large blocks cost far more memory. The 10s poll timeout is deliberate: it is
+ -- in the range the other WarpStream consumers use, not the 1s the precalculated
+ -- tables set.
+ SETTINGS
+ kafka_max_block_size = 10000,
+ kafka_poll_max_batch_size = 10000,
+ kafka_poll_timeout_ms = 10000,
+ kafka_flush_interval_ms = 7500,
+ kafka_num_consumers = 1,
+ kafka_skip_broken_messages = 100
'''
# ---
diff --git a/posthog/models/flag_evaluations/sql.py b/posthog/models/flag_evaluations/sql.py
index 367d593c6673..ad8dfce832c0 100644
--- a/posthog/models/flag_evaluations/sql.py
+++ b/posthog/models/flag_evaluations/sql.py
@@ -255,7 +255,18 @@ ENGINE = {
named_collection=settings.CLICKHOUSE_KAFKA_WARPSTREAM_INGESTION_NAMED_COLLECTION,
)
}
-SETTINGS kafka_skip_broken_messages = 100
+-- The block and batch sizes are an order of magnitude below the precalculated
+-- Kafka tables on this role: each row carries the full event-properties JSON, so
+-- large blocks cost far more memory. The 10s poll timeout is deliberate: it is
+-- in the range the other WarpStream consumers use, not the 1s the precalculated
+-- tables set.
+SETTINGS
+ kafka_max_block_size = 10000,
+ kafka_poll_max_batch_size = 10000,
+ kafka_poll_timeout_ms = 10000,
+ kafka_flush_interval_ms = 7500,
+ kafka_num_consumers = 1,
+ kafka_skip_broken_messages = 100
"""
)