Explore cache miss attacks, their impact, and mitigation strategies.
Caching is awesome but it doesnโt come without a cost, just like many things in life.
One of the issues is ๐๐๐๐ก๐ ๐๐ข๐ฌ๐ฌ ๐๐ญ๐ญ๐๐๐ค. Please correct me if this is not the right term. It refers to the scenario where data to fetch doesnโt exist in the database and the data isnโt cached either. So every request hits the database eventually, defeating the purpose of using a cache. If a malicious user initiates lots of queries with such keys, the database can easily be overloaded.
The diagram above illustrates the process.
Two approaches are commonly used to solve this problem:
Cache keys with null value. Set a short TTL (Time to Live) for keys with null value.
Using Bloom filter. A Bloom filter is a data structure that can rapidly tell us whether an element is present in a set or not. If the key exists, the request first goes to the cache and then queries the database if needed. If the key doesnโt exist in the data set, it means the key doesnโt exist in the cache/database. In this case, the query will not hit the cache or database layer.