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.

chore(cohorts): disable realtime cohort calculation for p80-p100 tiers (#74696)

Gustavo H. Strassburgerd7d06680c078
diff --git a/posthog/temporal/messaging/schedule.py b/posthog/temporal/messaging/schedule.py
index ba37919561e8..055fe9cd0261 100644
--- a/posthog/temporal/messaging/schedule.py
+++ b/posthog/temporal/messaging/schedule.py
@@ -231,7 +231,13 @@ async def create_reconcile_precalculated_data_schedule(client: Client):
async def create_all_realtime_cohort_calculation_schedules(client: Client):
- """Create or update all six percentile-based schedules for realtime cohort calculation.
+ """Create or update the active percentile-based schedules for realtime cohort calculation.
+
+ Only the p0-p80 tiers (p0-p50, p50-p80) are active. The p80-p100 tiers (p80-p90, p90-p95,
+ p95-p99, p99-p100) are intentionally disabled for now — they cover the slowest, most expensive
+ cohorts — so their schedules are deleted here if they exist. Re-enabling is a matter of
+ re-adding the create calls below and dropping the corresponding deletes; the per-tier
+ create_* helpers, settings, and schedule-ID constants are kept in place for that.
Note: This migration is non-atomic. Between creating new schedules and deleting the old one,
both schedules may fire simultaneously. The old schedule processes ALL cohorts while the new
@@ -240,13 +246,19 @@ async def create_all_realtime_cohort_calculation_schedules(client: Client):
"""
from posthog.temporal.common.schedule import a_delete_schedule, a_schedule_exists
- # First ensure all new percentile-based schedules are in place
+ # First ensure the active p0-p80 percentile-based schedules are in place
await create_realtime_cohort_calculation_p0_p50_schedule(client)
await create_realtime_cohort_calculation_p50_p80_schedule(client)
- await create_realtime_cohort_calculation_p80_p90_schedule(client)
- await create_realtime_cohort_calculation_p90_p95_schedule(client)
- await create_realtime_cohort_calculation_p95_p99_schedule(client)
- await create_realtime_cohort_calculation_p99_p100_schedule(client)
+
+ # Delete the disabled p80-p100 tiers so any previously registered schedules stop firing
+ for disabled_schedule_id in (
+ REALTIME_COHORT_CALCULATION_P80_P90_SCHEDULE_ID,
+ REALTIME_COHORT_CALCULATION_P90_P95_SCHEDULE_ID,
+ REALTIME_COHORT_CALCULATION_P95_P99_SCHEDULE_ID,
+ REALTIME_COHORT_CALCULATION_P99_P100_SCHEDULE_ID,
+ ):
+ if await a_schedule_exists(client, disabled_schedule_id):
+ await a_delete_schedule(client, disabled_schedule_id)
# Then clean up the legacy schedules if they exist to prevent duplicate runs
if await a_schedule_exists(client, REALTIME_COHORT_CALCULATION_SCHEDULE_ID):