Home / Companies / PostHog / Blog / Post Details
Content Deep Dive

We made experiment queries 4x faster using precomputation

Blog post from PostHog

Post Details
Company
Date Published
Author
Juraj Majerik
Word Count
2,627
Company Posts That Month
3
Language
English
Hacker News Points
-
Post removed?
No
Summary

PostHog substantially improved Experiments query performance as customer data volumes and product complexity grew, reducing p95 latency from 18.9 seconds to 4.3 seconds, p99 latency from 91 seconds to 13.5 seconds, and query failures by 14 times while monthly query volume more than tripled. The main change was a precomputation system that stores reusable time-bucketed query results, allowing subsequent requests to scan only recent data; this reduced average data scanned per metric from 207 GB to 7.6 GB. Because cached and direct calculations needed to remain consistent despite late-arriving events and distributed ClickHouse behavior, the team added synchronous cache writes, corrected edge cases, and built production canary tests that compare both calculation paths nightly. Additional gains came from SQL changes that reduced duplicate event-table scans, disk-based joins that avoid memory failures, deferred reads for optional session-recording data, and a dedicated experiment-exposure event that is far smaller than the previously reused feature-flag event. PostHog also moved metric recalculation from browsers to Temporal workflows, preventing duplicate requests, enabling reliable retries, and improving user visibility into queued and running work. AI agents connected to monitoring and query logs shortened investigations of regressions and anomalies, while the team concluded that production validation and operational complexity became necessary once incremental SQL optimization could no longer meet customer demand.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
AI Agents 1 2,121 373 132 -70%
Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.