Process 10 GB and 20 GB Files With PySpark on Your Laptop

You do not need a cluster to practise on big data. Spark can process files far larger than your memory on one laptop, because it spills work to disk. The limit is your disk space and your patience, not a cloud bill. Here is how to set up the Spark Lab for 10 GB and 20 GB files, and what to expect.

Open the Spark Lab

Why this works on one machine

In local mode Spark runs inside a single process on your laptop and uses all your CPU cores. It reads a big file in pieces, and when an operation such as a sort or a join does not fit in memory, it writes the extra to disk and carries on. So a 20 GB file can be processed on a laptop with 8 GB of memory. It is slower than a cluster, but it works.

Give Docker enough memory and disk

Docker Desktop limits what the lab can use. In Docker Desktop, open Settings, then Resources, and raise Memory and Disk image size. A good start is half of your laptop memory and at least three times the size of your biggest file in free disk, because shuffles and results also take space. The lab uses about 75% of the memory Docker gives it and shows the amount when you connect.

Skip the browser for the biggest files

Uploading through the browser works for large files, but for 10 GB and more it is simpler to put the file where the lab can already see it. Start the lab with the folder command from the Spark Lab page. The lab then uses the folder spark-lab in your home folder. Copy your file into spark-lab/uploads and it appears in the lab straight away. Nothing is uploaded or copied a second time.

Read it the efficient way

  • Prefer Parquet to CSV. It is smaller and faster, and it keeps column types. Convert a CSV once with the Format Converter or with Spark itself.
  • Avoid inferSchema on a huge CSV. It reads the whole file once just to guess types. Give Spark a schema instead.
  • Select only the columns you need early, and filter early, so less data moves.
  • Write results with export(df, "name", "parquet") rather than collecting them into Python.

Things that fail on a laptop

  • collect() and toPandas() on a big result pull everything into one process and can run out of memory. Write the result to a file instead, or show a small sample with limit().
  • A join between two big tables is a shuffle of both. Watch the Stages tab in the Spark UI to see how much data moves.
  • A very large number of tiny files is slow. Write fewer, larger files.

Keep the results

Results written with export() land in spark-lab/outputs (or in the Docker volume). Copy them out with the commands on the page, or save a small result to Recent files to keep its lineage with the rest of your work.

What to expect

On a modern laptop, a few GB takes minutes and 10 to 20 GB takes tens of minutes to hours, depending on the work. Use the Spark UI to see where the time goes: one slow stage usually points to one expensive shuffle or one skewed key.

Open the Spark Lab

Also try

How to use the Spark Lab: step by step

  1. Raise Docker memory and disk in Docker Desktop
  2. Start the lab with the folder command
  3. Copy the big file into spark-lab/uploads
  4. Read it, run your job and write the result with export()

When to use the Spark Lab

  • Practising on realistic file sizes
  • Testing a Spark job before it runs on a cluster
  • Processing a big export once without cloud costs
  • Learning how Spark spills to disk

Frequently asked questions

Can a laptop really process a 20 GB file?

Yes. Spark spills to disk when memory is full, so the limit is free disk space and time, not memory.

Is the file uploaded anywhere?

No. With the folder option the file stays on your disk and Spark reads it from there.

Tip: Test your code on the first million rows with limit() before running it on the whole file. Fix mistakes on a small sample, then run the full job once.