š” Ever wondered how Instagram or X tells you in milliseconds whether a username is available?
This post explains the exact system design, from beginner-level ideas to Big Tech scale ā in a simple, skimmable format.
When a user types a username:
Check directly in the database.
SELECT COUNT(1)
FROM users
WHERE username = 'new_user';ā ļø Direct DB queries don't scale to billions of users
Store frequently checked usernames in memory.
User ā App Server ā Cache ā Database āāāāāāāāāāāā
ā Cache ā
āāāāāā¬āāāāāā
ā miss
āāāāāā¼āāāāāā
ā Database ā
āāāāāāāāāāāāš” Cache helps, but it's not enough for Big Tech scale
A probabilistic data structure that answers:
"Does this username possibly exist?"
username ā hash1 ā bit array
ā hash2 ā bit array
ā hash3 ā bit arrayIf any bit = 0 ā definitely NOT taken
If all bits = 1 ā probably taken[0 1 1 0 1 1 1 0]
ā ā āā ļø False positives are possible, false negatives are not
User
ā
Load Balancer
ā
Bloom Filter
ā
Cache
ā
Databaseš„ Most requests never reach the database
When daniel is taken, platforms suggest:
daniel_123daniel_devdaniel2025A tree-like structure that stores strings by prefixes.
d
āāā a
āāā n
āāā i ā e ā l
āāā n ā yš” Compressed Tries (Radix Trees) reduce memory usage
| Layer | Purpose |
|---|---|
| Database | Source of truth |
| Cache | Fast repeated lookups |
| Bloom Filter | Eliminate most DB hits |
| Trie | Suggestions & autocomplete |
⨠Big Tech systems scale by layering smart optimizations ā not by relying on one trick.
Speed at scale comes from filtering early and touching the database as little as possible.