Techies Journal
AboutContact

Techies Journal

A collection of technical essays on systems, backend architecture, and the craft of engineering.

Sections

  • Technology
  • System Design
  • Backend Engineering
  • Cloud & DevOps
  • AI & ML

Connect

  • About Me
  • Contact

Presence

© 2026 Techies Journal. Handcrafted for readability.

PrivacyTerms
System Architecture
2026-01-26

How Instagram Tells You a Username Is Taken in Under 100ms

RU
Rishabh UpadhyaySoftware Engineer & Designer

‍ How Instagram Checks Usernames in < 100ms

How does Instagram tell you "username already taken" in under 100ms?

At Instagram's scale, this is a hard problem.

  • Millions of users
  • Global traffic
  • Thousands checking the same usernames simultaneously

Yet the feedback feels instant.

Here's what's really going on under the hood


Why This Is a Non-Trivial Problem

If Instagram queried its primary database every time you typed a username:

  • Latency would spike
  • Databases would melt
  • Signup would feel painfully slow

At global scale, this approach is not just inefficient — it's unsustainable.

So Instagram follows a different rule:

** Optimize for fast feedback, enforce correctness later.**


Step 1: Normalize Everything

Before any lookup happens, the username is normalized.

This typically includes:

  • Converting to lowercase
  • Stripping dots or special characters
  • Applying reserved-word rules

For example:

Code
John_Doe
john.doe
JOHNDOE

All map to the same canonical key: johndoe

This prevents edge-case collisions and simplifies downstream checks.


Step 2: Hit Memory, Not Disk

Username availability is checked against in-memory systems, not the main database.

This includes:

  • Redis-like caches
  • Optimized key-value stores

These systems provide:

  • O(1) lookups
  • Millisecond-level latency

This is what powers the fast "available / taken" message you see while typing.


Step 3: Assume the Cache Can Lie

Caches are fast — but they're not authoritative.

Two users can still:

  • Check the same username
  • See it as available
  • Click "Sign up" at the same time

This is expected behavior in distributed systems.

That's why Instagram never trusts the cache alone.


Step 4: Enforce Truth at Write Time

When you finally submit the signup form:

  1. Database enforces a unique constraint
  2. Only one insert succeeds
  3. The rest fail cleanly and predictably

This is where correctness lives.

The database is the final source of truth.


The Key Insight (This Is the Trick)

** Fast feedback is optimistic.** ** Final correctness is pessimistic.**

Code
Cache  → Speed (fast but can be stale)
Database → Truth (slow but authoritative)

Great systems separate:

  • User experience
  • Data integrity

Trying to solve both in one layer leads to slow, fragile systems.


Why This Pattern Matters

You'll see this design everywhere:

  • Username availability
  • Email checks
  • Seat booking systems
  • Inventory management
  • Rate-limited resources

Anytime you need:

  • Instant feedback
  • Strong correctness guarantees

This pattern shows up.


Visualizing the Flow

Code
User types username
  ↓
 Normalize input (lowercase, strip chars)
  ↓
 Cache lookup (fast, optimistic)
  ↓
 UI feedback shown ("available" or "taken")
  ↓
 Final submit
  ↓
 Database unique constraint (authoritative)
  ↓
 One succeeds, others fail gracefully

System Design Takeaway

If your system feels:

  • Instant
  • Responsive
  • And still never breaks rules

It's probably:

  • Lying early (optimistic cache)
  • Enforcing later (pessimistic database)

That's not a bug. That's good design.


Final Thought

At scale, correctness and speed rarely come from the same place.

The systems that win are the ones that know where each belongs.


What to Explore Next

Want to dive deeper into related topics?

  • Race condition handling & idempotency
  • Global consistency & replication strategies
  • CAP theorem in practice
  • Comparing naive vs optimized designs
Continue Reading
2026-01-28

When You Send 'Hi' in a WhatsApp Group of 256 People — Does the Database Get Hit 256 Times?

Ever wondered what really happens under the hood when you send a message in a large WhatsApp group? This post breaks down how modern chat systems avoid database overload and scale to billions of messages.

2026-01-27

How Google & Microsoft Authenticator Generate 6-Digit Codes Every 30 Seconds — Even Offline

A deep but simple explanation of how Google and Microsoft Authenticator generate time-based one-time passwords (TOTP) every 30 seconds without internet access.

2026-02-03

Why Netflix Shows a Black Screen When You Try to Screen Record

A deep technical breakdown of DRM, secure video pipelines, OS-level hooks, and hardware protections that prevent Netflix screen capture.

On This Page

  • ‍ How Instagram Checks Usernames in < 100ms
  • Why This Is a Non-Trivial Problem
  • Step 1: Normalize Everything
  • Step 2: Hit Memory, Not Disk
  • Step 3: Assume the Cache Can Lie
  • Step 4: Enforce Truth at Write Time
  • The Key Insight (This Is the Trick)
  • Why This Pattern Matters
  • Visualizing the Flow
  • System Design Takeaway
  • Final Thought
  • What to Explore Next

Share Perspective

TwitterLinkedInInstagram