APM Lab · decision prototype · serverless compute

pm rule: don't size the default for the average session

Mirrors: DataFrame caching on serverless compute entered Public Preview (Databricks release notes, Oct 23, 2026).

The decision: how much memory each serverless session's DataFrame cache should get by default, judged on the rare sessions that blow it up rather than the typical one.

01 · the decision board

one default, four pins on the board

Customer problem

A data scientist on serverless notebooks builds a cleaned feature DataFrame, then queries it ten times while exploring. Without a cache, every query recomputes the whole lineage, so each "quick look" is another 20–60 seconds of waiting and paying.

pinned: the iterative-notebook user

Proposed change

Caching is in Public Preview. Before it's on for everyone, set a default per-session cache budget (in GB). When a session asks for more than the budget, least-recently-used entries get evicted. Past 3× the budget, eviction can't keep up and the session restarts. That restart is the crash I'm guarding against.

budget: 2–64 GBevict: LRU
pinned: the knob we ship

Success metric

Compute minutes saved per caching session, with a target of ≥ 2.0 min on average, and ≥ 90% of sessions whose whole cache fits in the budget.

Guardrails

  • Crash rate (demand > 3× budget) ≤ 1 per 10,000 sessions
  • Sessions made slower by caching ≤ 2%
  • Reserved-memory cost ≤ 25% of compute dollars saved
  • p95 interactive latency unchanged within ±5% (watched in the experiment)
pinned: how we'll know

Stakeholders

  • Serverless compute eng (memory manager, eviction)
  • Notebook & ML experience PMs (the users who call .cache())
  • Finance / COGS owners (reserved memory)
  • Support & docs (Preview limits, how to opt out)
  • Field engineers with heavy-ETL design partners
pinned: who signs off

Why this is hard

The average session caches about 3 GB, so any budget looks fine on average. The real risk sits in the right tail: a few sessions cache a huge join and crash. At 1-in-10,000 odds, plain Monte Carlo barely ever sees a crash. Importance sampling is the method built for that kind of tail.

pinned: the tail is the product
simulation room
02 · live Monte Carlo

Ten thousand notebook sessions, one budget

Each simulated session caches a few DataFrames with heavy-tailed (log-normal) sizes and reuses each one a geometric number of times. The left canvas shows each session's cache demand against the budget. The right canvas shows the running Monte Carlo estimate of minutes saved, with its ±1.96·SE band. The table compares the crash risk from plain sampling with the importance-sampling estimate. All numbers are synthetic.

seed 2026
fits in budgetevicts (slower hits)crash (>3× budget)IS proposal draws

Running mean of minutes saved per session (gold) narrows as n grows. The band width shrinks like 1/√n, as the CLT predicts.

–
min saved / session
(95% CI)
target ≥ 2.0
–
sessions fully
in budget
target ≥ 90%
–
crashes per 10k
(importance sampling)
guardrail ≤ 1
–
sessions made
slower
guardrail ≤ 2%
–
memory cost /
dollars saved
guardrail ≤ 25%
–
IS efficiency vs
plain MC
mean w ≈ 1
budgetfitsmin savedslowercrash/10k plain MCcrash/10k IS ± SEmem cost ratioverdict
03 · director memo (rewrites itself from the run)

memo: default cache budget for serverless

DRAFT
Decision
Run the simulation.
Evidence
–
Risks
–
Rollout plan
–
Next step
–
WHAT I'D TELL THE VP IN ONE SENTENCE
–
04 · the math, from my Monte Carlo course

monte carlo integration + importance sampling

An expectation is an integral, so average it

"Expected minutes saved per session" is an integral of the savings function over every possible session. I can't do it by hand: sizes are log-normal, counts are random, and eviction is a step function. So I draw n sessions and take the sample mean. By the Strong Law of Large Numbers it converges to the true value. The CLT gives an error bar: mean ± 1.96·s/√n. To make the band half as wide, you need four times as many sessions.

θ = E[h(X)] ≈ (1/n) Σ h(xᵢ)    SE = s / √n

Probabilities fit the same pattern. A crash rate is just the average of an indicator: 1 if the session crashed, 0 otherwise.

When the event is rare, sample where it lives

If crashes happen 1 in 50,000 times, 10,000 plain draws usually show zero, which would read as "safe" with no evidence behind it. Instead I draw sizes from a proposal g that pushes log-sizes up by δ, so big sessions show up often. Each draw then gets a weight w = f/g so the estimate stays unbiased for the real world f.

P(crash) ≈ (1/n) Σ w(xᵢ)·1[crash(xᵢ)],   w = Π f(sⱼ)/g(sⱼ)

Two checks keep me honest: the average weight should be close to 1, and efficiency (plain-MC variance ÷ IS variance) shows how many plain draws one weighted draw is worth. Set δ too large and a handful of weights dominate, so efficiency falls again. You can see that with the slider.

Product example in one line

It's the same move as estimating a 1-in-10,000 crash rate for a new default without making 10,000 customers crash: oversample the scary sessions on purpose, then reweight them back to how often they really happen. Smaller pieces of the course also show up here. Reuse counts come from the inverse-CDF method (R = 1 + ⌊ln U / ln(1−p)⌋, a geometric draw), and log-normal sizes come from Box-Muller normals.

05 · how I'd run it on real data

swap synthetic draws for telemetry

Illustrative table names only. The idea: fit the size and reuse distributions from Preview telemetry, then run the same importance-sampling estimate on every candidate budget before choosing the GA default.

SQL · per-session cache demand from Preview sessions
-- illustrative schema: one row per cache() call during the Preview
WITH per_session AS (
  SELECT session_id,
         COUNT(*)                         AS dfs_cached,
         SUM(cached_bytes) / POW(1024, 3) AS demand_gb,
         AVG(reuse_count)                 AS avg_reuse,
         SUM(recompute_ms_avoided) / 6e4  AS minutes_saved
  FROM preview_telemetry.cache_events
  WHERE event_date >= current_date() - INTERVAL 28 DAYS
  GROUP BY session_id
)
SELECT percentile_approx(demand_gb, array(0.5, 0.9, 0.99, 0.999)) AS demand_q,
       AVG(LN(demand_gb / dfs_cached))    AS mu_log_size,
       STDDEV(LN(demand_gb / dfs_cached)) AS sigma_log_size,
       AVG(avg_reuse)                     AS mean_reuse,
       AVG(minutes_saved)                 AS avg_minutes_saved
FROM per_session;
Python · importance-sampled crash rate for each candidate budget
import numpy as np
rng = np.random.default_rng(2026)

def crash_rate_is(mu, sigma, lam, budget_gb, delta=1.2, n=200_000):
    k = 1 + rng.poisson(lam - 1, n)                   # DataFrames per session
    logs = rng.normal(mu + delta, sigma, k.sum())     # proposal g: shifted log-sizes
    sid = np.repeat(np.arange(n), k)
    demand = np.bincount(sid, weights=np.exp(logs))
    # log w = sum over DFs of [(x-mu-delta)^2 - (x-mu)^2] / (2 sigma^2)
    logw = np.bincount(sid, weights=((logs-mu-delta)**2 - (logs-mu)**2) / (2*sigma**2))
    w = np.exp(logw)
    hit = w * (demand > 3 * budget_gb)
    return hit.mean(), hit.std() / np.sqrt(n), w.mean()  # estimate, SE, sanity (≈1)

fit = spark.table("pm_sandbox.cache_fit").first()     # mu, sigma, lam from the SQL above
for b in [4, 8, 16, 32]:
    p, se, wbar = crash_rate_is(fit.mu, fit.sigma, fit.lam, b)
    print(f"{b:>3} GB  crash/10k = {1e4*p:.3f} ± {1e4*se:.3f}   mean w = {wbar:.2f}")