Have you ever tried creating an account on Instagram, Twitter, or Gmail?
You type a username like:
Abhijit8
…and instantly you get:
“Username already taken.”
What’s interesting is not the message.
It’s the speed.
These platforms have millions (sometimes billions) of users, yet they can check username availability in milliseconds.
So how do they do it so fast?
At first, the answer seems simple:
“Just search the username in the database.”
But here’s the problem.
Imagine:
-
20 million users
-
Thousands of signup requests every second
-
Every user trying 2–3 usernames
That would create an insane number of database calls.
And databases are expensive resources. You don’t want to hit them for every tiny operation.
#The Second Idea — HashMap:
Another idea could be storing all usernames in a HashMap.
That gives almost O(1) lookup time.
Fast? Yes.
Practical at huge scale? Not really.
Because storing millions or billions of usernames in memory takes a lot of space.
So engineers needed something:
-
Fast
-
Lightweight
-
Memory efficient
That’s where Bloom Filters come in.
#What is a Bloom Filter?
A Bloom Filter is a probabilistic data structure used to quickly check whether an element might exist in a system and it works on false positives.
The keyword here is:
Probabilistic
Unlike normal data structures, Bloom Filters are okay with being “slightly uncertain.”
And surprisingly, that tradeoff makes them extremely powerful.
#The Most Important Part — False Positives :
Bloom Filters work on something called:
#False Positives
Example:
Suppose Abhijit8 already exists.
Bloom Filter says:
“Yes, it exists.”
Correct.
Now suppose India90 does NOT exist.
Bloom Filter might still say:
“It probably exists.”
That’s called a false positive.
At first this feels wrong.
But think practically.
If a username gets rejected once, the user simply tries another one:
-
India901 -
India_90 -
India90x
No big issue.
And in return, the system avoids millions of expensive database lookups.
That’s a huge win.
#How Bloom Filters Work Internally
Bloom Filters mainly use:
-
Hash Functions : A hash function converts data into numeric values.
-
Buckets (Bit Arrays)
Suppose we have a bucket of size 10.
Initially:
Index : 0 1 2 3 4 5 6 7 8 9
Bucket : 0 0 0 0 0 0 0 0 0 0Now suppose:
Abhijit8 has hash value 0248
We mark those indexes as 1.
Index : 0 1 2 3 4 5 6 7 8 9
Bucket : 1 0 1 0 1 0 0 0 1 0Now another username comes:
Don7 → 1468
Before inserting, Bloom Filter checks:
-
Is index
1set? -
Is index
4set? -
Is index
6set? -
Is index
8set?Since index
1and6are still0, it understands:
“This username is definitely not present.”
Then it updates the bucket:
Updated bucket:
Index : 0 1 2 3 4 5 6 7 8 9
Bucket : 1 1 1 0 1 0 1 0 1 0Now suppose:
India90 → 1268
Bloom Filter checks:
-
1 → already filled
-
2 → already filled
-
6 → already filled
-
8 → already filled
So it says:
“This username probably already exists.”
Even though it was never added.
That’s the false positive.
And that’s completely okay.
Because the user can simply try another username.
#Why Bloom Filters Are Powerful
Bloom Filters are useful because they are:
-
Extremely fast
-
Memory efficient
-
Great for large-scale systems
They are commonly used in:
-
Username availability checks
-
Caching systems
-
Databases
-
Distributed systems
-
URL safety checks
Even Google Chrome uses Bloom Filter-like techniques to quickly detect malicious URLs.
#Conclusion:
Bloom Filters are a great example of real-world engineering.
What I personally love about Bloom Filters is the mindset behind them.
In college, we are taught:
“Systems should always be perfectly accurate.”
But real-world engineering teaches something different.
Sometimes being:
-
Fast enough
-
Efficient enough
-
Scalable enough
is more important than being 100% perfect.
Somewhere behind every “Username already taken” message…
a tiny Bloom Filter is probably doing its job silently in a few milliseconds.