← Blog

Serverless Spark still needs a session cache for expensive DataFrames

Databricks put DataFrame caching on serverless compute into Public Preview — df.cache()/persist() materializes a session-local snapshot so joins, foreachBatch fan-out, and multi-model training stop recomputing the same work.

Data EngineeringLakehouseLLM Ops

Moving notebooks to serverless does not erase the old tax: recompute the same join every time you branch an analysis. Without a cache, interactive sessions and agent-driven experiments burn wallet and wall-clock on work they already paid for.

Databricks put DataFrame caching on serverless compute into Public Preview on October 23, 2026. Call `df.cache()` or `df.persist()` on serverless; Databricks computes the DataFrame immediately and materializes a session-local snapshot. The cached DataFrame and DataFrames derived from it (filter, select, join, and further chains) read that snapshot for the rest of the session instead of recomputing against source tables. Requirements: serverless environment version 5+, Databricks Connect Python 18.1.8+ or Scala 18.1.5+. Enabled by default for most workspaces; admins can disable via Previews. Not available with the compliance security profile. Docs call out reuse of expensive joins/aggregations, computing a streaming micro-batch once in `foreachBatch` then writing to several sinks, training or tuning several ML models on the same prepared features, and holding a stable snapshot while source tables change. Snapshots last until session end or at most seven days; `unpersist()` releases storage earlier.

What platform and data engineering leads should require as serverless becomes default:

  • Cache once at the expensive boundary, then derive — identical re-queries that are not derived from the cached DataFrame still hit sources
  • Prefer cache for multi-sink streaming and multi-model feature prep over writing ephemeral tables for every branch
  • Treat unpersist and session lifecycle as FinOps hygiene; seven-day auto-reclaim is not a substitute for clearing unused snapshots

Serverless removes cluster babysitting. It does not remove the need to materialize hard work once and reuse it while the session is still thinking.