ShareChat
Moj
QuickTv

BigQuery let us move fast. Here's how we kept it affordable.

Placeholder

Brijesh Savaliya, Rushabh Shroff25 Nov, 2026

Follow us on FacebookFollow us on TwitterFollow us on InstagramFollow us on Linkedin
BigQuery let us move fast. Here's how we kept it affordable.

How a small platform team ran an 11 PB warehouse for dozens of teams without running clusters, and what we built when the bill grew.

BigQuery has been ShareChat's data warehouse from the start. It let a small data platform team serve dozens of teams running analytics, dashboards, ML pipelines and product features on a warehouse that grew to about 11 PB, without sizing, patching or upgrading a single cluster. Analysts, data scientists and engineers all wrote the same SQL, and when demand grew, we bought more slots and BigQuery absorbed it.

That ease had a cost we couldn't see. Most teams shared a few large pools of slots, capacity kept growing, and no one could say which workload it was for. In March 2023 a single ad hoc query used thousands of slots at once and slowed every team sharing them.

We didn't leave BigQuery. Between 2022 and 2024 we changed how we ran it: we put a cost on every query, bought capacity in one place, and built automation that cancelled runaway queries and moved slots to whichever team needed them that hour. By July 2023 our baseline was about 60% below late 2022, before any workload had moved off BigQuery. Some heavy batch work still cost too much on shared slots, and that's when we added Spark.

BigQuery is still our warehouse. This post covers why it worked so well for a fast-moving team, what made it expensive at our scale, and the strategies that brought the cost back down.

2022 to 2024 at a glance: the controls we built on BigQuery, and when Spark came in.

What BigQuery gave us

Four things made BigQuery the right warehouse for us.

No clusters to run. When we needed more capacity, we bought slots. A slot is BigQuery's unit of compute, roughly a virtual CPU, and one query can use thousands of them at once. We still owned workload priorities, capacity budgets, data retention and accountability for cost. The rest of this post covers that work.

SQL first. Analysts, data scientists and backend engineers write the same SQL, and the same query works in an ad hoc session, a dashboard and a scheduled job. Temporary tables and scripting let teams build multi-step analysis on their own, and new teams could go from an idea to a production dashboard or pipeline without waiting on new infrastructure.

Connected to the rest of GCP. The range of connectors was one of its strongest points for us. We used almost all of them. Load jobs bring in files from Cloud Storage, Pub/Sub subscriptions write streams straight into tables, and the Data Transfer Service pulls from other clouds, databases and Google's ad products on a schedule. EXPORT DATA writes query results back to Cloud Storage as Parquet, Avro, CSV or JSON.

An API for everything. Job history, table metadata and storage sizes are all queryable through INFORMATION_SCHEMA, a set of system views you query like tables, and BigQuery's APIs can cancel a running query, resize a reservation or move a project to another reservation. A daily metadata job of ours, for example, reads those views to record when each table was last read and last written, and the weekly storage clean-up later in this post runs on it. Every guardrail in this post is a scheduled query or a small Airflow DAG built on those pieces.

Those strengths still hold for teams whose work is mostly SQL analytics and dashboards, and for small platform teams that don't want to run compute clusters. Our analysts and most of our dashboards still run on BigQuery today.


Where the cost came from

The things that made BigQuery easy also made its cost easy to ignore. Buying slots was simple, so capacity bought for a short-term need was rarely released. Anyone could run a query, so an ad hoc analysis could take the same slots as a production pipeline. Creating a table cost nothing up front, so by early 2023 we had about 800,000 tables, and roughly 80% of them hadn't been read in 90 days. And because pipelines ran under shared service accounts, the bill told us which project spent the money but not which team or feature.

Making cost visible and buying capacity

How BigQuery capacity works

  • Reservations. Named pools of slots. Each project is assigned to one, and its queries run on that pool's slots.
  • On-demand and capacity pricing. On-demand pricing bills each query by the bytes it scans. Capacity pricing buys slots for reservations instead of billing on bytes.
  • Baseline and autoscaling. Under BigQuery Editions, a reservation has baseline slots, billed whether or not they're used, and it can also autoscale up to a set maximum. Autoscaled slots are billed only while they're allocated.
  • Commitments. One- or three-year purchases of slots at a lower price.
  • Admin project. The project that owns the reservations and pays for them.

Audit before anything else

In early 2022, five large BigQuery projects shared the warehouse: analytics, ML, dashboards, ad hoc analysis and product features. Four projects bought reserved slots, tens of thousands between them. Each team knew its own queries, but no one could see which workloads were growing, or which reservations had been bought for a short-term need and never released.

We audited reservations across every project. Temporary capacity that had become permanent went back to the shared pool, bursty workloads moved back to on-demand pricing, and we released reservations bought ahead of a migration that was then deferred. The audit fixed the reservations we could see. It couldn't tell us what each workload cost.

Strategy 1: Put a cost on every query

At the start of 2023 the warehouse held about 10.9 PB, and reserved capacity was still growing.

Most of our BigQuery compute came from Airflow DAGs, our scheduled workflows, plus scheduled queries and dashboards. Teams ran their own Cloud Composer environments, so scheduling was fully decentralised and no one was accountable for the slots a pipeline used. Pipelines ran under shared service accounts, and BigQuery's job history named that account for each query but not the DAG, team or feature behind it. The hardest part of attributing cost turned out to be finding every Composer environment.

In Q1 2023 we built a cost-attribution pipeline:

  1. Collect run metadata. A generic DAG in every Composer environment copies that environment's run history into a BigQuery table.
  2. Join it to BigQuery jobs. Each Airflow task records the IDs of the BigQuery jobs it starts in XCom. The DAG joins those IDs with the job history in INFORMATION_SCHEMA, which ties each job to a DAG, a task and a team.
  3. Price and roll up. Under capacity pricing a query has no price of its own, so we split each day's bill across jobs by their share of slot-time, which is slots multiplied by how long they're held. The costs add up to what we paid, idle capacity included, and Superset dashboards show every team its daily cost.
How the attribution pipeline ties every BigQuery job to a DAG, a team and a cost.

By the end of the quarter every query had a cost against it. The first thing we did with it was send each business unit head a list of their most expensive DAGs, and let them decide which features justified the compute. Teams cut costs fastest when they can see what they pay for.

Strategy 2: Buy capacity in one place

In 2023 Google replaced flat-rate pricing with BigQuery Editions, and we used the switch to change how we bought capacity:

  • One admin project buys every slot, mostly as commitments, and pays for all reserved compute.
  • Each team runs its queries from its own project, and service accounts are mapped to teams, so the attribution pipeline can split that central bill by team.
  • We turned BigQuery off in projects that no longer needed it.

With attribution in place, we ran an optimisation war room with the heaviest teams, and together they cut enough demand to release about a third of our reserved slots. By the end of July 2023 our baseline was about 60% below late 2022, and about 40% lower even at full autoscaling, before any workload had moved off BigQuery.

Reserved BigQuery slots as a share of late 2022, September 2022 to December 2024.

How we kept usage under control

Attribution told us who used what. Keeping usage down took rules that ran on their own: a guardrail on running queries, a scheduler for slots and a review loop for storage.

Strategy 3: Stop runaway queries automatically

The query killer stops long running ad hoc queries before they slow every other team. A DAG checks running jobs in INFORMATION_SCHEMA every five minutes and applies three rules.

We pushed analysts to pre-compute heavy analysis rather than run it ad hoc. We ran the query killer in audit-only mode for a few weeks before it started cancelling queries. In its first quarter it cut average slot usage by more than a thousand slots. Google's BigQuery pricing page lists the price per slot-hour, if you want to estimate what that saves.

We built our own because BigQuery's limits didn't fit. Custom quotas and maximum bytes billed cap the bytes a query scans under on-demand pricing, and at the time reservations had no per-query slot limit.

A short query can finish before the next check, and a cancelled query can still be billed, so the on-demand rules kept unintended spend small, not at zero. Mostly they caught leaks: projects running on demand by mistake, and projects that no longer needed BigQuery at all.

Strategy 4: Move slots to where the demand is

Once every query had an owner, we could see that teams needed slots at different times of day. Experiment analysis ran overnight, our dashboard aggregation tables, called cubes, built between 6 AM and 10 AM, and ad hoc analysis and dashboards peaked during office hours. A fixed split left some teams short at their peak while other teams' baselines sat unused.

We built a slot switcher to follow that pattern. The first version resized two reservations twice a day, and that alone cut reserved capacity by more than a thousand slots for eight hours every night. In early 2024 we extended it to more reservations and time windows, and with other optimisations and the first workloads moving to Spark, our autoscaling cost fell by about half. Today an hourly Airflow DAG reads a config table holding the baseline and maximum slots for each reservation, day and hour, and resizes each reservation through the Reservation API.

The switcher relies on BigQuery's idle slot sharing. A reservation can borrow slots that another reservation in the same admin project, region and edition isn't using, and BigQuery takes them back when their owner needs them. So a baseline is the only capacity a team can count on, and we size each one to the median load for that hour. A one-off spike runs on borrowed slots, which lets a smaller commitment cover the same work.

Hourly slot usage against each workload's assigned baseline, as a share of the full commitment. A line above its baseline is running on idle slots.

The switcher only moves slots between reservations. When combined demand fills the whole commitment, no idle slots are left to borrow, and the options are to move batch work into quieter hours or to buy more capacity.

Strategy 5: Make storage clean-up a weekly habit

Most tables nobody read were experiment outputs, scratch tables from ad hoc analysis, date-sharded copies and tables behind features that had since been retired. Our first clean-up was a one-off. We deleted old tables, and new experiment datasets used the space again within the same quarter. So we made deletion a weekly loop. A loop like that only works if owners trust it, and ours runs like this:

  1. A query reads the output of our daily metadata job and lists deletion candidates. These are tables that no job has read in 30 days and that weren't created in that window. It keeps only the tables that cost the most to store, so the list stays short enough for owners to review. The query joins them to a dataset-to-owner mapping.
  2. A bot posts the list to Slack, tagging the owners of those datasets.
  3. Owners can keep a table by whitelisting it, with a reason.
  4. On the next run, the bot deletes every table that wasn't kept, posts how much storage it freed, and publishes the next list.

Critical datasets, such as raw events, are excluded from the loop.

The weekly storage review loop, from daily table metadata to deletion and recovery.

The metadata job builds on BigQuery's job history, which is an incomplete signal. Queries answered from cache don't record the tables they read, and a 30-day window misses a report that runs once a quarter. That's why owners review every list before the bot deletes anything.

This loop deleted tens of tables a week, the most expensive first. More than once it deleted a table a team still needed. Each time we restored it with time travel, which keeps deleted or changed tables restorable for two to seven days. Those near misses are why we later set the time travel window per dataset by how critical the data is. Our datasets are on physical storage billing, which also bills the storage that time travel and fail-safe keep. A shorter window on less critical datasets saves money.

A second bot compares each dataset's size with the week before and tags the owners of any dataset that grew sharply.

Old partitions in tables that are still in use need a different rule. Some tables had partitions going back to 2020, while analysis needed at most a year. We set partition expiry, which deletes partitions older than a set age. Where a team still needed the history, we archived old partitions first and set an expiry on the archive too. Every partitioned table got an expiry, and each dataset's owners chose the age.

The weekly loop wasn't our only clean-up. Alongside it we ran several larger rounds that deleted whole datasets. Over 2024, together with partition expiry and shorter time travel windows, these cut the number of tables by almost 90% and our storage bill by about two thirds.

Where a second engine made sense

Cost attribution showed which workloads were expensive. Some of them didn't fit a warehouse where every team draws on the same purchased capacity:

  • ML training data-prep. Ranking teams built training sets by joining features and labels over very large logging tables. One logging table alone was about 380 TB. Those joins ran for a long time and competed with dashboards for slots, and the teams decided to build training data with Spark.
  • Large historical batch jobs. Backfills and historical aggregations needed many slots for hours at a time. When slots were tight they slowed down, and they often had to be retried.
  • Streaming ingestion. Events streamed into BigQuery through the Storage Write API, and a few hundred tables accounted for 99% of the streaming cost. Their consumers agreed that data 15 minutes or an hour old was fresh enough. Later, we moved them to loads every 15 minutes or every hour, written by the new Spark pipeline.

Separate reservations could isolate these jobs from dashboards, but giving both enough throughput meant more capacity than we wanted to pay for. So the question became whether another engine could run the heavy batch work for less cost. Slot contention on its own is a reservation problem. A second engine is worth adding when it cuts the cost of the heavy work.

The second engine also meant a lakehouse. We planned to store its tables on Cloud Storage in an open table format, Delta at the time, so Spark jobs and ML training could read the files directly instead of exporting from the warehouse, and no single engine would own the data.

How we chose Databricks

We looked at Dataproc, Databricks and running Spark on Kubernetes ourselves. Dataproc's metastore integration was painful at the time, and running Spark at our scale was going to be hard. Databricks brought managed clusters, Unity Catalog and engineers who had tuned Spark at that scale, which got our workloads to production faster and taught us much of what we later needed to run Spark ourselves.

A proof of concept from April to July 2023 showed Spark could run a ranking team's training query at the same or lower compute cost. That comparison covered compute, both the cloud VMs and DBUs (Databricks' own compute unit). Until ingestion moved, Spark read copies of the data, which added storage and export cost. A fair comparison counts compute and storage together, because two engines over two copies of the data cost more than compute alone suggests.

Deciding what moves and what stays

Once we had chosen Databricks, we mapped every workload to an engine by its share of BigQuery slot usage at the time. The attribution pipeline made this possible, because every query already had an owner and a workload type.

We planned to move scheduled, heavy and repeatable work to Spark, using spot instances and clusters sized for each job. Interactive SQL and dashboards would stay on BigQuery, where analysts already worked and queries didn't need a cluster to start. We planned three phases: platform-owned ETL such as cubes and experiment analysis, then raw event ingestion into Delta with BigQuery copies only where needed, then the data science teams' ETL.

The rollout took most of a year. We moved the data platform team's own ETL and event ingestion to Spark first. In practice the ingestion pipeline wrote every event type to both Delta and BigQuery, and that second copy stayed until 2026. Those first workloads moving to Spark cut our BigQuery commitment by about 70% from its mid-2023 level. We also turned autoscaling off, so the commitment was all the capacity we ran.

Analysts, most dashboards, scheduled queries that teams set up inside BigQuery, and product paths such as notifications stayed on BigQuery. Those workloads depend on what made us choose BigQuery: managed SQL execution, no clusters to run, and the analytics workflows our teams already had.

Where it ended up

BigQuery still serves our analysts, our dashboards, experiment analysis, the scheduled queries teams build themselves, and product paths such as notifications. Those workloads are most of what the slot switcher manages today. BigQuery also reads our lake's Apache Iceberg tables in place as external tables, so most data now has one copy.

Aggregation cubes, event ingestion and the ML teams' data preparation moved to Spark over the next two years. In 2025 and 2026 we moved them off Databricks to open-source Spark and Flink that we run ourselves, a step we could only take after years of building that expertise.

What we learned

  1. Start managed, and budget for governance. BigQuery let a small team move fast for years. The cost came from how we used it, and the fixes were built on its own APIs.
  2. Attribute before you optimise. Most decisions in this post, from deleting a DAG to choosing which workloads to move, started from the cost per query.
  3. Turn every clean-up into a schedule. The weekly bots kept finding waste long after the first clean-up.
  4. Choose engines by workload. BigQuery kept interactive SQL and dashboards. Spark took the heavy batch and ML jobs that cost more to run on slots.

We may follow this with more on why we moved from Databricks to an open lakehouse, and how we run Spark and Flink ourselves.


Credits: Rushabh Shroff, Brijesh Savaliya, Mrunal Mendgudle, Nilesh Kevlani, Rajneesh Gupta

Other Suggested Blog

Are you in search of a job profile that fits your skill set perfectly?

Congratulations! You’ve reached the right place!

We are enroute to building a team of humble, yet ambitious folks. Grow professionally in your career with us, as we offer tremendous room for growth in unique career fields. Do not miss out on this unique opportunity. Send us your resume today!