<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: niyati nehal</title>
    <description>The latest articles on DEV Community by niyati nehal (@niyati_nehal).</description>
    <link>https://dev.to/niyati_nehal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4132583%2Fab3c10c8-9584-4f6f-8ebf-76059357a795.png</url>
      <title>DEV Community: niyati nehal</title>
      <link>https://dev.to/niyati_nehal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/niyati_nehal"/>
    <language>en</language>
    <item>
      <title>So... What Actually Happens Inside the Database?</title>
      <dc:creator>niyati nehal</dc:creator>
      <pubDate>Wed, 30 Sep 2026 11:20:35 +0000</pubDate>
      <link>https://dev.to/niyati_nehal/so-what-actually-happens-inside-the-database-4j32</link>
      <guid>https://dev.to/niyati_nehal/so-what-actually-happens-inside-the-database-4j32</guid>
      <description>&lt;p&gt;In my last article, I was trying to figure out how to approach a system design problem without immediately jumping into technologies.&lt;/p&gt;

&lt;p&gt;The conclusion I came to was pretty simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I shouldn't start by asking “Should I use PostgreSQL or MongoDB?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I should first understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What data does the system need?&lt;/li&gt;
&lt;li&gt;How will I access it?&lt;/li&gt;
&lt;li&gt;How often will I access it?&lt;/li&gt;
&lt;li&gt;What happens when multiple things happen at the same time?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That sounded great.&lt;/p&gt;

&lt;p&gt;Until I actually started learning database design.&lt;/p&gt;

&lt;p&gt;Because then I realised I didn't really understand what the database was doing in the first place.&lt;/p&gt;

&lt;p&gt;I knew how to write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what happens after I run that?&lt;/p&gt;

&lt;p&gt;And why should I care about indexes, transactions, or isolation levels when I'm designing a system?&lt;/p&gt;

&lt;p&gt;So that's what I started with.&lt;/p&gt;




&lt;h2&gt;
  
  
  Let's start with one query
&lt;/h2&gt;

&lt;p&gt;Imagine our system has an &lt;code&gt;orders&lt;/code&gt; table.&lt;/p&gt;

&lt;p&gt;Maybe it looks something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;orders

id
user_id
amount
status
created_at
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And a user opens their order history.&lt;/p&gt;

&lt;p&gt;The application asks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;But now imagine the database has 10 rows.&lt;/p&gt;

&lt;p&gt;No problem.&lt;/p&gt;

&lt;p&gt;Now imagine it has 100 million.&lt;/p&gt;

&lt;p&gt;The database can't just scan every row every time someone asks for their orders.&lt;/p&gt;

&lt;p&gt;So I started asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How does the database find the rows it actually needs?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that's where indexes come in.&lt;/p&gt;




&lt;h2&gt;
  
  
  An index is basically an answer to a question
&lt;/h2&gt;

&lt;p&gt;Instead of thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“A database has indexes.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I find it easier to think:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I'm repeatedly looking for data in a particular way. Can I build something that makes that lookup faster?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, if I frequently search orders by &lt;code&gt;user_id&lt;/code&gt;, an index on &lt;code&gt;user_id&lt;/code&gt; can help the database find those rows without scanning the entire table.&lt;/p&gt;

&lt;p&gt;But there was one thing I initially misunderstood.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You usually aren't implementing these indexes yourself.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're using something like PostgreSQL, the database already provides index types such as B-tree and Hash indexes and handles the underlying data structures for you.&lt;/p&gt;

&lt;p&gt;You might write something as simple as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_orders_user_id&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PostgreSQL takes care of the actual index structure and maintaining it as data changes.&lt;/p&gt;

&lt;p&gt;So as a system designer, I'm generally not sitting there implementing a B-tree from scratch.&lt;/p&gt;

&lt;p&gt;My job is more like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What queries are going to happen frequently, and what indexes would help those queries?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that distinction matters.&lt;/p&gt;

&lt;p&gt;Because the system design problem isn't:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How do I build a B-tree?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“This is how my application accesses the data. How should the database support that access pattern?”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  But then I found out there isn't just “an index”
&lt;/h2&gt;

&lt;p&gt;This is where it got confusing again.&lt;/p&gt;

&lt;p&gt;There are things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hash indexes&lt;/li&gt;
&lt;li&gt;B-Trees&lt;/li&gt;
&lt;li&gt;LSM Trees&lt;/li&gt;
&lt;li&gt;SSTables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At first, this felt like another list I was supposed to memorise.&lt;/p&gt;

&lt;p&gt;But I kept coming back to the same question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Why do we need different ways of indexing data?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Different structures are useful for different workloads and access patterns.&lt;/p&gt;

&lt;p&gt;If I'm doing an exact lookup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user_id = 123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;that's different from something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;created_at &amp;gt; yesterday
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where ordering and range queries matter.&lt;/p&gt;

&lt;p&gt;And systems designed around heavy writes have different concerns again.&lt;/p&gt;

&lt;p&gt;The important part for me isn't:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hash → B-Tree → LSM → memorise.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What kind of reads and writes does this system need to handle?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And then:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What data structure or database feature supports that workload?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The database handles a lot of the implementation details for me.&lt;/p&gt;

&lt;p&gt;I still need to understand what it's doing, though, because those details affect the decisions I make later.&lt;/p&gt;




&lt;h1&gt;
  
  
  Then I got to writes
&lt;/h1&gt;

&lt;p&gt;Reading data was one thing.&lt;/p&gt;

&lt;p&gt;Writing data made things more interesting.&lt;/p&gt;

&lt;p&gt;Let's say a user places an order.&lt;/p&gt;

&lt;p&gt;Maybe the system needs to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create order
      ↓
Reduce inventory
      ↓
Create payment record
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now imagine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create order       ✓
Reduce inventory   ✓
Create payment     ✗
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We now have a problem.&lt;/p&gt;

&lt;p&gt;The system has partially completed something that, from the user's perspective, should have been one operation.&lt;/p&gt;

&lt;p&gt;I could technically write three separate database operations.&lt;/p&gt;

&lt;p&gt;But what I actually need is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Either all of these changes happen, or none of them do.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that is where transactions started making more sense to me.&lt;/p&gt;

&lt;p&gt;Instead of memorising:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“ACID = Atomicity, Consistency, Isolation, Durability.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I can start with the actual problem:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;I have multiple changes that need to behave like one logical operation.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's a much easier reason to remember why transactions exist.&lt;/p&gt;




&lt;h1&gt;
  
  
  But what if two requests happen at the same time?
&lt;/h1&gt;

&lt;p&gt;This was the part that made isolation finally click for me.&lt;/p&gt;

&lt;p&gt;Imagine a bank account has:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;₹1,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two withdrawal requests arrive at almost exactly the same time.&lt;/p&gt;

&lt;p&gt;Both want to withdraw:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;₹800
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If both requests read:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Balance = ₹1,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;before either one updates it, both might conclude:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“There is enough money.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And now the system has allowed something that shouldn't have happened.&lt;/p&gt;

&lt;p&gt;So the problem isn't just:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Can I read and write data?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What happens when multiple transactions are reading and writing the same data at the same time?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's where isolation comes in.&lt;/p&gt;




&lt;h1&gt;
  
  
  Isolation is about concurrent transactions
&lt;/h1&gt;

&lt;p&gt;I started learning about things like:&lt;/p&gt;

&lt;h3&gt;
  
  
  Read Committed
&lt;/h3&gt;

&lt;p&gt;A transaction shouldn't see data that another transaction hasn't committed yet.&lt;/p&gt;

&lt;p&gt;That sounds straightforward.&lt;/p&gt;

&lt;p&gt;Until you ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What if I read the same thing twice?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Can another transaction change it between those two reads?&lt;/p&gt;

&lt;p&gt;Then there is:&lt;/p&gt;

&lt;h3&gt;
  
  
  Snapshot Isolation
&lt;/h3&gt;

&lt;p&gt;Instead of seeing every change happening around you, a transaction can work with a consistent view of the data.&lt;/p&gt;

&lt;p&gt;That solves some problems.&lt;/p&gt;

&lt;p&gt;But again, not everything.&lt;/p&gt;

&lt;p&gt;Then you start running into things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write skew&lt;/li&gt;
&lt;li&gt;Phantom writes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And honestly, this is where database concepts stopped feeling like random terminology.&lt;/p&gt;

&lt;p&gt;They're all answering variations of the same question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What should happen when multiple things are happening at the same time?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  And this brings me back to system design
&lt;/h1&gt;

&lt;p&gt;This is probably the connection I was missing before.&lt;/p&gt;

&lt;p&gt;In my previous article, I said that when designing the database, I should ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What are the important queries?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now I understand that this isn't just about drawing a table.&lt;/p&gt;

&lt;p&gt;The query tells me something about how the data needs to be accessed.&lt;/p&gt;

&lt;p&gt;And that can lead to a decision like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“This column is queried constantly, so maybe it needs an index.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I also said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Do we need transactions?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now I have a better idea of what that question is actually asking.&lt;/p&gt;

&lt;p&gt;And when I ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What happens under concurrency?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I'm not asking some theoretical database question.&lt;/p&gt;

&lt;p&gt;I'm asking what happens when real users send requests at the same time.&lt;/p&gt;

&lt;p&gt;So my database questions are becoming more specific:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What data do we store?
        ↓
How do we read it?
        ↓
What access patterns do we have?
        ↓
Do we need indexes?
        ↓
How do we write the data?
        ↓
Do multiple writes need to succeed together?
        ↓
What happens when transactions run concurrently?
        ↓
What consistency/isolation do we need?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's actually starting to feel like system design.&lt;/p&gt;




&lt;h1&gt;
  
  
  I think this is the pattern I'm looking for
&lt;/h1&gt;

&lt;p&gt;One thing I'm noticing while learning all of this is that every concept becomes easier when I stop asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What is this?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and start asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“What problem made someone need this?”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Why do indexes exist?&lt;/p&gt;

&lt;p&gt;Because searching through everything gets expensive.&lt;/p&gt;

&lt;p&gt;Why do different index structures exist?&lt;/p&gt;

&lt;p&gt;Because different workloads have different access patterns.&lt;/p&gt;

&lt;p&gt;Why do transactions exist?&lt;/p&gt;

&lt;p&gt;Because multiple changes sometimes need to behave like one operation.&lt;/p&gt;

&lt;p&gt;Why do isolation levels exist?&lt;/p&gt;

&lt;p&gt;Because transactions can happen concurrently and interfere with each other.&lt;/p&gt;

&lt;p&gt;And this is exactly the way I want to continue learning system design.&lt;/p&gt;

&lt;p&gt;Not:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Learn PostgreSQL.&lt;br&gt;&lt;br&gt;
Learn Redis.&lt;br&gt;&lt;br&gt;
Learn Kafka.&lt;br&gt;&lt;br&gt;
Memorise when to use each.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What problem am I facing?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;What changes because of that problem?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;What design decision follows from it?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's the part I was trying to figure out in the first article.&lt;/p&gt;

&lt;p&gt;I think I'm finally starting to see how the pieces connect.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Everyone Says “Clarify the Requirements” in System Design. But How?</title>
      <dc:creator>niyati nehal</dc:creator>
      <pubDate>Wed, 30 Sep 2026 10:44:21 +0000</pubDate>
      <link>https://dev.to/niyati_nehal/everyone-says-clarify-the-requirements-in-system-design-but-how-30bb</link>
      <guid>https://dev.to/niyati_nehal/everyone-says-clarify-the-requirements-in-system-design-but-how-30bb</guid>
      <description>&lt;p&gt;You all might have watched a lot of YouTube videos on system design and heard almost every one of them say:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Before you start designing, clarify the functional and non-functional requirements.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And yes, obviously.&lt;br&gt;
You’re supposed to clarify the requirements.&lt;br&gt;
But how do you actually do that?&lt;br&gt;
What exactly do you ask the interviewer?&lt;br&gt;
How do you know whether the question you’re asking is useful?&lt;/p&gt;

&lt;p&gt;How do you go from:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Design a URL shortener”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;to actually knowing what you’re supposed to build?&lt;br&gt;
I think this is one of those things that sounds very obvious when someone explains it after the fact, but when you’re actually sitting in an interview, it’s much harder.&lt;/p&gt;

&lt;p&gt;So I wanted to break down the five things we usually hear about:&lt;/p&gt;

&lt;p&gt;1-Functional and non-functional requirements&lt;br&gt;
2-API design&lt;br&gt;
3-High-level design|&lt;br&gt;
4-Database design&lt;br&gt;
5-Detailed design&lt;/p&gt;

&lt;p&gt;But not as a checklist.&lt;/p&gt;

&lt;p&gt;More importantly, how do you arrive at each of these? What questions do you ask, and why?&lt;br&gt;
First: Don’t Start Designing&lt;/p&gt;

&lt;p&gt;The interviewer says:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Design a URL shortener.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;My brain might immediately go:&lt;br&gt;
“Okay, Redis, database, load balancer…”&lt;/p&gt;

&lt;p&gt;But wait.&lt;br&gt;
I don’t even know what I’m designing yet.&lt;br&gt;
The problem statement is intentionally vague.&lt;br&gt;
So the first thing I’m actually trying to do is:&lt;br&gt;
remove ambiguity.&lt;/p&gt;

&lt;p&gt;I want to turn:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Design a URL shortener”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;into something more like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“We’re building a URL-shortening service for authenticated users, supporting URL creation and redirection, with X traffic, Y latency requirements, and Z availability requirements.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now I have something I can actually design.&lt;br&gt;
And this is where those five things come in.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Functional Requirements: What Does the User Actually Need to Do?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The usual advice is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Clarify the functional requirements.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Okay.&lt;br&gt;
But I don’t want to ask the interviewer:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What are the functional requirements?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That’s technically correct, but it doesn’t really help me think.&lt;br&gt;
I’d rather start with:&lt;br&gt;
Who is using the system?&lt;/p&gt;

&lt;p&gt;For a URL shortener:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Are users authenticated, or can anyone create a short URL anonymously?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That one question already changes things.&lt;br&gt;
If users are authenticated, I might need:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user accounts
ownership
authorization
URL management
user-specific limits
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If it’s anonymous, a lot of that disappears.&lt;br&gt;
So I’m not asking questions just to collect information.&lt;br&gt;
I’m asking:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What information could actually change my design?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then ask: What can the user actually do?&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Is the requirement only to create and redirect short URLs, or do we also need expiration, custom aliases, analytics, deletion, etc.?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Because “URL shortener” could mean a very simple service.&lt;br&gt;
Or it could mean:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create URLs
delete URLs
custom aliases
expiration
analytics
user dashboard
authentication
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I need to know where the boundary is.&lt;br&gt;
And this applies to every system.&lt;br&gt;
If someone says:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Design Instagram.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That could mean the entire Instagram product.&lt;br&gt;
Obviously we’re not designing all of Instagram in an interview.&lt;br&gt;
So I need to establish the scope.&lt;br&gt;
Find the Main User Journey&lt;/p&gt;

&lt;p&gt;Once I know the scope, I want to understand the most important thing the user is trying to do.&lt;/p&gt;

&lt;p&gt;For a URL shortener:&lt;/p&gt;

&lt;p&gt;User&lt;br&gt;
 ↓&lt;br&gt;
Submits long URL&lt;br&gt;
 ↓&lt;br&gt;
System generates short code&lt;br&gt;
 ↓&lt;br&gt;
User gets short URL&lt;br&gt;
 ↓&lt;br&gt;
Someone opens short URL&lt;br&gt;
 ↓&lt;br&gt;
System finds original URL&lt;br&gt;
 ↓&lt;br&gt;
User is redirected&lt;/p&gt;

&lt;p&gt;That’s the core flow.&lt;br&gt;
Now I have something around which I can start thinking.&lt;br&gt;
And this gives me a useful rule:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Don’t try to understand every possible feature first. Find the primary user journey.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Non-Functional Requirements: How Well Does It Need to Work?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Okay, now I know what the system does.&lt;/p&gt;

&lt;p&gt;The next question is:&lt;br&gt;
How well does it need to do it?&lt;/p&gt;

&lt;p&gt;This is where non-functional requirements come in.&lt;br&gt;
And again, I don’t want to ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What are the NFRs?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I want to ask questions that reveal the constraints.&lt;br&gt;
How much traffic?&lt;br&gt;
Suppose the interviewer says:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“We have millions of users.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Cool.&lt;br&gt;
But that doesn’t tell me much.&lt;br&gt;
Millions of users doesn’t mean millions of requests per second.&lt;br&gt;
So I’d ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“How many daily active users are we expecting?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Approximately how many requests per second?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What’s the read-to-write ratio?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Is that average traffic or peak traffic?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Suppose I get:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1,000 URL creations/sec
100,000 redirects/sec
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now I know something important.&lt;br&gt;
The system is very read-heavy.&lt;br&gt;
That immediately makes things like caching and read scaling relevant.&lt;br&gt;
Notice what happened:&lt;br&gt;
I didn’t decide:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Let’s use Redis.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The traffic requirement led me toward that discussion.&lt;br&gt;
What About Latency?&lt;/p&gt;

&lt;p&gt;Instead of vaguely asking:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What’s the latency requirement?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I can ask something more concrete:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“For the redirect operation, are we okay with something like 100 ms, or do we need it to be closer to tens of milliseconds?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now I can start thinking about what belongs in the critical path.&lt;br&gt;
If something is expensive but doesn’t need to happen before the user receives a response, maybe it can happen asynchronously.&lt;br&gt;
Again:&lt;/p&gt;

&lt;p&gt;Requirement → consequence → architecture.&lt;br&gt;
What Absolutely Needs to Work?&lt;/p&gt;

&lt;p&gt;Availability is another thing I don’t want to treat as a number in isolation.&lt;/p&gt;

&lt;p&gt;I can ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“If the analytics system is temporarily unavailable, should URL redirection still work?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If the interviewer says yes, then I’ve learned something important:&lt;/p&gt;

&lt;p&gt;Redirection is critical. Analytics isn’t.&lt;/p&gt;

&lt;p&gt;So maybe analytics shouldn’t be part of the synchronous redirect path.&lt;br&gt;
Maybe I can process analytics asynchronously.&lt;br&gt;
That’s a much more useful way of thinking about availability than simply memorizing:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“The system should have 99.99% availability.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And Then There’s Consistency&lt;/p&gt;

&lt;p&gt;One question I like here is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What happens if two users temporarily see different values?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Because not everything needs the same consistency guarantees.&lt;br&gt;
A social-media like count being slightly stale might be acceptable.&lt;br&gt;
A bank balance being wrong is a very different problem.&lt;br&gt;
So instead of memorizing:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“This uses eventual consistency and this uses strong consistency.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What happens if the data is temporarily inconsistent?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The answer tells me how strong my consistency requirements actually need to be.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;API Design: Don’t Just Design Endpoints&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that I understand what the system needs to do, I can think about:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How does the outside world interact with it?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Suppose I need to create a short URL.&lt;br&gt;
First ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What does the client need to send?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Probably:&lt;/p&gt;

&lt;p&gt;{&lt;br&gt;
  "url": "&lt;a href="https://example.com" rel="noopener noreferrer"&gt;https://example.com&lt;/a&gt;"&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What does the client need back?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Maybe:&lt;/p&gt;

&lt;p&gt;{&lt;br&gt;
  "shortUrl": "&lt;a href="https://short.ly/abc123" rel="noopener noreferrer"&gt;https://short.ly/abc123&lt;/a&gt;"&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Only now does something like:&lt;/p&gt;

&lt;p&gt;POST /urls&lt;/p&gt;

&lt;p&gt;start making sense.&lt;br&gt;
I’m not inventing the endpoint.&lt;br&gt;
I’m deriving it from the user action.&lt;br&gt;
But Don’t Stop at the Happy Path&lt;/p&gt;

&lt;p&gt;For every important API, I want to ask:&lt;br&gt;
What is the action?&lt;/p&gt;

&lt;p&gt;Create a short URL.&lt;br&gt;
What information does it need?&lt;/p&gt;

&lt;p&gt;The original URL.&lt;br&gt;
What does it return?&lt;/p&gt;

&lt;p&gt;The generated short URL.&lt;br&gt;
What can go wrong?&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Invalid URL
Rate limit
Duplicate request
Service failure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And then one of my favourite questions:&lt;br&gt;
What happens if the client retries?&lt;/p&gt;

&lt;p&gt;Imagine this:&lt;br&gt;
Become a Medium member&lt;/p&gt;

&lt;p&gt;The client sends a request.&lt;br&gt;
The server successfully creates the short URL.&lt;br&gt;
But the response gets lost.&lt;br&gt;
The client doesn’t know whether the request succeeded.&lt;br&gt;
So it sends the request again.&lt;br&gt;
What happens?&lt;br&gt;
Do we create another short URL?&lt;br&gt;
Or do we return the previous result?&lt;br&gt;
Now we’ve naturally arrived at:&lt;/p&gt;

&lt;p&gt;idempotency.&lt;/p&gt;

&lt;p&gt;This is why I don’t think API design should just be:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Let’s design some REST endpoints.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The API is where the system’s behaviour starts becoming explicit.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HLD: Stop Drawing Boxes Just Because You Know Them&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is probably where I’ve seen the most “system design interview diagrams.”&lt;/p&gt;

&lt;p&gt;Something like:&lt;/p&gt;

&lt;p&gt;Client&lt;br&gt;
 ↓&lt;br&gt;
Load Balancer&lt;br&gt;
 ↓&lt;br&gt;
API Gateway&lt;br&gt;
 ↓&lt;br&gt;
Microservices&lt;br&gt;
 ↓&lt;br&gt;
Redis&lt;br&gt;
 ↓&lt;br&gt;
Kafka&lt;br&gt;
 ↓&lt;br&gt;
Database&lt;/p&gt;

&lt;p&gt;And then everyone nods because it looks like a system.&lt;br&gt;
But the interviewer can simply ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Why do you need Kafka?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And suddenly we’re in trouble.&lt;br&gt;
So I’ve started thinking about HLD differently.&lt;br&gt;
Before adding a component, ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What problem does this component solve?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Example: Why would I need a queue?&lt;/p&gt;

&lt;p&gt;Suppose I’m designing a video-sharing platform.&lt;br&gt;
Video processing can take a long time.&lt;br&gt;
I don’t want the user to sit there waiting for:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;transcoding
generating different resolutions
thumbnails
metadata processing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So I might design:&lt;/p&gt;

&lt;p&gt;Upload&lt;br&gt;
 ↓&lt;br&gt;
Object Storage&lt;br&gt;
 ↓&lt;br&gt;
Create Processing Job&lt;br&gt;
 ↓&lt;br&gt;
Queue&lt;br&gt;
 ↓&lt;br&gt;
Workers&lt;br&gt;
 ↓&lt;br&gt;
Processed Videos&lt;/p&gt;

&lt;p&gt;Now the queue has a reason to exist.&lt;br&gt;
It’s not there because:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Kafka is something senior engineers use.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It’s there because:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I have expensive work that doesn’t need to block the user’s request.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That’s the kind of explanation I want to be able to give.&lt;br&gt;
Every Box Should Have a “Why”&lt;/p&gt;

&lt;p&gt;If I draw Redis:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Why?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Because the data is frequently read and can be cached.&lt;br&gt;
If I draw Kafka:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Why?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Because work can happen asynchronously and doesn’t need to block the request.&lt;br&gt;
If I draw a separate service:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Why?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Because it has a separate responsibility, scaling requirement, or failure boundary.&lt;br&gt;
If I can’t explain why a component exists, maybe I shouldn’t have drawn it.&lt;/p&gt;

&lt;p&gt;So my rule here is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Architecture should be the consequence of requirements, not a collection of technologies I remember.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Database Design: Don’t Start With “SQL or NoSQL?”&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is another place where I think it’s easy to jump to the wrong question.&lt;/p&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Should I use PostgreSQL or MongoDB?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Start with:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What information does the system actually need to remember?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For a URL shortener:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;original URL
short code
user
creation time
expiration time
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How do I need to access this information?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Maybe the most important query is:&lt;/p&gt;

&lt;p&gt;shortCode → originalURL&lt;/p&gt;

&lt;p&gt;That’s more useful to me than immediately debating databases.&lt;/p&gt;

&lt;p&gt;Then I can ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How often do we run this query?
How much data will we have?
How quickly will it grow?
What relationships exist?
Do we need transactions?
What consistency do we need?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Only after answering these questions should I start thinking about the storage technology.&lt;br&gt;
So the mental sequence becomes:&lt;/p&gt;

&lt;p&gt;Data → relationships → queries → query frequency → scale → consistency → storage choice&lt;/p&gt;

&lt;p&gt;Not:&lt;/p&gt;

&lt;p&gt;Problem → MongoDB because it’s scalable.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Detailed Design: Where Is the Interesting Problem?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At this point, I should know:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;what we’re building
who uses it
how much traffic we have
what the important APIs are
what the major components are
what data we store
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now I can zoom in.&lt;br&gt;
But I don’t need to explain every single class or function.&lt;br&gt;
Instead, ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What’s the hardest part of this system?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For a URL shortener, maybe it’s:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“How do we generate unique short codes when multiple servers are creating URLs at the same time?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we can go deeper.&lt;/p&gt;

&lt;p&gt;Request&lt;br&gt;
 ↓&lt;br&gt;
Generate unique ID&lt;br&gt;
 ↓&lt;br&gt;
Base62 encoding&lt;br&gt;
 ↓&lt;br&gt;
Short code&lt;br&gt;
 ↓&lt;br&gt;
Store mapping&lt;/p&gt;

&lt;p&gt;And now more questions appear:&lt;br&gt;
What if two servers generate the same ID?&lt;br&gt;
Can IDs be generated independently?&lt;br&gt;
Do we need a centralized ID generator?&lt;br&gt;
What happens if the ID generator goes down?&lt;br&gt;
What happens if two identical requests arrive simultaneously?&lt;br&gt;
Now I’m actually doing detailed system design.&lt;br&gt;
The Most Important Thing: Every Answer Should Create the Next Question&lt;/p&gt;

&lt;p&gt;This is probably the biggest thing I’m taking away from all of this.&lt;/p&gt;

&lt;p&gt;System design shouldn’t feel like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question → answer → next section.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It should feel like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question → answer → consequence → next question → design decision
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;The interviewer says:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“We expect 1 million requests per second.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Are those mostly reads or writes?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;They say:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Mostly reads.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Can the data be cached?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;They say:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Yes, it doesn’t change frequently.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now I think:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Okay, caching can reduce the load on the database.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then I ask:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What happens on a cache miss?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now I’m thinking about the database.&lt;/p&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Can the database handle the remaining traffic?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If not:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Can we use read replicas?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Notice how the architecture is slowly appearing.&lt;br&gt;
I didn’t start with:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Let’s use Redis.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The requirement led me there.&lt;br&gt;
So What Are the Five Things Actually Doing?&lt;/p&gt;

&lt;p&gt;Maybe this is the easiest way for me to remember them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Functional requirements&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What are we building?&lt;br&gt;
Who uses it?&lt;br&gt;
What can they do?&lt;br&gt;
What is the main user journey?&lt;br&gt;
What’s in scope?&lt;br&gt;
What’s out of scope?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Non-functional requirements&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;How well does it need to work?&lt;br&gt;
How much traffic?&lt;br&gt;
How much data?&lt;br&gt;
What latency?&lt;br&gt;
What availability?&lt;br&gt;
What consistency?&lt;br&gt;
What happens during failures?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;API design&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;How does the outside world interact with it?&lt;br&gt;
What does the client send?&lt;br&gt;
What does it receive?&lt;br&gt;
What can go wrong?&lt;br&gt;
What happens on retries?&lt;br&gt;
Is it idempotent?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HLD&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What pieces do I need, and why?&lt;br&gt;
Cache?&lt;br&gt;
Queue?&lt;br&gt;
Database?&lt;br&gt;
Workers?&lt;br&gt;
Services?&lt;br&gt;
Load balancer?&lt;br&gt;
And most importantly:&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Database + detailed design&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;How does the system actually store and process information?&lt;br&gt;
What are the entities?&lt;br&gt;
What are the important queries?&lt;br&gt;
What happens under concurrency?&lt;br&gt;
What happens when something fails?&lt;br&gt;
Where is the bottleneck?&lt;br&gt;
The Question I Want to Keep Beside Me&lt;/p&gt;

&lt;p&gt;I don’t think I need to memorize a giant list of system-design questions.&lt;br&gt;
I just need to keep asking:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What do I need to know before I can make this decision?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I need to choose a database?&lt;br&gt;
First understand the data and access patterns.&lt;br&gt;
I need to add Redis?&lt;br&gt;
First understand whether caching solves an actual problem.&lt;br&gt;
I need Kafka?&lt;br&gt;
First understand whether something should be asynchronous.&lt;br&gt;
I need a read replica?&lt;br&gt;
First understand the read volume and database bottleneck.&lt;br&gt;
I need strong consistency?&lt;br&gt;
First understand what happens if users temporarily see different data.&lt;br&gt;
That’s probably the biggest shift in how I want to approach system design.&lt;br&gt;
Not:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What architecture do I know for this problem?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;But:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What questions do I need to answer so that the architecture becomes obvious?”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And honestly, that’s probably what I should be practicing when I practice system design.&lt;br&gt;
Not drawing more diagrams.&lt;br&gt;
Getting better at asking the next useful question&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
