Stop hitting the database for things that aren't there: Use a Valkey Bloom Filter
Blog post from Aiven
Valkey Bloom is a plugin included in Aiven for Valkey, designed to optimize database queries by utilizing Bloom filters, which are probabilistic data structures that efficiently determine whether an item has been seen before. This approach reduces unnecessary database queries by first using an in-memory lookup to filter out definite non-existent items, thereby improving application performance. The process involves setting up a Bloom filter with a specified false-positive rate and capacity, populating it with data from PostgreSQL, and ensuring that the filter is regularly refreshed to maintain accuracy. Additionally, the system employs a caching mechanism to handle repeat queries efficiently, and it requires careful management of filter updates and persistence to avoid potential pitfalls such as excessive false positives or downtime during filter rebuilds. Bloom filters are particularly useful for applications dealing with mostly static data, enabling functions like deduplication and fraud detection while minimizing load on the database.