Optimize the 100M-Row Join

PYSPARK coding challenge · Difficulty: hard · Topic: Performance · +200 XP

Problem

A join between a large DataFrame and a small lookup DataFrame is triggering a full shuffle, which is why the production version of this job runs for 40+ minutes.

large_df holds the transactions and small_ref_df is a tiny reference table. When one side is small enough to fit in memory, broadcasting it removes the shuffle entirely.

Join the two so every row of large_df is enriched with its category.

Example Input - `large_df`

| product_id | quantity | price |
| --- | --- | --- |
| SKU-001 | 5 | 29.99 |
| SKU-002 | 12 | 9.99 |
| SKU-001 | 3 | 29.99 |

Example Input - `small_ref_df`

| product_id | category |
| --- | --- |
| SKU-001 | Electronics |
| SKU-002 | Books |

Expected Output

| product_id | quantity | price | category |
| --- | --- | --- | --- |
| SKU-001 | 5 | 29.99 | Electronics |
| SKU-002 | 12 | 9.99 | Books |
| SKU-001 | 3 | 29.99 | Electronics |

Notes

What this PYSPARK challenge teaches you

“Optimize the 100M-Row Join” is a hard-level PYSPARK challenge focused on Performance. Working through it gives you hands-on practice with broadcast, partitioning, performance — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.

Concepts covered

How to approach it

If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:

  1. This is a Performance problem — review the matching pyspark concept.
  2. Compare your output to the Expected Output — the columns, values and row order must match exactly.

Where this comes up

Variations of this problem have been reported in interviews at Databricks, Meta, LinkedIn. Interviewers use it to check whether you can express the logic cleanly and reason about correctness on edge cases such as ties, nulls and empty groups.

How to practise it on PySpark.in

Open the challenge, write your PySpark code in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.

Related PYSPARK challenges

Frequently asked questions

Do I need to install Spark or a database to solve this?

No. The PYSPARK environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.

Is this challenge free?

Yes - the problem, the sample dataset, the hints and unlimited test runs are free.

What level is it?

It is rated hard and covers Performance.

Solve this challenge free on PySpark.in