Sub topic 1
What you are choosing for: workload types and data scale
Prerequisites
This chapter assumes you can write basic Python, read tabular data (rows, columns, data types), and write simple SQL with SELECT, WHERE, GROUP BY, and JOIN. You should have loaded and transformed a dataset with pandas or SQL at least once. No knowledge of Polars, DuckDB, or Spark is needed yet.
Why start with the workload
Tool comparisons often start with benchmarks. That is backwards. A tool is fast or slow only for a particular workload on a particular amount of data. Before you compare pandas, Polars, DuckDB, and Spark, you need to describe what you are asking them to do.
Two questions come first:
- What kind of work is it?
- How big is the data, and how fast is it growing?
Workload types
Most tabular work falls into a few families. Each puts different stress on a tool.
| Workload | Typical operations | What it stresses |
|---|---|---|
| Exploration | Inspect, filter, plot, try ideas | Interactivity, a rich Python ecosystem |
| Analytical queries | Filter, group, aggregate, join | Scan speed, reading only the needed columns |
| Batch ETL | Read, clean, reshape, write on a schedule | Throughput, reliability, repeatability |
| Feature engineering | Row-wise transforms, windows, custom functions | Expressiveness, support for Python code |
| Large joins and sorts | Combine or order very large tables | Memory, and data movement between machines |
Analytical queries touch a few columns across many rows. Exploration touches many columns, but you often work on a sample. This difference matters later, when we look at columnar storage and lazy evaluation.
Data scale
Scale means more than row count. Three measures matter:
- Size on disk. A Parquet file is compressed. The same data is much larger once loaded into memory.
- Size in memory. This decides whether a single machine can hold the data. It also includes the working copies that operations create.
- Growth. A table of 5 GB today that grows 3x a year is a different problem from one that stays flat.
A practical rule of thumb is that eager tools like pandas can need several times the raw data size in RAM during a transformation, because intermediate results are copies. Treat that as an estimate to check, not a fact. Chapter 10 covers it in detail.
Rough scale bands
These bands are guides. Hardware, data types, and the operation all move the boundaries.
Notice that the bands overlap. A dataset that fits in memory can still be a good fit for DuckDB if the work is SQL-shaped. The band narrows the options. It does not pick the tool.
A quick size estimate
You can estimate in-memory size before loading anything. Multiply rows by the bytes per value, summed over columns.
rows = 200_000_000
# region as int32 (4 bytes), revenue as float64 (8 bytes), user_id as int64 (8 bytes)
bytes_per_row = 4 + 8 + 8
gib = rows * bytes_per_row / 1024**3
print(f"{gib:.1f} GiB of raw column data")This prints about 3.7 GiB. A string column can cost far more, so check the real data types before you trust the estimate.
Common errors at this stage
- Choosing by data size alone. A small dataset with a heavy Python-function workload may suit a different tool than a large one with simple SQL.
- Using file size as memory size. Compressed Parquet can expand several times when loaded.
- Planning only for today. Pick a tool with the growth rate in mind, or plan a migration path.
Exercise
A Parquet file is 2 GB on disk. You want to run a join and a sort on it on a laptop with 8 GB of RAM. Why is "2 GB is less than 8 GB, so it will fit" an unreliable conclusion?
Show answer
The 2 GB is compressed. Loaded into memory it can be several times larger. Joins and sorts also create temporary copies, so peak memory use is higher than the loaded size. The job might run out of memory, or it might need a tool that reads only needed columns or processes data in chunks.