Skip to content

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

ClickHouse 16 min read How-to mediumAdept

ClickHouse and the MTA Data Challenge

Loading and cleaning the ~95 million-row NYC MTA subway turnstile dataset (2014–2022) in ClickHouse, using schema inference over S3, a staging table, and an optimized schema with LowCardinality strings, a combined DateTime column, UInt32 counters, sorted line-name arrays and a (station, date_time) ordering key. Because entry/exit counters are cumulative odometer-style readings that reset, count down and overflow, window functions partitioned by turnstile (ca, unit, scp) compute per-period deltas and discard negative or implausible values above a per-hour threshold. The steps are reproducible with clickhouse-local, and the cleaned data is published in the ClickHouse SQL playground.

Related posts

  • ClickPy at 2 Trillion rows: Scaling ingestion and fixing the past

    ClickHouse mediumAdept

    ClickPy, ClickHouse's free PyPI download analytics service, now holds over 2.2 trillion rows, and its cron-based ingestion script was replaced with ClickPipes without downtime. The new pipeline loaded data into a staging database with cloned schemas, a Null-engine raw table and a materialized view that holds all transformation logic. A fresh GCS bucket avoided reprocessing history, and the new pipeline ran in parallel and was validated by comparing daily row counts before cutover. That validation exposed missing historical days, which were fixed with lightweight deletes and per-day re-ingestion. Daily-aggregated materialized views could be deleted and repopulated by date, while non-daily aggregates such as monthly totals had to be dropped, rebuilt and recreated to avoid double counting.

  • How Chartmetric uses ClickHouse to turn artist data into music intelligence

    ClickHouse mediumAdept

    Chartmetric moved its heaviest time-series and relational workloads off Postgres RDS and Snowflake. It started on self-hosted ClickHouse on EC2, then switched to ClickHouse Cloud once operating the cluster past 8 TB on EBS became painful. Time-series queries that used to time out now finish in about six seconds, RDS storage dropped by 10 TB, and a two-billion-row artist-playlist table went from over five minutes to about two seconds per query. That table handles deletes through Snowflake-generated deletion markers, a row_active flag and VersionedCollapsingMergeTree instead of FINAL. Lessons learned: do joins upstream to avoid out-of-memory errors, and use multiple projections to serve different access patterns, keeping in mind that projections don't support deletes.

  • Replacing the HDB: ClickHouse for historical ticker data

    ClickHouse mediumAdept

    ClickHouse can serve as the historical tier (HDB) of a market data system, a low-risk place to adopt a new database. Its columnar storage with dictionary, delta and run-length encodings plus ZSTD/LZ4 compresses tick data well. A worked example loads one month of Binance USD-M futures data (373M trades and about 2B quotes) with clickhouse-local, reading zipped CSVs directly. Plain SQL then handles trading-desk queries: VWAP, hourly OHLC candles and minute-level drill-downs run in tens of milliseconds, and ASOF JOIN matches each trade to the prevailing quote to measure slippage during a sell-off.

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

  • How the D. E. Shaw group powers high-cardinality observability at scale with ClickHouse

    ClickHouse mediumAdept

    The D. E. Shaw group moved per-task resource metrics from its HPC grid, millions of high-cardinality time series keyed by unique task IDs, from an InfluxDB-protocol time-series platform to ClickHouse. In same-hardware benchmarks, a single ClickHouse node ingested about 3.5M samples/s against roughly 480k for a competitor, and queries that timed out elsewhere finished in seconds. Production keeps the InfluxDB line-protocol ingestion path through a custom batching service, backfills history by reading the old platform's files directly from disk, and stores 68 TB compressed on four replicated NVMe servers at about 530k inserts/s, with materialized views for capacity-planning dashboards. Tradeoffs included rewriting Prometheus-style queries in SQL and limited compression on unique-ID fields (up to 5x), while OpenTelemetry traces reach about 12.5x compression.

The quest for software engineering knowledge.

Look:
Layout: