<?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 Aashna Mahajan on Medium]]></title>
        <description><![CDATA[Stories by Aashna Mahajan on Medium]]></description>
        <link>https://medium.com/@mahajan.aashna?source=rss-6702bc1c0045------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MWTuaILUtl1Z-1RrQxv4yQ.png</url>
            <title>Stories by Aashna Mahajan on Medium</title>
            <link>https://medium.com/@mahajan.aashna?source=rss-6702bc1c0045------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 03:18:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahajan.aashna/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[5 System Design Concepts Every Software Engineer Should Understand Before Interviews]]></title>
            <link>https://medium.com/@mahajan.aashna/5-system-design-concepts-every-software-engineer-should-understand-before-interviews-c7d50cc63856?source=rss-6702bc1c0045------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7d50cc63856</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Aashna Mahajan]]></dc:creator>
            <pubDate>Sun, 24 May 2026 22:37:58 GMT</pubDate>
            <atom:updated>2026-05-31T20:39:33.364Z</atom:updated>
            <content:encoded><![CDATA[<p>I stumbled in my initial system design interviews because I was familiar with the buzzwords, yet I lacked a deep understanding of the crucial trade-offs that lay beneath them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*67x6UltWiS3Eaxhn.png" /></figure><p>I failed three system design interviews in a row.</p><p>Not because I didn’t know the concepts. I knew them. Caching, sharding, consistent hashing, CAP theorem, message queues — I could define every one.</p><p>What I couldn’t do: answer what came next.</p><p><em>“What happens when the cache gets stale?”</em><br><em>“Why are you sharding this?”</em><br><em>“So you’d ignore partition tolerance?”</em></p><p>Every time, I had the surface answer. Every time, the follow-up question exposed that I’d never thought one level deeper.</p><p><em>These are the 5 gaps that cost me.</em></p><h3>1. Everyone Adds a Cache. Almost Nobody Thinks About What Comes Next.</h3><p>I used to say “add Redis” like it was a complete answer.</p><p>Performance problem? Redis. Slow API? Redis. Interviewer asks about read load? Redis.</p><p>Then one interviewer asked, <em>“What happens when the user updates their profile?”</em></p><p>I stared. I knew how to add a cache. I hadn’t thought once about what happens when the data behind it changes.</p><p>That’s the trap. A cache is your phone saving images from apps so it doesn’t re-download them every time—simple, fast, and invisible. In backend systems, <strong>Redis</strong> stores hot data entirely in RAM instead of hitting a database on every request. Think of it as a database that never sleeps. Responses in under a millisecond.</p><p>Most read traffic is for the same hot data—the same user profiles, the same popular posts. A cache catches all of that before the database ever has to wake up.</p><p>Here’s how the cache-aside pattern looks in code—the most common one you’ll see:</p><pre>def get_user(user_id: str):<br>    # Step 1: Check cache first<br>    cached = redis.get(f&quot;user:{user_id}&quot;)<br>    if cached:<br>        return json.loads(cached)        # Cache hit ✓<br><br>    # Step 2: Cache miss — go to the database<br>    user = db.find_one({&quot;_id&quot;: user_id})<br><br>    # Step 3: Store result for next time (expires in 1 hour)<br>    redis.setex(f&quot;user:{user_id}&quot;, ttl=3600, value=json.dumps(user))<br>    return user<br><br># ⚠️ The hidden danger: what if the user updates their profile?<br># If you forget: redis.delete(f&quot;user:{user_id}&quot;)<br># ...they&#39;ll see stale data for up to an hour.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eqMjH_bO7UC1lCKUF2Tb8g.png" /></figure><p><em>Three strategies—each is right in one situation and quietly catastrophic in the wrong one.</em></p><p>I once watched a team spend three days debugging incorrect pricing at checkout. The cache populated correctly on product creation — but silently failed to invalidate when the price <em>changed</em>. Wrong prices were served for six weeks. Code looked fine. Tests passed.</p><p><strong>A cache without an invalidation strategy isn’t a performance win. It’s a time bomb with a clean interface.</strong></p><blockquote><em>💬 </em><strong>Beginner answer:</strong> “Add Redis.”<br><strong>Strong answer: </strong>Add Redis with a clear invalidation strategy — delete the cache key on write, set a TTL as a safety net, and know which pattern (cache-aside, write-through, write-behind) fits your consistency requirements.</blockquote><h3>2. Sharding: Impressive on a Whiteboard, Painful in Production</h3><p>After making the same mistake myself, I later watched another candidate repeat it almost exactly.</p><p>He spent 25 minutes designing a sharding strategy for a system serving 3,000 daily users.</p><p>Custom shard keys. Cross-shard routing. Resharding logic. The interviewer stopped him mid-sentence.</p><p>“Why are you sharding this?”</p><p>He didn’t have an answer. He didn’t get an offer.</p><p><strong>Over-engineering isn’t ambition. It’s anxiety wearing the mask of thoroughness.</strong></p><p>Sharding splits your database across multiple servers—each one owns a slice of the data. It’s genuinely powerful and genuinely hard: joins across shards become painful, transactions need distributed coordination, and debugging requires knowing which shard holds your data.</p><p>The right order before you even think about sharding:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7q3jm9Ec-lrKHoixFyNWFA.png" /></figure><p><em>Exhaust every step before moving to the next. Most systems never need to go past step 2.</em></p><p><a href="https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c">Instagram ran on a single <strong>Postgres</strong> instance</a> far longer than most people realize. They only sharded when simpler options genuinely couldn’t keep up.</p><blockquote><em>💬 </em><strong>Beginner answer:</strong> “Split the data across multiple servers.”<br><strong>Strong answer:</strong> Shard only after exhausting vertical scaling, read replicas, and caching. Choose a shard key based on access patterns — user ID distributes evenly; timestamps create hot shards.</blockquote><h3>3. Why Adding One Server Can Break Your Entire Cache</h3><p>The short answer: naive hashing routes cache keys by key % N. Change N, and almost every key routes to a different server. Your cache goes cold instantly.</p><pre># ❌ Naive modulo — breaks the moment you add a server<br>servers = [&quot;server_1&quot;, &quot;server_2&quot;, &quot;server_3&quot;]<br><br>def get_server(key: str) -&gt; str:<br>    return servers[hash(key) % len(servers)]<br><br>get_server(&quot;user_123&quot;)   # → &quot;server_2&quot;<br><br># You add a 4th server to handle more load...<br>servers.append(&quot;server_4&quot;)<br>get_server(&quot;user_123&quot;)   # → &quot;server_1&quot;  ← different server!<br><br># Almost every key now maps somewhere new.<br># Your entire cache just went cold. Enjoy the database stampede.</pre><p>Adding one server to a cache cluster can invalidate most of your cached data at once—causing every request to hit the database simultaneously. That’s not a scaling win. That’s an outage.</p><p><strong>Consistent hashing</strong> is the fix. Instead, both servers and keys are mapped onto a circular ring. Each key belongs to the nearest server clockwise.</p><p>Add a server? It takes only the keys between itself and its neighbor—roughly 1/N of data. Everything else stays put.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4JokFtC7kgdhvzhfL-STfg.png" /></figure><p><em>Adding one node displaces ~1/N keys. With naive modulo hashing, you’d be moving almost everything.</em></p><p>Akamai was built on this. Their founders <a href="https://dl.acm.org/doi/10.1145/258533.258660">wrote the original paper in 1997</a>, designing consistent hashing specifically to solve the server-addition problem at CDN scale. <a href="https://redis.io/docs/management/scaling/">Redis Cluster</a> and <a href="https://cassandra.apache.org/doc/latest/cassandra/architecture/dynamo.html">Cassandra</a> use the same principle today.</p><blockquote><em>💬 </em><strong>Beginner answer:</strong> “Consistent hashing distributes keys evenly across servers.”<br><strong>Strong answer:</strong> Consistent hashing minimises remapping when the cluster changes — adding a server displaces only ~1/N keys. Naive modulo hashing remaps nearly everything, which turns a scaling win into a cache stampede.</blockquote><p>So far we’ve been talking about scaling reads and distributing data. But distributed systems fail in a second, harder way — not “how do you store more?” but “what happens when the parts of your system stop agreeing with each other?”</p><h3>4. CAP Theorem Is Taught Wrong. Here’s What It Actually Means.</h3><p>I once confidently explained the CAP theorem in an interview. The interviewer looked up and asked:</p><p><em>“So you’d consider building a system that ignores partition tolerance?”</em></p><p>I had nothing. The conversation got uncomfortable fast.</p><p>Here’s the problem: <strong>CAP is almost always taught as “pick any two.” That’s misleading.</strong></p><p>Partition tolerance isn’t optional. Networks fail — servers lose the ability to talk to each other. It will happen to your system. So the real choice is</p><p><strong>When a network partition occurs, do you prioritize consistency or availability?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cEwBbFoLkiJ3d0Vl_qkvAw.png" /></figure><p><a href="https://engineering.fb.com/2022/05/04/core-infra/mysql-raft/">Facebook chose AP for their social graph</a>—a slightly stale follower count beats an app that won’t load. Systems that prioritize CP—like CockroachDB or Postgres with synchronous replication—refuse writes during a partition rather than risk an inconsistent state. You’d rather reject a transaction than double-charge someone.</p><blockquote><em>💬 </em><strong>Beginner answer:</strong> “You can pick any two of consistency, availability, and partition tolerance.”<br><strong>Strong answer:</strong> Partition tolerance isn’t a choice — networks fail. The real decision is CP vs AP: do you return stale data or refuse requests when nodes can’t communicate? Apply it directly: “This is a payments system, so I’d take CP — I’d rather reject a write than risk charging someone twice.”</blockquote><h3>5. Message Queues Don’t Guarantee What You Think They Guarantee</h3><p>Picture a restaurant on a Friday night. Orders are flying in faster than the kitchen can handle. If every waiter walked directly to a chef and demanded immediate attention, the kitchen collapses.</p><p>Instead, orders go on a ticket rail. Chefs work through them steadily. The kitchen stays calm no matter how busy the front gets.</p><p><strong>That’s a message queue.</strong></p><p>Uber’s trip events flow through Kafka. Netflix triggers encoding jobs through queues. Slack’s notification pipeline is async.</p><p>Most candidates in interviews draw a queue, say, “this decouples the services,” and move on. That’s not wrong. But here’s what nobody mentions until they’re paged at 3am:</p><p><strong>In most queue systems, design as if any message can arrive more than once.</strong></p><p>Retries, consumer crashes, and network timeouts can all cause duplicate processing. A user gets charged twice, an email is sent twice, and a report generates twice.</p><pre>def process_payment(message: dict):<br>    payment_id = message[&quot;payment_id&quot;]<br><br>    # ✅ Idempotency check — safe to receive this twice<br>    if db.payment_already_exists(payment_id):<br>        print(f&quot;Already processed {payment_id}. Skipping.&quot;)<br>        return<br><br>    # Process only if we haven&#39;t seen this before<br>    stripe.charge(message[&quot;amount&quot;], message[&quot;card_token&quot;])<br>    db.mark_payment_complete(payment_id)<br><br># Without this: duplicate charge on retry.<br># With this: second delivery is a no-op. ✓</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ud6eahUkHGOxxdrePaYXwQ.png" /></figure><p><em>The queue delivers to one person. Pub/Sub delivers to all. Get this wrong, and you’ll either starve consumers or duplicate work across all of them.</em></p><p>There’s a word for this: <strong>idempotency</strong>. It means the second call does nothing if the first one already worked. <a href="https://stripe.com/docs/api/idempotent_requests">Stripe built it into their payment API from day one</a>. Most queue-related incidents I’ve seen—duplicate charges, double emails, reports generated twice—came down to idempotency missing somewhere in the pipeline.</p><blockquote><em>💬 </em><strong>Beginner answer:</strong> “Add Kafka or SQS to decouple services.”<br><strong>Strong answer:</strong> Add a queue, but design consumers to be idempotent — queues guarantee at-least-once delivery, not exactly-once. Retries will happen; processing the same message twice should produce the same result as processing it once.</blockquote><h3>Quick Reference: Surface Answer vs Strong Answer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZp6dr63cPdJ7tQdoUwmBA.png" /></figure><h3>The Pattern Behind All 5 Mistakes</h3><p>The mistake was never <em>“I didn’t know Redis”</em> or <em>“I didn’t know Kafka.”</em></p><p>The mistake was treating components as answers.</p><p>Every component in a distributed system creates a new problem:</p><ul><li>Caches create <strong>invalidation</strong></li><li>Shards create <strong>routing</strong></li><li>Queues create <strong>retries</strong></li><li>Replicas create <strong>consistency trade-offs</strong></li><li>More servers create <strong>key remapping</strong></li></ul><p>The interview isn’t testing whether you know the component. It’s testing whether you know the consequence.</p><p>That’s the only pattern worth memorising.</p><p><em>Originally published at </em><a href="https://dev.to/aashna_mahajan/i-bombed-my-first-system-design-interviews-these-5-concepts-were-why-4nb3"><em>https://dev.to</em></a><em> on May 24, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7d50cc63856" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>