---
title: "Reducing BigQuery Costs: How We Fixed A $1 Million Query"
description: "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."
url: "https://swe.quest/articles/reducing-bigquery-costs-how-we-fixed-a-1-million-query-623d7a6f57bc4fa3"
canonical: "https://shopify.engineering/reducing-bigquery-costs"
source: "Shopify Engineering"
published: "2022-11-03"
difficulty: "medium"
kind: "Case study"
reading_minutes: 5
tags: ["analytics","cost-optimization","cloud","stream-processing"]
---

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

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2022-11-03, 5 min read, Case study. Original: [https://shopify.engineering/reducing-bigquery-costs](https://shopify.engineering/reducing-bigquery-costs)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)
- [Stream processing](https://swe.quest/tags/stream-processing.md) (Data & databases)

## Prerequisites

- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- data warehouse concepts ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

BigQuery, Apache Flink, Google Cloud Storage, RocksDB, Apache Kafka, Parquet

## Related posts

- [Why BigQuery can’t match ClickHouse Cloud for real-time analytics](https://swe.quest/articles/why-bigquery-can-t-match-clickhouse-cloud-for-real-time-analytics-fd197ffd824251d5.md): ClickHouse · 2026-10-08 · Medium · 19 min read · Analytics & OLAP, Performance engineering, Cost optimization, Cloud platforms, Data pipelines
  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 Cloud: Gumlet’s key to processing billions of video and image requests daily](https://swe.quest/articles/clickhouse-cloud-gumlet-s-key-to-processing-billions-of-video-and-image-74adef1921adb284.md): ClickHouse · 2024-12-19 · Medium · 6 min read · Analytics & OLAP, Video & media, Cost optimization, Data pipelines
  Gumlet, which serves over 2 billion video and image requests daily, moved its video analytics (900 billion rows) from BigQuery to ClickHouse Cloud.
- [Trade secrets: How Coinhall uses ClickHouse to power its blockchain data platform](https://swe.quest/articles/trade-secrets-how-coinhall-uses-clickhouse-to-power-its-blockchain-data-platform-a19f7fb99396fe78.md): ClickHouse · 2024-08-14 · Easy · 5 min read · Analytics & OLAP, Databases, Performance engineering, Cost optimization
  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.
- [ClickHouse vs BigQuery: Using ClickHouse to Serve Real-Time Queries on Top of BigQuery Data](https://swe.quest/articles/clickhouse-vs-bigquery-using-clickhouse-to-serve-real-time-queries-on-top-of-2c9e02d14f552560.md): ClickHouse · 2023-02-27 · Medium · 25 min read · Analytics & OLAP, Data pipelines, Cloud platforms, SQL
  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.
- [HIFI’s migration from BigQuery to ClickHouse](https://swe.quest/articles/hifi-s-migration-from-bigquery-to-clickhouse-5318550bbb72f66e.md): ClickHouse · 2023-01-09 · Medium · 8 min read · Analytics & OLAP, SQL, Databases, JavaScript
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
