Lago - Using ClickHouse to Scale an Events Engine
Lago, an open-source usage-based billing platform ingesting millions of events per minute, moved its streamed billable events from Postgres to ClickHouse Cloud and kept Postgres for all other transactional data. The ClickHouse side is small: a Kafka-engine queue table, a materialized view that maps event metadata from JSON into a string array, and a MergeTree raw_events table keyed on organization, subscription, code and timestamp. Aggregation queries got 18x to 137x faster; for example, a weighted sum dropped from 6.6s to 48ms. The post also covers OLTP vs OLAP tradeoffs, columnar storage, insert-time materialized views and vectorized execution.
Related posts
- Data Hive: The story of beehiiv’s journey from Postgres to ClickHouse
ClickHouse easyNovice
beehiiv replaced its Postgres-and-Ruby-queue analytics system, which struggled with billions of email events and had multi-hour reporting delays, with a Kafka-fed ClickHouse Cloud pipeline. The design leans on ReplacingMergeTree for idempotent ingestion and event replay, dictionaries to enrich inserts without joins, ephemeral columns for intermediate calculations, materialized views as pre-aggregated shadow tables with alternate sort keys, and window functions for analytics. After six months the system held over 33 billion raw events in 1.5 TiB compressed (13 TiB uncompressed), with 22 ms median and 85 ms average query times. Creators now see send performance within seconds instead of hours.
- 98% faster queries, 50% lower cloud costs: Verihubs’ journey from Postgres to ClickHouse
ClickHouse mediumAdept
Verihubs replaced a Postgres warehouse fed by daily Airflow batch pulls with a ClickHouse-based real-time OLAP stack. Kafka Connect and Debezium CDC stream data into MergeTree tables for append-only logs and ReplacingMergeTree tables for updatable rows. Materialized views and projections build daily and monthly rollups for reconciliation and invoicing, and Dagster handles complex detection jobs. Queries dropped from 20-30 minutes to 2-3 seconds, and cloud costs fell up to 50%. Lessons include designing ordering keys up front, choosing MergeTree engines carefully, expecting asynchronous mutations, and planning backfills because materialized views don't backfill automatically.
- How GitLab serves sub-second analytics to 50 million users
ClickHouse easyNovice
GitLab moved its user-facing product analytics from Postgres to ClickHouse after dashboards repeatedly hit its 15-second performance ceiling. Hierarchical multi-join queries over 100M+ rows dropped from 30–40 seconds to 0.24 seconds, and ClickHouse is now the default OLAP engine across GitLab.com, Dedicated and self-managed deployments. A hybrid data access layer routes queries between Postgres and ClickHouse, ingestion runs as TSV over HTTP plus an in-house CDC framework (Siphon), and materialized views are the main optimization tool. The team built and ran its own ClickHouse operator on object storage before moving SaaS to ClickHouse Cloud, and warns against self-managing unless required. It also flags poor visibility into background mutations as an ongoing operational pain.
- Front-end observability at scale: How OpenReplay captures billions of daily events in real time with ClickHouse
ClickHouse easyNovice
OpenReplay, a self-hosted session replay and product analytics platform, moved behavioral event storage from Postgres to ClickHouse. Session search dropped from roughly 3–10 seconds to about one second, and ~1 TB event tables compressed to 1–2 GB. ClickHouse's TTL replaced weekend-long delete-and-vacuum retention jobs. A chain of materialized views off a single flat events table cut pipeline changes from two days to half a day, and native JSON makes custom event properties queryable as columns. Each customer deployment runs on a single vertically scaled ClickHouse instance, ingesting up to billions of events and ~6 TB per day, because avoiding sharding keeps self-hosted operations lean.
- How Kami scaled from 80M to nearly 2B events per week with ClickHouse
ClickHouse mediumAdept
Kami's Postgres event tracking (Rails writing JSONB rows, queried via Redash) collapsed when COVID pushed weekly events from about 80M to nearly 2B. Read replicas, a message queue and NVMe storage only delayed the problem, and Citus and CDC tools like Debezium could not keep up. The team moved to ClickHouse using a custom Java Kafka consumer that turned JSON into structured columns, plus a manual backfill of historical events. They later added MaterializedPostgreSQL and Kafka syncs for production and CockroachDB CRM data, and built dbt daily per-user rollups that cut DAU queries from 3-4 minutes over 140B rows to about 1 second over 1.3B rows.