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.

feat(data-stack): add shared duckling backfill concurrency tag (#61027)

James Greenhilld5be1620c543
diff --git a/posthog/dags/events_backfill_to_duckling.py b/posthog/dags/events_backfill_to_duckling.py
index e2b087713f5d..5b5c6b26bd11 100644
--- a/posthog/dags/events_backfill_to_duckling.py
+++ b/posthog/dags/events_backfill_to_duckling.py
@@ -188,12 +188,24 @@ EVENTS_COLUMNS = """
BACKFILL_EVENTS_S3_PREFIX = "backfill/events"
BACKFILL_PERSONS_S3_PREFIX = "backfill/persons"
+# Shared concurrency key across events + persons backfills. Each duckling
+# connection spins up a duckgres worker, and the per-org worker pool is capped
+# (maxWorkers in the duckgres chart) and shared with product queries — so the
+# two backfills must draw from ONE combined limit, not two independent ones.
+# The limit itself is a Dagster Cloud deployment setting (charts repo); this tag
+# is just the key it targets. Per-product keys are kept for optional finer limits.
+DUCKLING_BACKFILL_CONCURRENCY_TAG = {
+ "duckling_backfill_concurrency": "duckling_v1",
+}
+
EVENTS_CONCURRENCY_TAG = {
"duckling_events_backfill_concurrency": "duckling_events_v1",
+ **DUCKLING_BACKFILL_CONCURRENCY_TAG,
}
PERSONS_CONCURRENCY_TAG = {
"duckling_persons_backfill_concurrency": "duckling_persons_v1",
+ **DUCKLING_BACKFILL_CONCURRENCY_TAG,
}
# Persons columns for export - joined with person_distinct_id2 to include distinct_ids
diff --git a/posthog/dags/test_events_backfill_to_duckling.py b/posthog/dags/test_events_backfill_to_duckling.py
index 2c571a167722..7aa4dd2a7141 100644
--- a/posthog/dags/test_events_backfill_to_duckling.py
+++ b/posthog/dags/test_events_backfill_to_duckling.py
@@ -9,8 +9,10 @@ import psycopg
from parameterized import parameterized
from posthog.dags.events_backfill_to_duckling import (
+ DUCKLING_BACKFILL_CONCURRENCY_TAG,
EARLIEST_BACKFILL_DATE,
EVENTS_COLUMNS,
+ EVENTS_CONCURRENCY_TAG,
EVENTS_TABLE_DDL,
EXPECTED_DUCKLAKE_COLUMNS,
EXPECTED_DUCKLAKE_PERSONS_COLUMNS,
@@ -19,6 +21,7 @@ from posthog.dags.events_backfill_to_duckling import (
ICEBERG_PERSONS_PARTITION_EXPR,
ICEBERG_PERSONS_TABLE_DDL,
PERSONS_COLUMNS,
+ PERSONS_CONCURRENCY_TAG,
PERSONS_TABLE_DDL,
_get_cluster,
_set_iceberg_table_partitioning,
@@ -905,3 +908,18 @@ class TestIcebergInsertByNameHivePartitioning:
insert_sql = next(s for s in executed if "read_parquet" in s)
assert "BY NAME" in insert_sql
assert "hive_partitioning=false" in insert_sql
+
+
+class TestDucklingConcurrencyTags:
+ # The combined events+persons cap is enforced on the shared key in the charts
+ # Dagster deployment settings. If either backfill drops the shared tag, the
+ # cap silently stops applying to it — guard against that here.
+ @parameterized.expand(
+ [
+ ("events", EVENTS_CONCURRENCY_TAG),
+ ("persons", PERSONS_CONCURRENCY_TAG),
+ ]
+ )
+ def test_backfill_carries_shared_concurrency_key(self, _name, tag_dict):
+ ((shared_key, shared_value),) = DUCKLING_BACKFILL_CONCURRENCY_TAG.items()
+ assert tag_dict[shared_key] == shared_value