AlgoMaster Logo

HyperLogLog

Low Priority17 min readUpdated October 25, 2026
AI Mock Interview

Practice this topic in a realistic system design interview

Premium Video

This video is available to premium subscribers only

Unlock Full Access

Analytics systems often need to answer questions like:

  • How many unique users visited today?
  • How many different people read this article?
  • How many unique search queries did we see this week?

Counting these exactly means remembering every item you've seen, which gets expensive fast. HyperLogLog estimates the count instead, using only a few kilobytes of memory.

In this chapter, we'll learn what HyperLogLog is, how it can estimate the number of unique items in a huge dataset using only a few kilobytes of memory, and where systems use it in practice.

1. The Problem

Suppose you're running a large content platform. You want to show how many unique readers each article gets in a day.

We're not interested in the total number of views, but in how many different people actually read the article. If someone opens the same article ten times, they should still count as just one reader.

There's a simple, exact way to track this. For each article, maintain a set of user IDs. Whenever someone views the article, we add their ID to the set. Since a set only stores unique values, repeated views from the same user won't increase its size.

At the end of the day, we simply count the IDs in the set to get the number of unique readers.

2. Why Exact Counting Gets Expensive

Now let's look at how much memory this approach requires.

Suppose a popular article gets 50 million unique readers in a day. If each user ID takes 8 bytes, storing those IDs alone takes about 400 MB, even before counting the hash set overhead. And that's just for one article on a single day.

Now imagine your platform has a million articles. And you also want to track unique readers by week, month, country, and device type. Each of these combinations needs its own set, so memory usage grows very quickly.

The more unique readers you have, and the more ways you slice them, the more data you need to store. And if that data is spread across multiple servers, combining exact counts means sending all those IDs over the network.

QuestionExact setHyperLogLog
Unique readers of one article todayGrows with readers (~400 MB for 50M)~12 KB
Unique readers this weekRe-dedupe all the daily IDsMerge 7 daily sketches
Unique readers per country and deviceOne large set per combinationOne small sketch per combination
Unique readers across serversShip all IDs to one placeShip ~12 KB per server

This brings us to an important question: can we count unique items without storing every single one?

3. What Is HyperLogLog?

Premium Content

This content is for premium members only.