Bloom filter — probabilistic data structure для проверки "element is probably in set" или "definitely not in set". Использует bit array + multiple hash functions. Memory-efficient (килобайты для millions items), но false positives возможны (no false negatives). Применяется: Cassandra (skip disk reads для missing keys), CDN (dedupe), DB indices, Chrome URL safety checks.
Ниже: подробности, пример, смежные термины, FAQ.
Бесплатный онлайн-инструмент — проверка HTTP-заголовков: результат мгновенно, без регистрации.
// Redis RedisBloom
> BF.RESERVE users 0.01 100000
> BF.ADD users alice
> BF.EXISTS users alice → 1 (probably)
> BF.EXISTS users bob → 0 (definitely not)A Bloom filter is a probabilistic data structure used to quickly check if an element might be in a set. It works by hashing the element multiple times and setting corresponding bits in a bit array. If all the bits are set, it indicates that the element might be in the set, but there's a chance of a false positive (indicating presence when it's not there). If any bit is not set, the element is definitely not in the set.
The false positives occur because the Bloom filter uses multiple hash functions to map elements to bits, and the chance of multiple hash functions colliding (mapping to the same bit) increases as more elements are added. However, there are no false negatives—if the filter says an element is not in the set, it's definitely not there.
To reduce the chance of false positives, you can increase the size of the bit array or use more hash functions. However, this will also increase memory usage.
Bloom filters have several advantages, including:
However, Bloom filters also have disadvantages, including:
Bloom filters are used in a variety of applications, including:
In each of these cases, the ability to quickly check for the presence of an element is more important than the small chance of a false positive.
Pre-filter перед expensive operations: check before DB query, before CDN miss. Если >95% запросов "not in set" — saves huge load.
Tradeoff: lower FPR = более crupнный filter. 1% FPR = 10 bits/element. 0.1% = 14 bits/element. Выбирайте по downstream cost.
HLL — count unique elements (cardinality), не membership. Разные задачи.
Бесплатный тариф — 10 мониторов, проверки каждые 5 мин, без карты. Платные тарифы — интервал от 1 минуты и проверки из нескольких регионов.