<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: When should we avoid caching DataFrames in Databricks? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/178018#M57460</link>
    <description>&lt;DIV&gt;&lt;P&gt;Just adding a note which might help you :&lt;/P&gt;&lt;P&gt;Previously, for most of the ML workloads, teams heavily relied on caching DataFrames to avoid recomputation during multiple validation and transformation steps. However, with advancements in Spark optimization, storage engines, and modern data platform architectures, caching is no longer a default recommendation for every scenario.&lt;/P&gt;&lt;P&gt;Today, many workloads are optimized through efficient table formats (Delta/Iceberg/Hudi), query optimization, adaptive execution, memory management improvements, and the use of temporary or intermediate tables. These approaches often reduce repeated computation without consuming large amounts of executor memory, helping save significant compute resources while improving cluster stability.&lt;/P&gt;&lt;P&gt;A good rule of thumb is to cache only when:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The same DataFrame is reused multiple times in the execution plan.&lt;/LI&gt;&lt;LI&gt;The DataFrame is expensive to recompute (complex joins, aggregations, UDFs, ML feature engineering, etc.).&lt;/LI&gt;&lt;LI&gt;The performance gain from avoiding recomputation outweighs the cost of materializing and maintaining the cache.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Before caching, it's worth validating through Spark UI and execution plans whether recomputation is actually occurring and if it represents a significant portion of the job runtime.&lt;/P&gt;&lt;P&gt;Also, if the cached DataFrame is larger than available executor memory, Spark starts evicting cached partitions or spills data depending on the storage level. In such cases, using persist() with an appropriate storage level such as MEMORY_AND_DISK is generally more effective than pure in-memory caching, as it prevents repeated recomputation while avoiding executor out-of-memory issues.&lt;/P&gt;&lt;P&gt;In practice, modern architectures increasingly favor optimized table storage, checkpointing, or materialized intermediate datasets over aggressive DataFrame caching, reserving caching for proven high-reuse and high-computation datasets where measurable performance benefits exist.&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Sun, 29 Nov 2026 13:09:23 GMT</pubDate>
    <dc:creator>saisaranv</dc:creator>
    <dc:date>2026-11-29T13:09:23Z</dc:date>
    <item>
      <title>When should we avoid caching DataFrames in Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/177883#M57398</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Caching is generally recommended when we reuse a DataFrame multiple times. However, there seem to be situations where caching actually increases the execution time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How do we identify whether a DataFrame is worth caching?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also, what happens when the cached DataFrame is larger than the available executor memory? Is persist() with a different storage level a better option in such cases?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2026 08:33:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/177883#M57398</guid>
      <dc:creator>fatimak01</dc:creator>
      <dc:date>2026-11-28T08:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: When should we avoid caching DataFrames in Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/177939#M57426</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Caching is beneficial when a DataFrame is expensive to compute and reused multiple times. However, caching introduces memory and materialization overhead, which can outweigh its benefits.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;1. When should you avoid caching?&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;The DataFrame is used only once.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;The underlying transformation is inexpensive.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;The DataFrame is significantly larger than available executor memory.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;Caching creates memory pressure for subsequent joins and aggregations.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;2. Choose an appropriate storage level&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the DataFrame cannot fit entirely in memory, consider:&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;from pyspark import StorageLevel

df.persist(StorageLevel.MEMORY_AND_DISK)&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;Partitions that cannot fit in memory can be stored on disk, reducing the need for recomputation. However, disk access introduces additional overhead.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Note that PySpark &lt;/SPAN&gt;&lt;SPAN&gt;cache()&lt;/SPAN&gt;&lt;SPAN&gt; already uses &lt;/SPAN&gt;&lt;SPAN&gt;MEMORY_AND_DISK_DESER&lt;/SPAN&gt;&lt;SPAN&gt; by default in modern Spark versions.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;3. Monitor caching effectiveness&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Navigate to Spark UI → Storage and check the cached partition percentage, memory size and disk size. Also monitor garbage collection time and spill metrics in the Executors and Stages tabs.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example, if an expensive DataFrame is reused across five aggregations, caching may improve performance. However, caching the same DataFrame for a single Delta write may unnecessarily increase execution time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Always release cached data when it is no longer required:&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;df.unpersist()&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;My recommendation is to benchmark execution with and without caching rather than applying it by default. Also, consider caching only the required columns and filtered records instead of the entire DataFrame.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Official references:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrame.persist.html?utm_source=chatgpt.com" target="_blank" rel="noopener"&gt;PySpark DataFrame persist&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/optimizations/disk-cache?utm_source=chatgpt.com" target="_blank" rel="noopener"&gt;Caching in Databricks&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sat, 28 Nov 2026 12:08:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/177939#M57426</guid>
      <dc:creator>tajamulkhan</dc:creator>
      <dc:date>2026-11-28T12:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: When should we avoid caching DataFrames in Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/178013#M57458</link>
      <description>&lt;P&gt;cache&amp;nbsp;is &lt;STRONG&gt;not cheap&lt;/STRONG&gt; as it forces &lt;STRONG&gt;materialization&lt;/STRONG&gt; of the full result up front, stores it as in-memory blocks and deserialized Spark data can be several times larger than the compressed Parquet/Delta files it came from. So when a DataFrame is read only once, is a plain spark.table() read (automatic disk cache already accelerates on SSD-enabled workers) or is too big for executor &lt;STRONG&gt;memory&lt;/STRONG&gt;, you pay &lt;STRONG&gt;serialization&lt;/STRONG&gt;, &lt;STRONG&gt;storage&lt;/STRONG&gt; and &lt;STRONG&gt;eviction&lt;/STRONG&gt;/&lt;STRONG&gt;GC&lt;/STRONG&gt; costs for zero reuse - its when caching makes jobs slower&amp;nbsp;and you can prefer the &lt;STRONG&gt;automatic disk&lt;/STRONG&gt; &lt;STRONG&gt;cache&lt;/STRONG&gt; for repeated Parquet/Delta reads instead.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Cache&lt;/STRONG&gt; only when the same DataFrame feeds multiple actions after &lt;STRONG&gt;expensive&lt;/STRONG&gt; work (heavy joins, aggregations, complex filters, ML feature prep) - the transformation cost and its reuse count clearly exceeds the storage cost. Check the Spark UI - if a stage re-runs the same expensive subtree repeatedly, cache it - if it's a single scan, do not do it. For &lt;STRONG&gt;data&lt;/STRONG&gt; larger than executor memory, the classic compute default is already MEMORY_AND_DISK_DESER (spills to disk rather than recomputing), so persist(StorageLevel.DISK_ONLY) mainly helps when memory pressure evicts other work - but in that scenario you can usually skip Spark cache entirely and write the intermediate result to a Delta table instead, which downstream consumers can reuse. On serverless compute, persist&amp;nbsp;ignores the storage level entirely as it snapshots immediately - so storage-level tuning generally applies only to classic clusters.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2026 12:54:42 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/178013#M57458</guid>
      <dc:creator>balajij8</dc:creator>
      <dc:date>2026-11-29T12:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: When should we avoid caching DataFrames in Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/178018#M57460</link>
      <description>&lt;DIV&gt;&lt;P&gt;Just adding a note which might help you :&lt;/P&gt;&lt;P&gt;Previously, for most of the ML workloads, teams heavily relied on caching DataFrames to avoid recomputation during multiple validation and transformation steps. However, with advancements in Spark optimization, storage engines, and modern data platform architectures, caching is no longer a default recommendation for every scenario.&lt;/P&gt;&lt;P&gt;Today, many workloads are optimized through efficient table formats (Delta/Iceberg/Hudi), query optimization, adaptive execution, memory management improvements, and the use of temporary or intermediate tables. These approaches often reduce repeated computation without consuming large amounts of executor memory, helping save significant compute resources while improving cluster stability.&lt;/P&gt;&lt;P&gt;A good rule of thumb is to cache only when:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The same DataFrame is reused multiple times in the execution plan.&lt;/LI&gt;&lt;LI&gt;The DataFrame is expensive to recompute (complex joins, aggregations, UDFs, ML feature engineering, etc.).&lt;/LI&gt;&lt;LI&gt;The performance gain from avoiding recomputation outweighs the cost of materializing and maintaining the cache.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Before caching, it's worth validating through Spark UI and execution plans whether recomputation is actually occurring and if it represents a significant portion of the job runtime.&lt;/P&gt;&lt;P&gt;Also, if the cached DataFrame is larger than available executor memory, Spark starts evicting cached partitions or spills data depending on the storage level. In such cases, using persist() with an appropriate storage level such as MEMORY_AND_DISK is generally more effective than pure in-memory caching, as it prevents repeated recomputation while avoiding executor out-of-memory issues.&lt;/P&gt;&lt;P&gt;In practice, modern architectures increasingly favor optimized table storage, checkpointing, or materialized intermediate datasets over aggressive DataFrame caching, reserving caching for proven high-reuse and high-computation datasets where measurable performance benefits exist.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 29 Nov 2026 13:09:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-should-we-avoid-caching-dataframes-in-databricks/m-p/178018#M57460</guid>
      <dc:creator>saisaranv</dc:creator>
      <dc:date>2026-11-29T13:09:23Z</dc:date>
    </item>
  </channel>
</rss>

