Describe strategies to handle data skew in BigQuery queries during joins or aggregations.

Quick Overview

Describe how to find and fix data skew in BigQuery joins and aggregations when a few hot keys hold most of the rows. Tests reading a distributed query plan and knowing practical remedies such as pre-aggregation, broadcast joins, salting and handling NULL or placeholder keys.

Describe strategies to handle data skew in BigQuery queries during joins or aggregations.

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Describe strategies to handle data skew in BigQuery queries during joins or aggregations. A typical case is an events table where a few keys, such as bot accounts or a placeholder user id, hold a large share of the rows. ```hint Follow the shuffle In a distributed join or `GROUP BY`, rows with the same key are sent to the same worker. Ask what that worker's load looks like when one key holds 20% of the table, and how you would see that in the query plan. ``` ```hint Splitting a key If you split one hot key across several workers, think about what the other side of a join has to do so that every row still finds its match. ``` ### What a Strong Answer Covers - What skew is and why it slows a distributed query: hashing on the key sends all of a hot key's rows to one worker. - How to confirm skew before fixing it, from per-stage average and maximum worker time in the query plan and from the key's value distribution. - Ways to shrink the data before the shuffle: filtering, pre-aggregating, and separating NULL or placeholder keys. - Salting for joins and aggregations, including replicating the other side of a join and re-aggregating afterwards. - When BigQuery's broadcast join applies, and isolating hot keys into a separate path. ### Follow-up Questions - Salting a join means replicating the smaller side. How do you choose the number of buckets, and what does it cost? - How would you compute an exact `COUNT(DISTINCT session_id)` per user when a few users have most of the sessions? - A window function with `PARTITION BY user_id` fails with "Resources exceeded". What are your options? - How would you keep a daily pipeline from slowing down again when new hot keys appear?

Overview: Describe how to find and fix data skew in BigQuery joins and aggregations when a few hot keys hold most of the rows. Tests reading a distributed query plan and knowing practical remedies such as pre-aggregation, broadcast joins, salting and handling NULL or placeholder keys.

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

Describe strategies to handle data skew in BigQuery queries during joins or aggregations. A typical case is an events table where a few keys, such as bot accounts or a placeholder user id, hold a large share of the rows.

What a Strong Answer Covers Guidance

  • What skew is and why it slows a distributed query: hashing on the key sends all of a hot key's rows to one worker.
  • How to confirm skew before fixing it, from per-stage average and maximum worker time in the query plan and from the key's value distribution.
  • Ways to shrink the data before the shuffle: filtering, pre-aggregating, and separating NULL or placeholder keys.
  • Salting for joins and aggregations, including replicating the other side of a join and re-aggregating afterwards.
  • When BigQuery's broadcast join applies, and isolating hot keys into a separate path.

Follow-up Questions Guidance

  • Salting a join means replicating the smaller side. How do you choose the number of buckets, and what does it cost?
  • How would you compute an exact COUNT(DISTINCT session_id) per user when a few users have most of the sessions?
  • A window function with PARTITION BY user_id fails with "Resources exceeded". What are your options?
  • How would you keep a daily pipeline from slowing down again when new hot keys appear?