23 Eylül 2026 Çarşamba

Cache Stratejileri - Cache Stampede

Giriş
Açıklamalar çoğunlukla buradan.

1. No protection
Every caller discovers the miss and independently loads the value.

This is the classic cache stampede / thundering herd.

The dangerous part is that the application may be completely correct. The database is simply receiving an unexpected burst.

2. Local singleflight
Here, each application instance says:

"If another thread on this same machine is already loading this key, I'll wait for its result."

Burada halen pod sayısı kadar hit gelebilir.

3. Fleet refresh lease
Only the pod that acquires the lease is allowed to refresh. Burada A uyandı ancak işi bitiremedi, sonra B uyandı işi bitirdi ve daha sonra A uyandı o da işi bitirdi ancak eski veriyi yazdı problemi var. Yani optimistic lock koymak lazım

4. Stale-while-revalidate
you distinguish:
- fresh
- stale-but-usable
- too-old / unavailable

Stale iken de veriyi sunar

The TTL jitter
Hepsi için kullanılabilir. Açıklaması şöyle
Bad jitter
If you do:
TTL = maxTTL + random()

then everything is already guaranteed to live at least maxTTL.

You're spreading the expiration times, but you're also violating the intended freshness boundary.

Subtractive jitter
Instead:
TTL = maxTTL - random()

gives:
maxTTL-0
maxTTL-3
maxTTL-17
maxTTL-42
...

So everything expires at or before the maximum freshness deadline.

The important concept isn't really the exact formula.

It's:

Randomize expiration without extending the maximum allowed lifetime.







Hiç yorum yok:

Yorum Gönder