Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 24 min read Case study mediumAdept

Building a product analytics solution with ClickHouse

ClickHouse's in-house product analytics platform, Galaxy, stores over 20 billion events (14 TB, roughly 14x compression) in a single denormalized MergeTree table keyed on created_at. A single sparse table avoids join overhead, since ClickHouse's sparse serialization makes empty columns cheap. Columns used for cohorts and filters should be top-level rather than buried in a JSON payload. Incremental materialized views speed up the few dozen recurring queries, and a custom SDK handles event capture.

Related posts

  • What Replo learned optimizing 100+ billion events in ClickHouse

    ClickHouse mediumAdept

    Replo's in-product analytics for Shopify merchants ingests 3,000-5,000 events per second into ClickHouse and analyzes 100+ billion events, but reaching that point took several data-model resets. A precomputation pipeline that marked sessions with SummingMergeTree and recomputed them via a refreshable materialized view worked until fractional attribution exposed that MergeTree deduplication is only eventual. Adding FINAL/DISTINCT fixed correctness but made recomputation slower than the one-minute refresh window, causing a runaway backlog. The fix was to recompute only from a small table holding the last 40 minutes of purchase-related events, using joins in a single materialized view, and to handle historical backfills with offline scripts. Follow-up tuning included LowCardinality columns, materialized JSON fields and dropping Nullable types.

  • Accelerating ClickHouse queries on JSON data for faster Bluesky insights

    ClickHouse mediumAdept

    Incremental materialized views feeding AggregatingMergeTree tables cut ClickHouse dashboard queries over 4+ billion Bluesky JSON documents (1.6 TiB) from 44–56 seconds to 3–7 ms. Partial aggregation states are computed only for newly inserted rows and merged in the background, so the pre-aggregated tables stay tiny (e.g. 892 rows, 11 KiB) and constant-size regardless of source growth. Query latency therefore stays flat as the source table grows, and memory drops from ~776 MiB to ~186 KiB per query. Three dashboard scenarios cover count, uniq-based unique-user counts and top-reposted posts, with DDL, materialized view definitions and execution statistics; the reposts dashboard runs with a 5-second delay.

  • Using Materialized Views in ClickHouse

    ClickHouse mediumAdept

    ClickHouse materialized views act as insert-time triggers that write the result of a SELECT into a target table, letting expensive aggregations be precomputed. On a 1B-row Wikistat dataset, a SummingMergeTree-backed view cuts a top-projects query from 15 seconds to 3 ms, and AggregatingMergeTree with *State()/*Merge() combinators handles min/max/avg the same way. The same mechanism supports compacting history (with source-table TTL), validating and filtering rows via a Null-engine source table, routing invalid data to separate tables, and transforming columns. Practical guidance: keep views per table to around ten or fewer, still GROUP BY at query time since merges are asynchronous, avoid FINAL on large tables, and only aggregate for storage when it reduces rows by roughly 10x.

  • 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.

  • Harnessing the Power of Materialized Views and ClickHouse for High-Performance Analytics at Inigo

    ClickHouse mediumAdept

    Inigo stores analytics on billions of GraphQL API requests in ClickHouse after rejecting Snowflake as too slow and costly for customer-facing data and lacking a local emulator, and PostgreSQL because its indexes and costs blew up past roughly 100K–1M rows. Raw tables keyed on observed_at feed AggregatingMergeTree materialized views bucketed at 1-minute, 6-minute, 40-minute and 3-hour intervals, so most queries scan thousands of aggregated rows instead of millions of raw ones. Counts are stored as a calls column and read back with sum(calls), percentiles use quantilesState in the view and quantileMerge at query time, and high-cardinality fields like trace_id stay in raw tables only. The result is month-long retention in views versus a week of raw data, lower database load, and fast local integration tests, at the cost of setup complexity and no transactions.

The quest for software engineering knowledge.

Look:
Layout: