<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sachin on Medium]]></title>
        <description><![CDATA[Stories by Sachin on Medium]]></description>
        <link>https://medium.com/@sachin.jhaa?source=rss-2f01a9dde1f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pxzhoC8FpBJpPkNMQ01SFw.jpeg</url>
            <title>Stories by Sachin on Medium</title>
            <link>https://medium.com/@sachin.jhaa?source=rss-2f01a9dde1f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:11:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sachin.jhaa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Big Tech Checks Your Username in Milliseconds]]></title>
            <link>https://medium.com/@sachin.jhaa/how-big-tech-checks-your-username-in-milliseconds-6ffdac12797f?source=rss-2f01a9dde1f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ffdac12797f</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[social-media]]></category>
            <dc:creator><![CDATA[Sachin]]></dc:creator>
            <pubDate>Wed, 24 Sep 2025 18:47:26 GMT</pubDate>
            <atom:updated>2025-09-24T18:49:25.600Z</atom:updated>
            <content:encoded><![CDATA[<p>When you sign up for an account on platforms like Google, Instagram, or Twitter, one of the first steps is picking a username. The system instantly tells you:</p><p>✅ Available<br> ❌ Already taken</p><p>But have you ever wondered <strong>how this check happens in milliseconds</strong>, despite billions of existing usernames?</p><p>Let’s dive into the <strong>data structures</strong> that make it possible: <strong>Trie, B-Tree, and B+ Tree</strong>.</p><p><strong>1. The Challenge </strong><br>- Billions of usernames already stored.<br>- Millions of concurrent sign-ups and checks<br>- Ultra-low latency (sub-millisecond response expected)<br>- Efficient memory + disk usage</p><p>The key question: How do we store and search usernames so fast?</p><h3>2. Trie: Character-by-Character Lookup ✨</h3><p>A <strong>Trie (prefix tree)</strong> is a natural fit for strings like usernames.</p><ul><li><strong>How it works</strong>: Each node represents a character. A path from root → leaf forms a username.</li><li><strong>Check availability</strong>: Traverse character by character. If the full path exists → username is taken. If traversal breaks → it’s available.</li></ul><p><strong>Why it’s fast:</strong></p><ul><li>Time complexity: O(L) (L = length of username).</li><li>Independent of the number of usernames stored.</li></ul><p><strong>Trade-offs:</strong></p><ul><li>High memory usage (sparse nodes, lots of pointers).</li><li>Not as disk-friendly — better for in-memory checks.</li></ul><p>👉 Big Tech often uses tries in <strong>caching layers</strong> (Redis, Memcached) to handle hot queries in memory.</p><h3>3. B-Tree: Disk-Friendly Indexing 📂</h3><p>When data exceeds memory capacity, systems resort to <strong>disk-based indexes</strong>.</p><ul><li><strong>B-Trees</strong> store keys in sorted order across nodes with multiple children.</li><li>A username (or its hash) can be quickly located by traversing a few levels.</li><li>Balanced structure ensures logarithmic search: O(log N).</li></ul><p><strong>Why it’s useful:</strong></p><ul><li>Handles <strong>billions of entries on disk</strong> efficiently.</li><li>Minimises I/O operations (nodes sized to match disk block size).</li></ul><p><strong>Trade-offs:</strong></p><ul><li>Slightly slower than Trie for pure string lookup.</li><li>Good compromise between speed and scalability.</li></ul><h3>4. B+ Tree: Optimized for Range + Bulk Lookups 🔎</h3><p>Most databases (MySQL, PostgreSQL, etc.) use <strong>B+ Trees</strong> for indexing.</p><ul><li>Unlike B-Trees, <strong>all actual data (usernames) are stored in leaf nodes</strong>.</li><li>Internal nodes only store keys for navigation.</li><li>Leaf nodes are <strong>linked</strong>, making range scans (e.g., “suggest usernames starting with john”) very efficient.</li></ul><p><strong>Why it’s powerful:</strong></p><ul><li>Fast exact lookups (O(log N)), perfect for “Is this username taken?”</li><li>Excellent for <strong>suggestions/autocomplete</strong>.</li><li>Disk-friendly and cache-optimised.</li></ul><h3>5. How Big Tech Combines Them ⚡</h3><p>A typical username availability check might look like this:</p><ol><li><strong>Cache layer (Trie in Redis)</strong></li></ol><ul><li>Hot usernames, recent lookups, autocomplete suggestions.</li><li>Super-fast, in-memory string traversal.</li></ul><p><strong>2. Database index (B+ Tree)</strong></p><ul><li>Full persistence of billions of usernames.</li><li>Disk-optimised, handles cold lookups.</li></ul><p><strong>3. Hybrid checks</strong></p><ul><li>Trie catches 90% of queries instantly.</li><li>Fallback to database (B+ Tree) for uncached lookups.</li><li>Background sync keeps cache + DataBase consistent.</li></ul><p>This layered approach ensures <strong>sub-millisecond availability checks</strong>, even at the scale of Big Tech.</p><h3>6. Key Takeaways 📝</h3><ul><li><strong>Trie</strong> = Blazing fast string lookup in memory.</li><li><strong>B-Tree</strong> = General-purpose balanced index on disk.</li><li><strong>B+ Tree</strong> = Optimised for databases, exact + range queries.</li><li>Together, they allow platforms to check your username instantly — even if there are <strong>billions of records</strong>.</li></ul><p>So the next time you see “❌ Username already taken,” remember: a clever mix of <strong>tries, B-trees, and B+ trees</strong> just worked in milliseconds to tell you that.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ffdac12797f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>