Minus Log Of Random

A hot key is written with a 60 second TTL. Readers arrive throughout its life, and the four nearest expiry are marked.

A key written at t=0 with a 60 second TTL, with the early recompute window sitting just before expiry t=0 write t=60 expiry r1 r2 r3 r4 early recompute window

Every reader runs this, where Δ\Delta is the measured wall time the last recompute took and rand() draws uniformly from (0,1](0, 1]:

function XFetch(key, ttl; beta = 1)
    value, delta, expiry <- CacheRead(key)
    if !value or Time() - delta * beta * log(rand()) >= expiry then
        start <- Time()
        value <- RecomputeValue()
        delta <- Time() - start
        CacheWrite(key, (value, delta), ttl)
    end
    return value
end

What does the term −Δβln⁡(rand())-\Delta\beta\ln(\text{rand}()) accomplish?

A

It scales the TTL by β\beta, so raising β\beta keeps values cached longer and lowers origin load

B

It pulls each reader's effective expiry earlier by an independent exponential random amount whose scale is the recompute cost, so expensive keys are refreshed further ahead and typically one reader does it

C

It adds jitter to the TTL when the value is written, spreading expiry times across keys

D

It makes readers that arrive near expiry sleep a random interval and retry, so only the first one reaches the origin