What are approximate aggregates like APPROX_COUNT_DISTINCT, and when should you trade exactness for speed and cost?

Quick Overview

Asks what approximate aggregate functions such as APPROX_COUNT_DISTINCT do in BigQuery and when accepting a small error is worth the savings. Tests your understanding of probabilistic sketches, the cost of exact distinct counts at scale, and which metrics must stay exact.

What are approximate aggregates like APPROX_COUNT_DISTINCT, and when should you trade exactness for speed and cost?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

In BigQuery, what are approximate aggregate functions like `APPROX_COUNT_DISTINCT`, and when would you trade exactness for cost and speed? ```hint What exact counting needs Think about how much state an exact distinct count has to keep, and move between workers, when a column has billions of unique values. ``` ```hint Ask who reads the number Decide whether the person or system using the figure would act differently if it were off by about one percent. ``` ### What a Strong Answer Covers - What approximate aggregates are and how they work, including their memory and accuracy characteristics. - Why an exact `COUNT(DISTINCT ...)` becomes expensive at scale. - The main approximate functions and the HyperLogLog++ sketch functions for precomputing and merging results. - Workloads where the error is acceptable and workloads where it is not. - What actually gets cheaper under the billing model in use. ### Follow-up Questions - Why can't you add up daily distinct user counts to get a weekly count, and how do sketches solve that? - An experiment's primary metric is unique purchasers and the expected lift is 0.5%. Would you compute it with `APPROX_COUNT_DISTINCT`? - How does HyperLogLog estimate a cardinality from hashed values? - Under on-demand pricing, does switching a query to `APPROX_COUNT_DISTINCT` lower its bill? What would?

Overview: Asks what approximate aggregate functions such as APPROX_COUNT_DISTINCT do in BigQuery and when accepting a small error is worth the savings. Tests your understanding of probabilistic sketches, the cost of exact distinct counts at scale, and which metrics must stay exact.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

In BigQuery, what are approximate aggregate functions like APPROX_COUNT_DISTINCT, and when would you trade exactness for cost and speed?

What a Strong Answer Covers Guidance

  • What approximate aggregates are and how they work, including their memory and accuracy characteristics.
  • Why an exact COUNT(DISTINCT ...) becomes expensive at scale.
  • The main approximate functions and the HyperLogLog++ sketch functions for precomputing and merging results.
  • Workloads where the error is acceptable and workloads where it is not.
  • What actually gets cheaper under the billing model in use.

Follow-up Questions Guidance

  • Why can't you add up daily distinct user counts to get a weekly count, and how do sketches solve that?
  • An experiment's primary metric is unique purchasers and the expected lift is 0.5%. Would you compute it with APPROX_COUNT_DISTINCT ?
  • How does HyperLogLog estimate a cardinality from hashed values?
  • Under on-demand pricing, does switching a query to APPROX_COUNT_DISTINCT lower its bill? What would?