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.

refactor(bigquery): Set chunk size separately for multiple consumers (#96070)

Tomás Farías Santana536b00364b54
diff --git a/posthog/settings/batch_exports.py b/posthog/settings/batch_exports.py
index 0beeeff02b93..3c7225057410 100644
--- a/posthog/settings/batch_exports.py
+++ b/posthog/settings/batch_exports.py
@@ -21,6 +21,7 @@ BATCH_EXPORT_POSTGRES_RECORD_BATCH_QUEUE_MAX_SIZE_BYTES: int = get_from_env(
)
BATCH_EXPORT_BIGQUERY_UPLOAD_CHUNK_SIZE_BYTES: int = 1024 * 1024 * 150 # 150MB
+BATCH_EXPORT_BIGQUERY_MULTIPLE_CONSUMERS_UPLOAD_CHUNK_SIZE_BYTES: int = 1024 * 1024 * 150 # 150MB
BATCH_EXPORT_BIGQUERY_RECORD_BATCH_QUEUE_MAX_SIZE_BYTES: int = get_from_env(
"BATCH_EXPORT_BIGQUERY_RECORD_BATCH_QUEUE_MAX_SIZE_BYTES", 1024 * 1024 * 100, type_cast=int
)
diff --git a/products/batch_exports/backend/temporal/destinations/bigquery_batch_export.py b/products/batch_exports/backend/temporal/destinations/bigquery_batch_export.py
index 9aaad1fd713c..4b8e54f66b31 100644
--- a/products/batch_exports/backend/temporal/destinations/bigquery_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/bigquery_batch_export.py
@@ -1552,8 +1552,10 @@ async def insert_into_bigquery_activity_from_stage(inputs: BigQueryInsertInputs)
)
max_consumers = 1
+ max_file_size_bytes_per_consumer = settings.BATCH_EXPORT_BIGQUERY_UPLOAD_CHUNK_SIZE_BYTES
if str(inputs.team_id) in settings.BATCH_EXPORT_BIGQUERY_USE_MULTIPLE_CONSUMERS_TEAM_IDS:
max_consumers = settings.BATCH_EXPORT_BIGQUERY_MAX_CONSUMERS
+ max_file_size_bytes_per_consumer = settings.BATCH_EXPORT_BIGQUERY_MULTIPLE_CONSUMERS_UPLOAD_CHUNK_SIZE_BYTES
async with bq_client:
bigquery_target_table = await bq_client.get_or_create_table(target_table)
@@ -1601,7 +1603,6 @@ async def insert_into_bigquery_activity_from_stage(inputs: BigQueryInsertInputs)
file_format: typing.Literal["Parquet", "JSONLines"] = "Parquet" if can_perform_merge else "JSONLines"
- max_file_size_bytes_per_consumer = settings.BATCH_EXPORT_BIGQUERY_UPLOAD_CHUNK_SIZE_BYTES // max_consumers
barrier_size = max_consumers + 1 if can_perform_merge else max_consumers
all_consumers_done = asyncio.Barrier(barrier_size)
merge_done = asyncio.Event()