Skip to content

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

Shopify Engineering 5 min read Case study mediumAdept

Reducing BigQuery Costs: How We Fixed A $1 Million Query

Clustering a BigQuery table on two columns used in a query's WHERE clause cut the data scanned per query from about 75 GB to roughly 100–500 MB, turning a projected ~$949K/month bill into about $1,370/month. The query came from a Flink pipeline for a Shopify marketing tool. To avoid ingesting an ever-growing billion-row dataset into RocksDB state, the pipeline was being redesigned to offload queries to BigQuery at an estimated 60 requests per minute. Other cost tips: avoid SELECT *, partition tables, and use free table previews instead of exploratory queries.

Related posts

  • Why BigQuery can’t match ClickHouse Cloud for real-time analytics

    ClickHouse mediumAdept

    In the CostBench benchmark, ClickHouse Cloud and BigQuery ingest 113.2 billion stock quotes at a target of 1M rows/s while aggregate and drill-down queries run continuously, and ClickHouse Cloud scores 438× better end-to-end performance per dollar under BigQuery Capacity pricing and 512× under On-demand. ClickHouse wins all three components: preparation cost ($28.69 vs $243–265), normalized query cost (~$0.05 vs $4.75–24.80) and accumulated query runtime (58 seconds vs 49 minutes). The gap is traced to the fresh-data path. ClickHouse ingest nodes sort raw data and compute incremental materialized-view aggregates from the same async-insert flush. BigQuery's Storage Write API, automatic reclustering and MV refresh (minimum one-minute interval) each advance separately, which leaves more work for queries.

  • ClickHouse Cloud: Gumlet’s key to processing billions of video and image requests daily

    ClickHouse mediumAdept

    Gumlet, which serves over 2 billion video and image requests daily, moved its video analytics (900 billion rows) from BigQuery to ClickHouse Cloud. The drivers were BigQuery's per-query and ingestion pricing, its 100-concurrent-query limit, and billing on logical storage size. The new pipeline uses a Go service that batches inserts at 20,000 rows, direct S3 log ingestion, and materialized views that pre-aggregate playback and rebuffer metrics. Lessons include choosing primary keys carefully up front (changing one means recreating the table), using LowCardinality and Delta compression, preferring DateTime over DateTime64, and swapping in compatible tools such as Metabase.

  • Trade secrets: How Coinhall uses ClickHouse to power its blockchain data platform

    ClickHouse easyNovice

    Coinhall, an omnichain trading terminal aggregating swap data from 23 blockchains, moved from BigQuery (about 2-second queries, thousands of dollars per month) to QuestDB and then to self-hosted ClickHouse. In Coinhall's comparison against Rockset, SingleStore and Snowflake, ClickHouse ran candlestick queries in 20 ms, latest-price queries in 8 ms and ASOF JOINs in 50 ms, on a 4 vCPU / 16 GB server costing about $50 a month. After migrating, the team tuned queries around sparse primary indexes and replaced full-table LIMIT BY scans with aggregating tables fed by materialized views. They also avoided or simplified sort-merge joins.

  • ClickHouse vs BigQuery: Using ClickHouse to Serve Real-Time Queries on Top of BigQuery Data

    ClickHouse mediumAdept

    ClickHouse can sit alongside BigQuery to serve sub-second, high-concurrency analytical queries for real-time applications, while BigQuery remains the warehouse for ad-hoc deep analysis. The guide maps BigQuery types to narrower ClickHouse types and codecs, and avoids Nullable columns to save storage. It bulk-exports the public Ethereum dataset to GCS as sharded gzip CSV, then loads it in parallel with s3Cluster and parallel_distributed_insert_select; the 16.5M-row blocks table imports in about 23 seconds. It also covers continuously appending new rows using BigQuery scheduled queries and Google Dataflow/Apache Beam, keyed on a time dimension.

  • HIFI’s migration from BigQuery to ClickHouse

    ClickHouse mediumAdept

    HIFI moved music royalty analytics from BigQuery to ClickHouse because BigQuery's per-query pricing discouraged exploratory use and slot reservations didn't fit a startup's shifting workloads. Dashboard loads for accounts with 25M+ rows dropped from up to 30 seconds (with timeouts) to a few seconds. The migration surfaced ClickHouse-specific join behaviour: bulk updates work better via a Join engine table and joinGet, and LEFT joins from PostgreSQL to large ClickHouse tables can exhaust memory because the hash join loads the right side into memory, which pre-aggregating the right side with GROUP BY fixes (under 1 second). A community Node.js client also silently converted NULLs to empty strings on insert, which they patched.

The quest for software engineering knowledge.

Look:
Layout: