Polars new Streaming Engine and Spill-To-Disk
Probably one of the biggest updates in the history of Polars happened recently, one that was long overdue. Polars has been slowly but surely creeping into the data landscape more and more, although not as quickly or as loudly as one would have hoped. I still see plenty of lost souls on Substack and LinkedIn posting their Pandas how-to’s, which is mind-boggling at this point … it’s time for those folk to move on to greener pastures.
I’ve been using Polars for years, on and off, many times in production. It’s been plagued by OOM (out of memory) issues since the early days. This is not really any surprise, though; most people don’t have big data and usually are fiddling about with data that easily fits on any one machine: a laptop or a server. This has been a well-documented problem, mostly ignored by the power that be in Polars. Until now, that is. Better late than never.
Probably one of the most confusing things about the ghost of Polars’ past, especially for the target audience coming from Pandas … that they really never grasped was that, normally, Polars, out of the box, most instructions and documentation supported that notion and reality that Polars was eager. Meaning, it would consume all the memory available and try to materialize any dataset(s) into memory when doing its work. Again, not a problem for small beans, but it can easily become a problem if you don’t understand what is going on behind the scenes… joining datasets, etc.
Old Polars
import polars as pl
df = (
pl.read_parquet("transactions.parquet")
.filter(pl.col("amount") > 100)
.group_by("merchant_id")
.agg(pl.col("amount").sum().alias("total_amount"))
)
print(df)
… in old Polars you could stream if you wanted …
import polars as pl
df = (
pl.scan_parquet("transactions.parquet")
.filter(pl.col("amount") > 100)
.group_by("merchant_id")
.agg(pl.col("amount").sum().alias("total_amount"))
.collect(streaming=True)
)
print(df)
- Note the difference in some of the terminology and functions…
read_parquetfor eager mode,scan_parquetwithcollect()for lazy mode.
The problem is people are lazy, especially data and software folk. They just wouldn’t spend the time to read the docs and understand the difference … they might be confused by the two options scan vs read but just move on with life. Now with the release of Polars 2.0 (use 2.1), the streaming engine is now the default.
import polars as pl
df = (
pl.scan_parquet("transactions.parquet")
.filter(pl.col("amount") > 100)
.group_by("merchant_id")
.agg(pl.col("amount").sum().alias("total_amount"))
.collect()
)
print(df)
In the past, there was this whole concept of Lazy Polars where you could do things in a streaming manner, and then collect() at any point, wherein the dataset would be materialized. This sort of Lazy approach is what should have been the main default since the inception of Polars. For those used to working in the Spark-land of big data, this all would have been familiar territory.
But for true high-end and large data processing in production, even the streaming mode could only get you so far.
Sure, this lazy execution can reduce memory pressure in many instances; combined with predicate pushdowns and smart query execution, this can be a good option, especially if you can stream resulting datasets straight to disk, some file sink, but most likely there were some data operations that required data to be materialized, and depending on the operation, OOM would happen anyway … just to much data in memory at some point. Polars was still missing a critical piece of data operation that tools like DuckDB were already handling, that is spill-to-disk.
When Lazy isn’t enough … spill, baby, spill.
To be counted among the pantheon of the greatest data tools to bless the threads of Linux servers, one must at some point have first-class support for spill-to-disk. Combined with streaming data processing, spill-to-disk takes a tool unto the top of Mt. Olympus. This is data processing on steroids, wherein during certain complex and intensive data movement like groupBy or Joins , maybe a Window function, requires a lot of data in memory for obvious reasons … and the compute and query engine can spill those datasets to disk as needed to avoid OOM.
Sure, this might “slow down” processing slightly, but that is much more preferable than OOM during the middle of operation.

This has been the Achilles’ heel of Polars for years, and it is finally fixed. Not only that, since Polars 2.1, with more SQL support, it can spill to disk across lots of data methods; Polars has finally outdone itself. Not only can you use Polars in Production for datasets larger than memory, but it now appears to be one of the fastest options out there, according to my testing … faster than DuckDB. That’s saying something.
- It’s wonderful to watch the Single Node Rebillion gain traction slowly, but surely.
It takes a while for such things to trickle down into the data community at large, much longer than it should. But now there are no excuses. Most people do not have big data, and if they do, they usually work on small subsets of said data. Cloud compute costs are no joke anymore; the big tools like Snowflake and Databricks are indeed amazing, but not cheap. Polars running on some commodity box on Linode or an Apache Airflow worker has now been supercharged with something like Polars installed. What was once not possible is now more than possible; it’s advisable.
Good job, Polars.


