Name some Cache Stampede mitigation techniques

Technology CommunityCategory: CachingName some Cache Stampede mitigation techniques
VietMX Staff asked 4 years ago
  • Locking – a process will attempt to acquire the lock for the cache key and recompute it only if it acquires it. If implemented properly, locking can prevent stampedes altogether, but requires an extra write for the locking mechanism. Apart from doubling the number of writes, the main drawback is a correct implementation of the locking mechanism which also takes care of edge cases including failure of the process acquiring the lock, tuning of a time-to-live for the lock, race-conditions, and so on.
  • External recomputation – This solution moves the recomputation of the cache value from the processes needing it to an external process. This approach requires one more moving part – the external process – that needs to be maintained and monitored. The recomputation of the external process can be triggered in different ways:
    • When the cache value approaches its expiration
    • Periodically
    • When a process needing the value encounters a cache miss
  • Probabilistic early expiration – With this approach, each process may recompute the cache value before its expiration by making an independent probabilistic decision, where the probability of performing the early recomputation increases as we get closer to the expiration of the value. Since the probabilistic decision is made independently by each process, the effect of the stampede is mitigated as fewer processes will expire at the same time.