Suggest an editImprove this articleRefine the answer for “What is HyperLogLog?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)HyperLogLog (HLL) in Redis is a probabilistic data structure for counting the number of unique elements (cardinality) with minimal memory use: it takes about ~12 KB regardless of how many elements there are, with roughly ±0.81% accuracy, and it doesn't store the values themselves. **Key point:** unlike a Set, HyperLogLog doesn't give an exact result and doesn't let you iterate elements or check membership - only an approximate count, so it fits DAU/MAU, traffic analytics, and large volumes of events, not places where 100% accuracy is required.Shown above the full answer for quick recall.Answer (EN)Image**HyperLogLog (HLL) in Redis** is a **probabilistic data structure** for **counting the number of unique elements** (cardinality) **with minimal memory use**. ## In simple terms If you need to find out: - how many **unique users** visited a site, - how many **unique IPs / events / IDs** there were, - while **not storing all the values**, → **HyperLogLog** solves this problem **very efficiently**. ## Key properties | Property | Value | |---|---| | Type | A probabilistic algorithm | | Purpose | Counting unique values | | Memory | ~12 KB **regardless of the number of elements** | | Accuracy | ≈ **±0.81%** | | Speed | Very high | | Stores the values themselves? | No | Important: HLL **doesn't return the elements themselves**, only an **approximate count**. ## How it works (intuitively) 1. Elements get **hashed** 2. The distribution of bits gets analyzed 3. A mathematical model estimates the number of unique values Redis stores a **compact statistical representation**, not a list of values. ## Redis commands for HyperLogLog ### `PFADD`, add elements ```redis PFADD users 1 2 3 4 ``` ### `PFCOUNT`, get the unique count ```redis PFCOUNT users ``` ### `PFMERGE`, merge several HLLs ```redis PFMERGE all_users users_day1 users_day2 ``` ## A real-world example ### Unique users per day ```redis PFADD visitors:2025-12-22 user_123 PFADD visitors:2025-12-22 user_456 PFCOUNT visitors:2025-12-22 ``` Even with **10 million** users, memory usage stays at ~12 KB. ## Comparison with other approaches ### Set ```redis SADD users user1 user2 user3 SCARD users ``` | Set | HyperLogLog | |---|---| | Exact | Approximate | | Stores values | No | | Memory grows | Memory is fixed | | Fits analytics | Yes | ## When to use HyperLogLog A great fit for: - DAU / MAU / WAU - traffic analytics - events, clicks, views - large systems (millions / billions of IDs) Not a fit if: - **100% accuracy** is required - you need to **iterate elements** - you need `exists`, `remove` ## Frequently asked questions ### How large is the error margin? Around **0.81%** For example: - the real value: `1,000,000` - the result: `~992,000 - 1,008,000` ### Can the error margin be reduced? No, in Redis, the size and accuracy are fixed by the implementation. ### Can elements be removed? No. Only adding is supported. ## The short rule of thumb > **Need a unique count + a lot of data + minimal memory → HyperLogLog**For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.