Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Why this matters**: Wrong storage level = OOM or unnecessary disk I/O. **cache()** = `persist(StorageLevel.MEMORY_AND_DISK)`—default for quick reuse. **persist()** accepts levels: MEMORY_ONLY (fast, evicted if OOM), MEMORY_AND_DISK (spill to disk), MEMORY_ONLY_SER (serialized,...
Why this matters: Wrong storage level = OOM or unnecessary disk I/O. cache() = persist(StorageLevel.MEMORY_AND_DISK)—default for quick reuse. persist() accepts levels: MEMORY_ONLY (fast, evicted if OOM), MEMORY_AND_DISK (spill to disk), MEMORY_ONLY_SER (serialized, less memory), MEMORY_AND_DISK_SER, DISK_ONLY. Use cases: MEMORY_ONLY for hot small DataFrames; MEMORY_AND_DISK when data may not fit; serialized for memory savings. Scalability trade-offs: MEMORY_ONLY eviction = recompute; MEMORY_AND_DISK = disk I/O on eviction. Cost implications: Unpersist when done—holding memory blocks other tasks. Checkpoint for lineage truncation when DAG is deep. Best practice: Profile; prefer built-in operators over manual cache when possible.
Red Flag: Caching and never unpersisting—memory leak across jobs. Pro-Move: 'We persist(MEMORY_AND_DISK_SER) for 500MB dim; unpersist in finally block.'
According to DataEngPrep.tech, this is one of the most frequently asked Spark/Big Data interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.