<?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: Arslan Ahmad</title>
    <description>The latest articles on DEV Community by Arslan Ahmad (@arslan_ah).</description>
    <link>https://dev.to/arslan_ah</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%2F34147%2F2974e0a5-f688-45b5-a4c9-5fa49c257854.jpg</url>
      <title>DEV Community: Arslan Ahmad</title>
      <link>https://dev.to/arslan_ah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arslan_ah"/>
    <language>en</language>
    <item>
      <title>The 2027 System Design Interview Playbook: Framework, Concepts, and a Full Worked Example</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Mon, 02 Nov 2026 13:38:14 +0000</pubDate>
      <link>https://dev.to/arslan_ah/the-2027-system-design-interview-playbook-framework-concepts-and-a-full-worked-example-2mn6</link>
      <guid>https://dev.to/arslan_ah/the-2027-system-design-interview-playbook-framework-concepts-and-a-full-worked-example-2mn6</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A quick note before we start:&lt;/strong&gt; This guide is written by me, Arslan Ahmad. I'm the founder of &lt;a href="https://www.designgurus.io" rel="noopener noreferrer"&gt;DesignGurus.io&lt;/a&gt; and the author of &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt;. Before that, I spent years as a software engineer and hiring manager at Microsoft and Meta, where I sat on the other side of hundreds of these interviews. Where one of our courses or articles goes deeper on a topic, I link it. You can follow everything in this playbook without buying anything.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you're preparing for a system design interview in 2027, you're facing a strange situation. There's more free material than ever, and it has never been harder to know what to study.&lt;/p&gt;

&lt;p&gt;Most guides give you one of three things: a list of concepts with no idea how to use them, a framework with no worked example, or a single example with no reusable method. Candidates come out of those guides knowing what a load balancer is but freezing when an interviewer says "Design Instagram's feed. You have 45 minutes."&lt;/p&gt;

&lt;p&gt;This playbook gives you all three in one place:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A framework&lt;/strong&gt; you can apply to any question, with a minute-by-minute time budget.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The core concepts&lt;/strong&gt; that show up in nearly every interview, explained at the depth interviewers actually probe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A full worked example&lt;/strong&gt; (a news feed), done the way I'd want a strong senior candidate to do it, with real numbers, a data model, deep dives, and failure handling.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's long on purpose. Bookmark it, skim the table of contents, and come back to the sections you need.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR: The 60-Second Version
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The interview tests how you think, not what you've memorized.&lt;/strong&gt; There's no single correct answer. There are defensible trade-offs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use a framework every time:&lt;/strong&gt; clarify requirements → estimate scale → define the API → model the data → high-level design → deep dives → bottlenecks and wrap-up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spend the first ~15 minutes on scope, numbers, API, and data.&lt;/strong&gt; Candidates who skip this end up designing the wrong system very well.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Know ~15 building blocks cold:&lt;/strong&gt; load balancers, caches, CDNs, SQL vs NoSQL, replication, sharding, consistent hashing, queues, rate limiting, idempotency, IDs, CAP/PACELC, consistency models, observability, API styles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every decision should come with a "because."&lt;/strong&gt; "I'll use Cassandra &lt;em&gt;because&lt;/em&gt; the workload is write-heavy, access is by key, and we can tolerate eventual consistency."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Seniority is judged by how you drive the conversation&lt;/strong&gt;, not by how many boxes you draw.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2027 additions:&lt;/strong&gt; expect AI/LLM system questions, more focus on cost and observability, and designing APIs that AI agents (not just humans) will call.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What Is a System Design Interview?&lt;/li&gt;
&lt;li&gt;What's Different About System Design Interviews in 2027&lt;/li&gt;
&lt;li&gt;The Types of System Design Interviews&lt;/li&gt;
&lt;li&gt;How You're Evaluated (and What Changes by Level)&lt;/li&gt;
&lt;li&gt;The 7-Step System Design Interview Framework&lt;/li&gt;
&lt;li&gt;Core Concepts: The System Design Toolkit&lt;/li&gt;
&lt;li&gt;The Trade-offs Interviewers Love to Probe&lt;/li&gt;
&lt;li&gt;Full Worked Example: Design a News Feed&lt;/li&gt;
&lt;li&gt;Bonus: A Template for AI System Design Questions&lt;/li&gt;
&lt;li&gt;The Most Common System Design Interview Questions&lt;/li&gt;
&lt;li&gt;12 Mistakes That Sink Strong Candidates&lt;/li&gt;
&lt;li&gt;An 8-Week Preparation Plan&lt;/li&gt;
&lt;li&gt;Best Resources to Prepare&lt;/li&gt;
&lt;li&gt;FAQ&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What Is a System Design Interview?
&lt;/h2&gt;

&lt;p&gt;A system design interview is a 45 to 60 minute conversation where you design a large-scale software system from a vague prompt. "Design a URL shortener." "Design WhatsApp." "Design a rate limiter." "Design a system that lets 10 million people buy concert tickets at the same moment."&lt;/p&gt;

&lt;p&gt;You'll usually work on a whiteboard or a shared online diagramming tool. The interviewer plays a mix of product manager, tech lead, and skeptical colleague. They answer your questions, push on weak spots, and steer you toward the parts they want to see in depth.&lt;/p&gt;

&lt;p&gt;What it is &lt;strong&gt;not&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Not a trivia quiz.&lt;/strong&gt; Nobody will ask you to recite the Raft paper. They'll ask you &lt;em&gt;why&lt;/em&gt; you need consensus here and what happens if the leader dies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not a test of whether you've built this exact system.&lt;/strong&gt; Very few candidates have built Twitter. Interviewers know that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not a search for the "right" architecture.&lt;/strong&gt; Two candidates can draw very different diagrams and both get a strong hire. What matters is whether your choices fit the requirements and whether you can defend them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What it &lt;strong&gt;is&lt;/strong&gt;: a simulation of a design review. The question behind every question is, &lt;em&gt;"Would I trust this person to lead the design of a real system on my team?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That's why the system design round carries so much weight in leveling decisions. A coding round tells a company whether you can write correct code. A system design round tells them whether you're a mid-level, senior, or staff engineer. If you want the long version of how this round fits into the loop, I wrote about it in &lt;a href="https://www.designgurus.io/blog/system-design-interview-fundamentals" rel="noopener noreferrer"&gt;System Design Interview Fundamentals&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Different About System Design Interviews in 2027
&lt;/h2&gt;

&lt;p&gt;The core of the interview hasn't changed in a decade: requirements, scale, components, trade-offs. But the questions and the bar around them have shifted. Here's what I'm seeing from candidates and hiring managers going into 2027.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. AI system design questions are now mainstream.&lt;/strong&gt; "Design ChatGPT," "Design a RAG-based support bot," and "Design an LLM inference service" have moved from niche ML loops into general backend loops. You don't need to be an ML researcher, but you do need to know how retrieval, vector search, model serving, token streaming, and GPU cost fit into an architecture. I added a template for these below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Your API's clients might be agents, not people.&lt;/strong&gt; More systems now have AI agents calling them in tight loops. That raises the stakes on things that used to be "nice to have": idempotency keys, strict rate limits per key, machine-readable errors, pagination that doesn't break under retries, and clear contracts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Cost is a first-class requirement.&lt;/strong&gt; Interviewers increasingly ask, "What does this cost to run?" A design that needs 4,000 GPUs or petabytes of hot Redis isn't automatically wrong, but you should notice and say so.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Observability and failure modes get more airtime.&lt;/strong&gt; "How would you know it's broken?" and "What happens when the cache cluster dies?" are now standard follow-ups, especially at senior levels.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Interviewers expect you to drive.&lt;/strong&gt; With so much prep material available, the baseline has gone up. Reciting a memorized "Design Twitter" answer stands out less than it used to. Adapting your design to the interviewer's twist stands out more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Some companies now allow AI tools in parts of the loop.&lt;/strong&gt; Policies vary a lot between companies and change often, so ask your recruiter. Even where AI assistance is allowed, the system design round is still mostly about &lt;em&gt;your&lt;/em&gt; judgment: what to build, what to skip, and why.&lt;/p&gt;

&lt;p&gt;None of this changes the fundamentals. If anything, it rewards them more. You can't reason about LLM serving costs if you can't do back-of-the-envelope math.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Types of System Design Interviews
&lt;/h2&gt;

&lt;p&gt;"System design" covers a few different interview formats. Find out which one you're getting, because the prep is different.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Typical prompt&lt;/th&gt;
&lt;th&gt;What they're really testing&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Product / backend design&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Design Instagram, Uber, Dropbox&lt;/td&gt;
&lt;td&gt;End-to-end architecture, data modeling, scaling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Infrastructure design&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Design a rate limiter, key-value store, message queue&lt;/td&gt;
&lt;td&gt;Distributed systems depth, consistency, failure handling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;API design&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Design the API for a payments platform&lt;/td&gt;
&lt;td&gt;Resource modeling, versioning, idempotency, pagination&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Object-oriented / low-level design&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Design a parking lot, elevator system&lt;/td&gt;
&lt;td&gt;Classes, interfaces, design patterns, extensibility&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AI / ML system design&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Design ChatGPT, a recommendation system&lt;/td&gt;
&lt;td&gt;Data pipelines, model serving, evaluation, cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mobile / frontend system design&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Design the Instagram mobile app&lt;/td&gt;
&lt;td&gt;Client architecture, offline sync, caching, rendering&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Most backend and full-stack engineers will see &lt;strong&gt;product design&lt;/strong&gt; and &lt;strong&gt;infrastructure design&lt;/strong&gt;. Meta, for example, has long split its loop into "product architecture" and "system design" flavors. I break down each format in &lt;a href="https://www.designgurus.io/blog/types-of-system-design-interviews" rel="noopener noreferrer"&gt;Types of System Design Interviews: Product, Infrastructure, and More&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This playbook focuses on the product and infrastructure formats, because that's where most people need help. The framework applies to all of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  How You're Evaluated (and What Changes by Level)
&lt;/h2&gt;

&lt;p&gt;Interviewers don't score your diagram. They score signals. Almost every big-tech rubric I've seen boils down to four:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Problem navigation.&lt;/strong&gt; Do you scope the problem before solving it? Do you ask questions that change the design, not questions for the sake of asking?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solution design.&lt;/strong&gt; Do the components fit together into something that would actually work end to end?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technical depth.&lt;/strong&gt; When pushed on a component, do you know &lt;em&gt;why&lt;/em&gt; it works, not just &lt;em&gt;what&lt;/em&gt; it is?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Communication.&lt;/strong&gt; Do you think out loud, check in, and adjust when the interviewer gives you a hint?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The same question is asked to mid-level, senior, and staff candidates. What changes is the bar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxmnhkrwf1y0l8qfhgdqa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxmnhkrwf1y0l8qfhgdqa.png" alt="What system design interviewers evaluate at L4, L5, and L6" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;L4 / mid-level:&lt;/strong&gt; You can produce a working design with reasonable components. The interviewer may guide you through some steps. You discuss a couple of trade-offs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L5 / senior:&lt;/strong&gt; You drive the whole conversation without prompting. You pick the two or three hardest parts of the problem and go deep. You back decisions with numbers and plan for failure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L6 / staff:&lt;/strong&gt; You reframe the problem. You compare multiple architectures before committing. You talk about cost, migration paths, operational burden, and what you'd deliberately &lt;em&gt;not&lt;/em&gt; build in v1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a practical way to tell where you are: record yourself doing a mock interview, then count how many times the interviewer had to redirect you. Senior candidates rarely need it. I wrote about the specific behaviors that separate candidates in &lt;a href="https://www.designgurus.io/blog/sys-design-distinguishes" rel="noopener noreferrer"&gt;7 Tips to Stand Out in Your System Design Interview&lt;/a&gt;, and I list level-appropriate practice questions in &lt;a href="https://dev.to/arslan_ah/system-design-interview-questions-by-level-junior-mid-level-senior-and-staff-2m6h"&gt;System Design Interview Questions by Level&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have never run a timed mock before, this &lt;a href="https://www.designgurus.io/blog/system-design-mock-interview" rel="noopener noreferrer"&gt;guide to system design mock interviews&lt;/a&gt; breaks down what happens minute by minute, how the scorecard works, and which platforms to practice on.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 7-Step System Design Interview Framework
&lt;/h2&gt;

&lt;p&gt;This is the framework I've taught for years in &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt;. It's not magic. It just makes sure you never skip the steps that interviewers grade, and it keeps you from panicking when the prompt is vague.&lt;/p&gt;

&lt;p&gt;For another end-to-end walkthrough of this framework, with the exact signals interviewers score, see &lt;a href="https://arslan-ahmad.medium.com/the-complete-system-design-interview-guide-for-2027-85a1ab94ace7" rel="noopener noreferrer"&gt;The Complete System Design Interview Guide for 2027&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftb2isl26fvp7je7g04b8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftb2isl26fvp7je7g04b8.png" alt="The 7-step system design interview framework with a 45-minute time budget" width="799" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you prefer video, here's my walkthrough of the same 7-step method:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/N3r-Z6_IGTM" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's go through each step: what to do, what to say, and what to avoid.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Clarify Requirements (≈5 minutes)
&lt;/h3&gt;

&lt;p&gt;Every system design prompt is underspecified on purpose. The interviewer wants to see whether you'll charge ahead or figure out what you're building first.&lt;/p&gt;

&lt;p&gt;Split requirements into two lists and write both on the board.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functional requirements&lt;/strong&gt; are what the system does. Aim for 3 to 5 core features, and explicitly park the rest.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"For a news feed, I'm thinking the core features are: users can create posts with text and images, follow other users, and see a feed of posts from people they follow. I'll leave out comments, likes, ads, and search for now unless you'd like me to include them. Does that work?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Non-functional requirements&lt;/strong&gt; are how well it does it. These drive the architecture far more than the features do. Ask about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scale:&lt;/strong&gt; How many users? Daily active users? Read-heavy or write-heavy?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency:&lt;/strong&gt; What's acceptable for the critical path? (For a feed: p99 under ~200 ms.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Availability vs consistency:&lt;/strong&gt; Is it OK if a post takes a few seconds to appear for followers? (Usually yes.) Is it OK if a payment is double-charged? (Never.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Durability:&lt;/strong&gt; Can we ever lose data? (Posts: no. View counts: maybe.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Other constraints:&lt;/strong&gt; Global or single region? Mobile clients with bad networks? Compliance needs?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Avoid:&lt;/strong&gt; asking 15 questions in a row. Ask the ones whose answers change the design, propose sensible defaults for the rest, and move on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Back-of-the-Envelope Estimation (≈3–5 minutes)
&lt;/h3&gt;

&lt;p&gt;Estimation turns "it should scale" into "we need roughly this much." Its job is to tell you which parts of the system are hard. A design serving 100 QPS and a design serving 1 million QPS look very different.&lt;/p&gt;

&lt;p&gt;Estimate four things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Traffic:&lt;/strong&gt; reads and writes per second, average and peak.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage:&lt;/strong&gt; per day, per year, and total.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bandwidth:&lt;/strong&gt; bytes in and out per second, mostly relevant for media.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory:&lt;/strong&gt; what you'd need to cache the hot set.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trick is to round aggressively. A day has 86,400 seconds; call it 100,000 (10⁵). So 1 million requests/day ≈ 10 per second, and 1 billion/day ≈ 10,000 per second. Interviewers want the order of magnitude and your reasoning, not decimals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7ybi2lra1qnv4iye7qpx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7ybi2lra1qnv4iye7qpx.png" alt="Back-of-the-envelope estimation cheat sheet: latency numbers, traffic math, availability nines, and typical sizes" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Avoid:&lt;/strong&gt; spending 10 minutes on math the design doesn't use. Every number you compute should lead to a decision ("~35K peak read QPS, so we need a cache in front of the database").&lt;/p&gt;

&lt;p&gt;For a step-by-step method with practice problems, read &lt;a href="https://www.designgurus.io/blog/back-of-the-envelope-system-design-interview" rel="noopener noreferrer"&gt;Back-of-the-Envelope Estimation for System Design Interviews&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Define the API (≈3–5 minutes)
&lt;/h3&gt;

&lt;p&gt;The API is the contract between your system and the world. Writing it down forces you and the interviewer to agree on exactly what the system does.&lt;/p&gt;

&lt;p&gt;Keep it to the 3 to 5 endpoints that match your functional requirements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /v1/posts              { text, media_ids[], idempotency_key }  -&amp;gt; 201 { post_id }
GET  /v1/feed?cursor=&amp;amp;limit=20                                       -&amp;gt; 200 { items[], next_cursor }
POST /v1/users/{id}/follow                                           -&amp;gt; 204
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Things worth mentioning briefly, because they show maturity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pagination:&lt;/strong&gt; cursor-based, not offset-based, for anything that changes in real time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idempotency keys&lt;/strong&gt; on writes, so a retried request doesn't create a duplicate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auth and rate limiting&lt;/strong&gt; at the gateway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API style:&lt;/strong&gt; REST is the default for public APIs, gRPC is common between internal services, and GraphQL fits client-driven aggregation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4: Model the Data (≈3–5 minutes)
&lt;/h3&gt;

&lt;p&gt;List the core entities, their key fields, and, most importantly, &lt;strong&gt;the access patterns&lt;/strong&gt;. Your database choice should follow from how data is read and written, not from what's fashionable.&lt;/p&gt;

&lt;p&gt;Questions to answer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are the main entities and relationships?&lt;/li&gt;
&lt;li&gt;What are the top 2–3 queries? (e.g., "get the latest 20 posts for user X's feed")&lt;/li&gt;
&lt;li&gt;Do we need transactions across entities, or mostly single-key reads and writes?&lt;/li&gt;
&lt;li&gt;How will this be partitioned once it no longer fits on one machine?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A good habit: say out loud which database you'd pick &lt;strong&gt;and why&lt;/strong&gt;, in one sentence. "Follows are a simple many-to-many relationship queried by user ID in both directions. A sharded relational store with two tables, one keyed by follower and one by followee, handles that well."&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: High-Level Design (≈8–10 minutes)
&lt;/h3&gt;

&lt;p&gt;Now draw the boxes. Start with the simplest design that satisfies the functional requirements end to end, then evolve it to meet the non-functional ones.&lt;/p&gt;

&lt;p&gt;A reliable approach:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Draw the client, the entry point (load balancer / API gateway), and the services that handle each API.&lt;/li&gt;
&lt;li&gt;Add the data stores from Step 4.&lt;/li&gt;
&lt;li&gt;Walk through &lt;strong&gt;one write request&lt;/strong&gt; and &lt;strong&gt;one read request&lt;/strong&gt; end to end, out loud.&lt;/li&gt;
&lt;li&gt;Add caches, queues, CDNs, and replicas only where your numbers from Step 2 say you need them.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Avoid:&lt;/strong&gt; drawing 25 boxes before explaining any of them. Five well-explained boxes beat twenty-five vague ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Deep Dives (≈10–12 minutes)
&lt;/h3&gt;

&lt;p&gt;This is where most hiring decisions are made. Pick the two or three components that are hardest &lt;em&gt;for this specific problem&lt;/em&gt; and go deep. Often the interviewer will steer you; at senior levels, they want to see you pick.&lt;/p&gt;

&lt;p&gt;How to find the hard parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where does the scale from Step 2 concentrate? (A hot key? A huge fan-out?)&lt;/li&gt;
&lt;li&gt;Where do consistency requirements bite? (Payments, inventory, bookings.)&lt;/li&gt;
&lt;li&gt;What's unique to this problem? (Geospatial search for Uber, fan-out for feeds, contention for ticketing.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For each deep dive, present &lt;strong&gt;two or three options, compare them, then commit&lt;/strong&gt;. That pattern alone separates many senior candidates from mid-level ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7: Bottlenecks, Failures, and Wrap-up (≈5 minutes)
&lt;/h3&gt;

&lt;p&gt;Finish by stress-testing your own design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single points of failure:&lt;/strong&gt; what happens if each box dies?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bottlenecks:&lt;/strong&gt; which component saturates first as traffic grows 10×?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hot spots:&lt;/strong&gt; celebrity users, viral content, popular keys.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Observability:&lt;/strong&gt; what would you monitor and alert on?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What's next:&lt;/strong&gt; what would you add with more time?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzewlje4aas4haxhv65l7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzewlje4aas4haxhv65l7.png" alt="How bottlenecks limit system throughput: a 2,000 RPS database caps the whole pipeline" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That last image captures the key point: a system is only as fast as its slowest stage. Scaling your app servers from 8,000 to 80,000 RPS does nothing if the database tops out at 2,000.&lt;/p&gt;

&lt;p&gt;Want the full step-by-step breakdown with examples for each step? See &lt;a href="https://www.designgurus.io/blog/step-by-step-guide" rel="noopener noreferrer"&gt;System Design Interview Guide – 7 Steps to Ace It&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Concepts: The System Design Toolkit
&lt;/h2&gt;

&lt;p&gt;You don't need to know everything about distributed systems. You need a toolkit of roughly 15 concepts that you understand well enough to (a) know when to use each one and (b) answer two levels of "why?" about it.&lt;/p&gt;

&lt;p&gt;Here's how they fit together in a typical web system:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl4e5i4gyrehupn52qp54.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl4e5i4gyrehupn52qp54.png" alt="Anatomy of a scalable web system: clients, CDN, load balancer, API gateway, app services, cache, databases, queue, and workers" width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Scalability: Vertical vs Horizontal
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vertical scaling&lt;/strong&gt; (scale up) means a bigger machine. It's simple and there are no distributed-system headaches, but there's a ceiling and a single point of failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Horizontal scaling&lt;/strong&gt; (scale out) means more machines. There's effectively no ceiling, but now you need load balancing, data partitioning, and a plan for partial failure.&lt;/p&gt;

&lt;p&gt;The interview move: keep your application servers &lt;strong&gt;stateless&lt;/strong&gt; (sessions in a shared store like Redis, files in object storage) so you can scale them horizontally behind a load balancer. Then focus your energy on the stateful parts, which are almost always the hard parts.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Load Balancing
&lt;/h3&gt;

&lt;p&gt;A load balancer spreads requests across servers and routes around unhealthy ones.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;L4 (transport layer)&lt;/strong&gt; balances TCP/UDP connections. It's fast and doesn't look at content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L7 (application layer)&lt;/strong&gt; looks at HTTP paths, headers, and cookies, so it can route &lt;code&gt;/api/video&lt;/code&gt; differently from &lt;code&gt;/api/chat&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Algorithms:&lt;/strong&gt; round robin, least connections, weighted, and consistent hashing (when you want the same user or key to hit the same server, e.g., for local caches).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mention &lt;strong&gt;health checks&lt;/strong&gt;, and that the load balancer itself must be redundant (active-passive pairs or a managed cloud LB), or it becomes your single point of failure.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Caching
&lt;/h3&gt;

&lt;p&gt;Caching is the highest-leverage tool in system design. Reading from memory is roughly 1,000× faster than a disk-backed database query. A good cache can absorb 90%+ of read traffic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffz4rl31p7in0nhgj12kc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffz4rl31p7in0nhgj12kc.png" alt="Caching strategies: cache-aside, write-through, and write-back compared" width="799" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Know where caches live (client, CDN, application-level like Redis, database buffer cache) and the main write policies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cache-aside&lt;/strong&gt; (lazy loading): the default. App checks cache, falls back to DB on a miss, then populates the cache.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write-through:&lt;/strong&gt; writes go through the cache to the DB, so the cache is never stale for written keys.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write-back:&lt;/strong&gt; writes go only to the cache and are flushed later. Fastest, but you can lose data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then be ready for the follow-ups: How do you invalidate? (TTL plus explicit delete on write.) What's the eviction policy? (Usually LRU.) What happens when a hot key expires and 10,000 requests hit the database at once? (A cache stampede; fix it with request coalescing, jittered TTLs, or proactive refresh.)&lt;/p&gt;

&lt;p&gt;Redis comes up in almost every interview, so know its data structures, not just "key → value." Sorted sets (leaderboards, feeds), hashes (objects), and streams (event logs) solve a lot of design problems on their own.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyeza7okg1pgniu7ssglk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyeza7okg1pgniu7ssglk.png" alt="Redis in-memory data structures: strings, lists, sets, sorted sets, hashes, and streams" width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Content Delivery Networks (CDNs)
&lt;/h3&gt;

&lt;p&gt;A CDN caches static content (images, video, JS, CSS) at edge locations close to users. It cuts latency for global users and offloads huge amounts of bandwidth from your origin.&lt;/p&gt;

&lt;p&gt;Use a CDN for anything large and read-heavy: profile pictures, video segments, thumbnails. Mention &lt;strong&gt;cache keys and versioned URLs&lt;/strong&gt; (e.g., &lt;code&gt;avatar_v3.jpg&lt;/code&gt;) so updates don't serve stale content. A cross-continent round trip is ~150 ms, while a CDN edge is often a few milliseconds away.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Databases: SQL vs NoSQL
&lt;/h3&gt;

&lt;p&gt;This is one of the most-asked trade-offs. Don't answer with "NoSQL scales better." Answer with access patterns.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Relational (PostgreSQL, MySQL)&lt;/th&gt;
&lt;th&gt;NoSQL (Cassandra, DynamoDB, MongoDB)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Schema&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Fixed, enforced&lt;/td&gt;
&lt;td&gt;Flexible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Transactions&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Full ACID across rows and tables&lt;/td&gt;
&lt;td&gt;Usually single-item or limited&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Queries&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Joins, ad-hoc queries&lt;/td&gt;
&lt;td&gt;Optimized for known access patterns&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scaling writes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Harder; needs manual sharding&lt;/td&gt;
&lt;td&gt;Built-in partitioning&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Best for&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Payments, orders, inventory, anything relational&lt;/td&gt;
&lt;td&gt;High-volume key-based access, time series, feeds&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A strong answer sounds like: "Orders need multi-row transactions and strong consistency, so PostgreSQL. The activity log is append-heavy, read by user ID and time range, and can be eventually consistent, so Cassandra."&lt;/p&gt;

&lt;p&gt;Also know the specialized stores: &lt;strong&gt;object storage&lt;/strong&gt; (S3) for blobs, &lt;strong&gt;search indexes&lt;/strong&gt; (Elasticsearch/OpenSearch) for full-text search, &lt;strong&gt;time-series databases&lt;/strong&gt; for metrics, &lt;strong&gt;graph databases&lt;/strong&gt; for deep relationship queries, and &lt;strong&gt;vector databases&lt;/strong&gt; for embeddings in AI systems.&lt;/p&gt;

&lt;p&gt;For the deeper comparison, see &lt;a href="https://www.designgurus.io/blog/sql-vs-nosql-key-differences" rel="noopener noreferrer"&gt;SQL vs. NoSQL: Key Differences&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Indexing
&lt;/h3&gt;

&lt;p&gt;An index makes reads fast at the cost of slower writes and extra storage. B-tree indexes handle range queries; hash indexes handle exact matches. LSM-tree storage engines (Cassandra, RocksDB) make writes cheap by appending and compacting later.&lt;/p&gt;

&lt;p&gt;The interview-relevant point: &lt;strong&gt;design your indexes around your queries.&lt;/strong&gt; If your top query is "posts by user, newest first," you want a composite index (or a partition + clustering key) on &lt;code&gt;(author_id, created_at DESC)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Replication
&lt;/h3&gt;

&lt;p&gt;Replication keeps copies of data on multiple machines for availability, durability, and read scaling.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Leader–follower (primary–replica):&lt;/strong&gt; one node takes writes, replicas serve reads. Simple, but replicas can lag (stale reads), and failover needs care.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-leader:&lt;/strong&gt; multiple nodes accept writes (e.g., one per region). Good for geo-distribution, but you have to resolve write conflicts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leaderless (Dynamo-style):&lt;/strong&gt; any replica accepts writes; reads and writes use quorums (e.g., with N=3, W=2, R=2, so R + W &amp;gt; N guarantees overlap).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Know &lt;strong&gt;synchronous vs asynchronous&lt;/strong&gt; replication: synchronous is safer but slower; asynchronous is faster but can lose the latest writes on failover.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Sharding (Partitioning) and Consistent Hashing
&lt;/h3&gt;

&lt;p&gt;When data or write traffic outgrows one machine, you split it across many. The hard part is picking the &lt;strong&gt;shard key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpejqcaxpcry2wy48f7t5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpejqcaxpcry2wy48f7t5.png" alt="Database sharding with consistent hashing, virtual nodes, and shard key selection" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Range-based:&lt;/strong&gt; easy range scans, but risk of hot spots (all new data hits the last shard).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hash-based:&lt;/strong&gt; even distribution, but range queries become scatter-gather.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Directory-based:&lt;/strong&gt; a lookup service maps keys to shards. Flexible, but it's another component to keep available.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Consistent hashing&lt;/strong&gt; solves the "add a server and everything moves" problem. With &lt;code&gt;hash(key) % N&lt;/code&gt;, going from 4 to 5 servers remaps about 80% of keys. On a hash ring, only about 1/N of keys move. Virtual nodes smooth out the distribution further. This shows up in caches, Dynamo-style databases, and load balancers. If you want a dedicated walkthrough, I wrote &lt;a href="https://dev.to/arslan_ah/how-to-use-consistent-hashing-in-a-system-design-interview-33ge"&gt;How to Use Consistent Hashing in a System Design Interview&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Always mention &lt;strong&gt;hot keys&lt;/strong&gt;: a celebrity's user ID or a viral post can overload one shard no matter how good your hash function is.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. CAP and PACELC
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;CAP:&lt;/strong&gt; when a network partition happens, a distributed system must choose between &lt;strong&gt;consistency&lt;/strong&gt; (every read sees the latest write, or gets an error) and &lt;strong&gt;availability&lt;/strong&gt; (every request gets a response, possibly stale). You can't skip partitions in a real network, so "CA" isn't a real option for a distributed system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PACELC&lt;/strong&gt; extends this: &lt;strong&gt;if&lt;/strong&gt; there's a Partition, choose Availability or Consistency; &lt;strong&gt;else&lt;/strong&gt; (normal operation), choose Latency or Consistency. This is the more useful framing, because your system spends most of its time &lt;em&gt;not&lt;/em&gt; partitioned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fot462qkuuahac36e4n3q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fot462qkuuahac36e4n3q.png" alt="CAP theorem and PACELC trade-offs explained for system design interviews" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The senior move is to choose &lt;strong&gt;per feature, not per system&lt;/strong&gt;. A social app's feed can be AP/EL; the payments for promoted posts in the same app must be CP/EC.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Consistency Models
&lt;/h3&gt;

&lt;p&gt;Between "strong" and "eventual" there's a useful middle ground, and naming it precisely is a strong signal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Strong (linearizable):&lt;/strong&gt; every read sees the latest write. Expensive, especially across regions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Eventual:&lt;/strong&gt; replicas converge if writes stop. Cheap and highly available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read-your-writes:&lt;/strong&gt; a user always sees their own updates (e.g., your own post shows up in your feed immediately), even if others see it a moment later.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monotonic reads:&lt;/strong&gt; a user never sees data go "back in time" between requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Causal:&lt;/strong&gt; if A caused B (a reply to a comment), everyone sees A before B.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read-your-writes is the one that saves you in most product designs. Users tolerate others being a few seconds behind; they don't tolerate their own action disappearing. More on this in &lt;a href="https://www.designgurus.io/blog/consistency-patterns-distributed-systems" rel="noopener noreferrer"&gt;Consistency Patterns in Distributed Systems&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  11. Message Queues and Event-Driven Architecture
&lt;/h3&gt;

&lt;p&gt;Queues decouple producers from consumers. A service publishes an event, and any number of consumers process it at their own pace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq001zkwexfj7d9vobil5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq001zkwexfj7d9vobil5.png" alt="Event-driven architecture: an Order Service publishes an Order Placed event to an event bus consumed by inventory, fulfillment, notification, analytics, and fraud services" width="799" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why they matter in interviews:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Absorb spikes:&lt;/strong&gt; the queue buffers bursts that would otherwise overwhelm downstream services.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async work:&lt;/strong&gt; send emails, resize images, update search indexes without blocking the user's request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fan-out:&lt;/strong&gt; one "OrderPlaced" event feeds inventory, fulfillment, notifications, analytics, and fraud, as in the diagram above.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Know the difference between a &lt;strong&gt;queue&lt;/strong&gt; (SQS, RabbitMQ: each message is processed by one consumer, then deleted) and a &lt;strong&gt;log/stream&lt;/strong&gt; (Kafka, Kinesis: messages are retained and can be replayed by many consumer groups). Know &lt;strong&gt;delivery semantics&lt;/strong&gt;: at-most-once, at-least-once (the common default), and "effectively once" via idempotent consumers. And know &lt;strong&gt;back pressure&lt;/strong&gt;: what happens when consumers can't keep up.&lt;/p&gt;

&lt;h3&gt;
  
  
  12. Rate Limiting
&lt;/h3&gt;

&lt;p&gt;Rate limiting protects your system from abuse, runaway clients, and (increasingly) runaway AI agents. Common algorithms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Token bucket:&lt;/strong&gt; allows bursts up to the bucket size, then a steady rate. The most common choice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leaky bucket:&lt;/strong&gt; smooths output to a constant rate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixed window counter:&lt;/strong&gt; simple, but allows bursts at window edges.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sliding window log/counter:&lt;/strong&gt; more accurate, a bit more expensive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In a distributed setup, counters usually live in Redis with atomic operations (or a Lua script). Rate limiting is also a classic standalone interview question; I walk through it in &lt;a href="https://dev.to/arslan_ah/grokking-the-system-design-interview-how-to-design-a-rate-limiter-step-by-step-5g25"&gt;How to Design a Rate Limiter (Step by Step)&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  13. Idempotency and Retries
&lt;/h3&gt;

&lt;p&gt;Networks fail, clients retry, and at-least-once queues redeliver. Any operation that can be retried must be safe to repeat.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have clients send an &lt;strong&gt;idempotency key&lt;/strong&gt; with each write; the server stores the key and the result, and returns the stored result for repeats.&lt;/li&gt;
&lt;li&gt;Make consumers idempotent (e.g., "set status to SHIPPED" instead of "increment shipped count").&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;exponential backoff with jitter&lt;/strong&gt; on retries, so a recovering service isn't flattened by a synchronized retry storm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In any design involving money, orders, or bookings, bring this up before the interviewer does.&lt;/p&gt;

&lt;h3&gt;
  
  
  14. Unique ID Generation
&lt;/h3&gt;

&lt;p&gt;Auto-increment IDs don't work across shards. Common options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;UUIDv4:&lt;/strong&gt; no coordination, but 128 bits, random, and not sortable (bad for B-tree index locality).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UUIDv7 / ULID:&lt;/strong&gt; time-ordered, sortable, and no coordination needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Snowflake-style IDs:&lt;/strong&gt; 64-bit = timestamp + machine ID + sequence. Compact and roughly time-sorted, which makes them perfect as cursors for feeds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  15. Observability and Reliability
&lt;/h3&gt;

&lt;p&gt;You can't operate what you can't see. Mention:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Metrics:&lt;/strong&gt; the four golden signals (latency, traffic, errors, saturation), plus business metrics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logs and distributed tracing:&lt;/strong&gt; to follow one request across many services.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SLOs:&lt;/strong&gt; e.g., "99.9% of feed requests under 200 ms." Error budgets tell you when to slow down releases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resilience patterns:&lt;/strong&gt; timeouts, retries with backoff, circuit breakers, bulkheads, graceful degradation (serve a stale feed rather than an error page).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are 60+ named patterns in this space. I collected them, with when to use each, in &lt;a href="https://www.designgurus.io/blog/system-design-patterns-complete-guide" rel="noopener noreferrer"&gt;System Design Patterns: The Complete Guide&lt;/a&gt;. For a one-page version of this whole toolkit, there's also the &lt;a href="https://www.designgurus.io/blog/system-design-cheat-sheet" rel="noopener noreferrer"&gt;System Design Cheat Sheet&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Where to learn these properly:&lt;/strong&gt; If several of these concepts are new to you, start with &lt;a href="https://www.designgurus.io/course/grokking-system-design-fundamentals" rel="noopener noreferrer"&gt;Grokking System Design Fundamentals&lt;/a&gt;. It covers each building block from scratch. If you know the basics but struggle to &lt;em&gt;apply&lt;/em&gt; them under pressure (when to shard, what to cache, how to survive failures), &lt;a href="https://www.designgurus.io/course/grokking-scalable-systems-for-interviews" rel="noopener noreferrer"&gt;Grokking Scalable Systems for Interviews&lt;/a&gt; treats caching, sharding, replication, and fault tolerance as design decisions rather than definitions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Trade-offs Interviewers Love to Probe
&lt;/h2&gt;

&lt;p&gt;System design is the art of choosing what to give up. Here are the trade-offs that come up most often, with a one-line rule of thumb for each.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Trade-off&lt;/th&gt;
&lt;th&gt;Lean toward the first when…&lt;/th&gt;
&lt;th&gt;Lean toward the second when…&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Consistency vs availability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Money, inventory, bookings&lt;/td&gt;
&lt;td&gt;Feeds, likes, view counts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Latency vs throughput&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;User-facing requests&lt;/td&gt;
&lt;td&gt;Batch jobs, analytics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;SQL vs NoSQL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Relationships, transactions&lt;/td&gt;
&lt;td&gt;Massive scale, simple key access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Push vs pull&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Readers far outnumber writers&lt;/td&gt;
&lt;td&gt;Writers with huge audiences&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sync vs async&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The user needs the result now&lt;/td&gt;
&lt;td&gt;The work can happen later&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cache-aside vs write-through&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Read-heavy, staleness OK&lt;/td&gt;
&lt;td&gt;Must read your own writes from cache&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Monolith vs microservices&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Small team, early product&lt;/td&gt;
&lt;td&gt;Many teams, independent scaling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Strong vs eventual consistency&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Correctness is critical&lt;/td&gt;
&lt;td&gt;Scale and latency matter more&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Batch vs stream processing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Daily reports, ML training&lt;/td&gt;
&lt;td&gt;Fraud detection, live dashboards&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Normalize vs denormalize&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Write-heavy, integrity matters&lt;/td&gt;
&lt;td&gt;Read-heavy, joins are too slow&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The phrase that signals seniority: &lt;strong&gt;"It depends on X. Given our requirement of Y, I'd choose Z, and the cost is W."&lt;/strong&gt; For a deeper treatment of how to reason through these in the room, see &lt;a href="https://www.designgurus.io/blog/complex-system-design-tradeoffs" rel="noopener noreferrer"&gt;System Design Trade-Offs: How to Navigate Them Like a Senior Engineer&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full Worked Example: Design a News Feed
&lt;/h2&gt;

&lt;p&gt;Let's put everything together. I'll walk through "Design a news feed" (think Instagram, Facebook, or X/Twitter home timeline) exactly as I'd want a strong senior candidate to do it in 45 minutes. I'll also mark where an L4, L5, and L6 answer would differ.&lt;/p&gt;

&lt;p&gt;I picked the news feed because it touches almost every concept above: caching, sharding, queues, fan-out, hot keys, consistency, and ranking. If you can do this one well, you can adapt it to Twitter timelines, notification systems, activity feeds, and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Requirements
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Functional (in scope):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Users can create posts (text + optional images/video).&lt;/li&gt;
&lt;li&gt;Users can follow/unfollow other users.&lt;/li&gt;
&lt;li&gt;Users see a home feed of posts from people they follow, newest first (with light ranking later).&lt;/li&gt;
&lt;li&gt;Feed supports infinite scroll.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Out of scope (said out loud):&lt;/strong&gt; comments, likes, ads, search, stories, DMs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-functional:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scale:&lt;/strong&gt; 500M monthly users, 200M daily active users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency:&lt;/strong&gt; feed load p99 &amp;lt; 200 ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Availability:&lt;/strong&gt; high (99.99%). A slightly stale feed is better than an error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency:&lt;/strong&gt; eventual is fine for followers (a few seconds of delay is OK), but &lt;strong&gt;authors must see their own posts immediately&lt;/strong&gt; (read-your-writes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Durability:&lt;/strong&gt; posts must never be lost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read-heavy:&lt;/strong&gt; reads far outnumber writes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 2: Estimation
&lt;/h3&gt;

&lt;p&gt;Assumptions (state them, then compute):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;200M DAU, each opens the feed &lt;strong&gt;5 times/day&lt;/strong&gt; → &lt;strong&gt;1B feed reads/day&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;10% of DAU post once a day → &lt;strong&gt;20M new posts/day&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Average user has &lt;strong&gt;~200 followers&lt;/strong&gt;; a small number of accounts have millions.&lt;/li&gt;
&lt;li&gt;Post metadata ≈ &lt;strong&gt;1 KB&lt;/strong&gt;; 20% of posts include media averaging &lt;strong&gt;~500 KB&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Traffic:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Feed reads: 1B / 10⁵ s ≈ &lt;strong&gt;~12K QPS&lt;/strong&gt; average, &lt;strong&gt;~35K QPS&lt;/strong&gt; peak (3×).&lt;/li&gt;
&lt;li&gt;Post writes: 20M / 10⁵ ≈ &lt;strong&gt;~230 QPS&lt;/strong&gt; average, &lt;strong&gt;~700 QPS&lt;/strong&gt; peak.&lt;/li&gt;
&lt;li&gt;If we fan out on write: 20M posts × 200 followers = &lt;strong&gt;4B feed inserts/day ≈ 46K/s&lt;/strong&gt; average. This is the number that should make you pause.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Storage:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Post metadata: 20M × 1 KB = &lt;strong&gt;20 GB/day ≈ 7 TB/year&lt;/strong&gt;. Easy.&lt;/li&gt;
&lt;li&gt;Media: 4M × 500 KB = &lt;strong&gt;2 TB/day ≈ 730 TB/year&lt;/strong&gt; → object storage + CDN, not the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Feed cache size:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep the latest &lt;strong&gt;500 post IDs&lt;/strong&gt; per active user. Each entry ≈ 16 bytes (8-byte ID + 8-byte score) → 8 KB/user.&lt;/li&gt;
&lt;li&gt;200M users × 8 KB = &lt;strong&gt;1.6 TB raw&lt;/strong&gt;, maybe &lt;strong&gt;5–8 TB&lt;/strong&gt; with Redis overhead. That's a large but very normal Redis cluster (dozens of nodes). Capping at 200 entries would cut it by more than half.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What the numbers tell us:&lt;/strong&gt; reads dominate, so precomputing feeds is worth it. But the fan-out write volume is large and spiky, so it has to be asynchronous, and celebrity accounts need special handling.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;L4 vs L5:&lt;/strong&gt; An L4 candidate often computes QPS and storage and stops. An L5 candidate notices the 46K/s fan-out number and lets it drive the design.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 3: API
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /v1/posts
  body: { text, media_ids[], idempotency_key }
  -&amp;gt; 201 { post_id, created_at }

GET /v1/feed?cursor={post_id}&amp;amp;limit=20
  -&amp;gt; 200 { items: [ { post_id, author, text, media_urls[], created_at } ], next_cursor }

POST   /v1/users/{user_id}/follow     -&amp;gt; 204
DELETE /v1/users/{user_id}/follow     -&amp;gt; 204

POST /v1/media/upload-url
  -&amp;gt; 200 { media_id, presigned_url }   // client uploads directly to object storage
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Design notes worth saying out loud:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cursor pagination&lt;/strong&gt; using the last post ID. Offset pagination breaks when new posts arrive at the top while you scroll.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idempotency key&lt;/strong&gt; on post creation so a flaky mobile network doesn't create duplicate posts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pre-signed upload URLs&lt;/strong&gt; so large media goes straight to object storage, not through our app servers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4: Data Model
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Store&lt;/th&gt;
&lt;th&gt;Key / schema&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Users&lt;/strong&gt; (relational)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;users(user_id PK, name, avatar_url, follower_count, …)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Small, relational, rarely written&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Follows&lt;/strong&gt; (sharded relational or wide-column)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;following(follower_id, followee_id, created_at)&lt;/code&gt; and &lt;code&gt;followers(followee_id, follower_id, created_at)&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Two copies, one per query direction, each sharded by its first column&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Posts&lt;/strong&gt; (wide-column, e.g., Cassandra)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;posts(post_id PK, author_id, text, media_keys, created_at)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hydration by ID; huge, append-heavy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;User timeline&lt;/strong&gt; (wide-column)&lt;/td&gt;
&lt;td&gt;partition &lt;code&gt;author_id&lt;/code&gt;, clustering &lt;code&gt;post_id DESC&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;"Latest posts by author X," used for celebrity pull and feed rebuilds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Feed cache&lt;/strong&gt; (Redis)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;feed:{user_id}&lt;/code&gt; → sorted set of &lt;code&gt;post_id&lt;/code&gt;, scored by time&lt;/td&gt;
&lt;td&gt;Precomputed home feed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Post cache&lt;/strong&gt; (Redis/Memcached)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;post:{post_id}&lt;/code&gt; → serialized post&lt;/td&gt;
&lt;td&gt;Fast hydration of feed items&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Media&lt;/strong&gt; (object storage + CDN)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;media/{media_id}/{size}.jpg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Blobs don't belong in a database&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Post IDs&lt;/strong&gt; are Snowflake-style 64-bit IDs: time-sortable, unique across shards, and directly usable as feed scores and pagination cursors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: High-Level Design
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi6hiu4mvb3pu13jc89c9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi6hiu4mvb3pu13jc89c9.png" alt="News feed system design: high-level architecture with post service, Kafka, fan-out workers, feed cache, and feed service" width="800" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write path (create a post):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Client uploads media using a pre-signed URL, then calls &lt;code&gt;POST /v1/posts&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;API gateway authenticates and rate-limits the request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Post Service&lt;/strong&gt; generates a post ID, writes to the &lt;strong&gt;Posts DB&lt;/strong&gt; and the author's &lt;strong&gt;user timeline&lt;/strong&gt;, and publishes a &lt;code&gt;PostCreated&lt;/code&gt; event to &lt;strong&gt;Kafka&lt;/strong&gt;. It returns success to the client right away.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fan-out workers&lt;/strong&gt; consume the event, look up the author's followers in the &lt;strong&gt;Social Graph&lt;/strong&gt;, and add the post ID to each follower's &lt;strong&gt;feed cache&lt;/strong&gt; (&lt;code&gt;ZADD feed:{follower} {post_id} {post_id}&lt;/code&gt;), trimming each set to the latest 500 entries.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Read path (load the feed):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Client calls &lt;code&gt;GET /v1/feed&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feed Service&lt;/strong&gt; reads the top N post IDs from &lt;code&gt;feed:{user_id}&lt;/code&gt; (starting after the cursor).&lt;/li&gt;
&lt;li&gt;It merges in recent posts from any &lt;strong&gt;celebrities&lt;/strong&gt; the user follows (more on that below).&lt;/li&gt;
&lt;li&gt;It &lt;strong&gt;hydrates&lt;/strong&gt; IDs into full posts with one multi-get against the &lt;strong&gt;Post Cache&lt;/strong&gt; (falling back to the Posts DB on misses), filters deleted or blocked content, and returns the page with media URLs pointing at the &lt;strong&gt;CDN&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At this point, we have a design that works. Now let's make it survive real traffic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Deep Dives
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Deep Dive 1: Fan-out on Write vs Fan-out on Read
&lt;/h4&gt;

&lt;p&gt;This is the core decision in any feed design, so present all three options.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjwqxvos9hktwt5ppewp7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjwqxvos9hktwt5ppewp7.png" alt="Fan-out on write vs fan-out on read vs hybrid for news feed design" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fan-out on write (push):&lt;/strong&gt; precompute every follower's feed at post time. Reads are a single cache lookup, which is ideal for our 35K peak read QPS. But a user with 50M followers would trigger 50M writes for one post, and much of that work is wasted on followers who won't open the app today.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fan-out on read (pull):&lt;/strong&gt; compute the feed when the user opens the app by fetching recent posts from everyone they follow and merging. Writes are cheap, but each feed load becomes hundreds of queries plus a merge. That's very hard to keep under 200 ms at p99.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hybrid (my choice):&lt;/strong&gt; push for normal accounts and pull for celebrities. If an author has more than a threshold of followers (say ~10K–100K, tuned from real data), the fan-out workers skip them. At read time, the Feed Service fetches recent posts from the handful of celebrities the user follows (from the user timeline table, heavily cached) and merges them in.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two extra optimizations worth mentioning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only fan out to active users.&lt;/strong&gt; Skip followers who haven't logged in for, say, 30 days. When an inactive user returns, rebuild their feed with a one-time pull. This can cut fan-out volume dramatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prioritize fan-out.&lt;/strong&gt; Use separate Kafka topics or priority lanes so a viral post's fan-out doesn't delay everyone else's.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;L5 vs L6:&lt;/strong&gt; An L5 candidate lands on the hybrid approach and explains the threshold. An L6 candidate also talks about how to choose and tune the threshold with data, what the write amplification costs in Redis memory and dollars, and how to migrate an account that crosses the threshold without double-delivering posts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Deep Dive 2: The Feed Read Path and the 200 ms Budget
&lt;/h4&gt;

&lt;p&gt;Let's budget the p99:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gateway + auth: ~10 ms&lt;/li&gt;
&lt;li&gt;Feed cache read (&lt;code&gt;ZREVRANGEBYSCORE&lt;/code&gt;, 20–50 IDs): ~1–2 ms&lt;/li&gt;
&lt;li&gt;Celebrity merge (cached user timelines for ~5–20 celebrities): ~5–10 ms&lt;/li&gt;
&lt;li&gt;Post hydration (one batched multi-get of ~20–50 posts): ~5 ms&lt;/li&gt;
&lt;li&gt;Filtering, light ranking, serialization: ~20–40 ms&lt;/li&gt;
&lt;li&gt;Network to client: varies, but outside our server-side budget&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's comfortably under 200 ms server-side, &lt;em&gt;if&lt;/em&gt; the caches hit. So the real questions are about misses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feed cache miss&lt;/strong&gt; (new or returning user): fall back to a pull-based rebuild, return the first page, and write the rebuilt feed to cache asynchronously.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Post cache miss:&lt;/strong&gt; batch-read from the Posts DB. Keep the post cache hit rate above ~95% by caching recent posts aggressively; most feed reads are for posts less than 48 hours old.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Deep Dive 3: Hot Keys and Celebrities
&lt;/h4&gt;

&lt;p&gt;A viral post from a celebrity means millions of reads for the same &lt;code&gt;post:{id}&lt;/code&gt; key, which all land on a single Redis shard.&lt;/p&gt;

&lt;p&gt;Mitigations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Replicate hot keys&lt;/strong&gt; across several cache nodes (e.g., &lt;code&gt;post:{id}#1&lt;/code&gt; … &lt;code&gt;#8&lt;/code&gt;) and pick one at random on read.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local in-process cache&lt;/strong&gt; (a few seconds TTL) on the Feed Service instances for the hottest posts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Request coalescing:&lt;/strong&gt; if 1,000 requests miss the same key at once, only one goes to the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Deep Dive 4: Consistency and Ordering
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Followers:&lt;/strong&gt; eventual consistency is fine. If fan-out takes 2–5 seconds, nobody notices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Author:&lt;/strong&gt; must see their own post instantly. Fix it by having the Feed Service always merge the author's own last few posts (from the user timeline) into their feed, or by synchronously writing to the author's own feed key before returning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ordering:&lt;/strong&gt; Snowflake IDs give us roughly time-ordered keys across shards. For a chronological feed, that's enough. For a ranked feed, ordering comes from the ranker instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deletes and privacy changes:&lt;/strong&gt; don't try to remove a deleted post from millions of feed caches. Mark it deleted (a tombstone) and filter at hydration time. The same goes for blocks and account deactivations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Deep Dive 5: Ranking (if the Interviewer Asks)
&lt;/h4&gt;

&lt;p&gt;Most real feeds aren't purely chronological. The standard approach is two-stage:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Candidate generation:&lt;/strong&gt; the precomputed feed (plus celebrity posts, plus maybe some recommended content) gives you a few hundred candidates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ranking:&lt;/strong&gt; a model scores each candidate on predicted engagement (likes, comments, dwell time) using features like author affinity, post age, and content type. You return the top 20.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keep features in a low-latency feature store, and keep ranking within your latency budget. If the ranker is slow or down, &lt;strong&gt;fall back to chronological&lt;/strong&gt;. That's graceful degradation, and it's exactly the kind of detail senior interviewers look for.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7: Bottlenecks, Failures, and Monitoring
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What fails&lt;/th&gt;
&lt;th&gt;Impact&lt;/th&gt;
&lt;th&gt;Mitigation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A fan-out worker crashes&lt;/td&gt;
&lt;td&gt;Some feeds update late&lt;/td&gt;
&lt;td&gt;Kafka retains events; another worker resumes from the committed offset. &lt;code&gt;ZADD&lt;/code&gt; is idempotent, so replays are safe.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kafka lag spikes (viral post)&lt;/td&gt;
&lt;td&gt;Fan-out delayed for everyone&lt;/td&gt;
&lt;td&gt;Autoscale consumers on lag; separate topic for high-follower authors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Feed cache node dies&lt;/td&gt;
&lt;td&gt;Those users see cache misses&lt;/td&gt;
&lt;td&gt;Redis replicas with automatic failover; fall back to pull-based rebuild&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Posts DB partition slow&lt;/td&gt;
&lt;td&gt;Hydration misses get slow&lt;/td&gt;
&lt;td&gt;Post cache absorbs most reads; timeouts + serve partial feed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ranking service down&lt;/td&gt;
&lt;td&gt;No ranked feed&lt;/td&gt;
&lt;td&gt;Fall back to chronological order&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Region outage&lt;/td&gt;
&lt;td&gt;Users in that region affected&lt;/td&gt;
&lt;td&gt;Multi-region deployment; route to nearest healthy region; async cross-region replication&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;What I'd monitor:&lt;/strong&gt; feed p50/p99 latency, cache hit ratios (feed and post), Kafka consumer lag, fan-out throughput, error rates per endpoint, and a business metric like "time from post creation to appearing in followers' feeds."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I'd add with more time:&lt;/strong&gt; likes and comments counters (with sharded counters to avoid hot rows), notifications, content moderation, and multi-region active-active.&lt;/p&gt;

&lt;h3&gt;
  
  
  How the Same Answer Looks at L4, L5, and L6
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;L4:&lt;/strong&gt; Gets to a working design with a cache and a database. Mentions fan-out on write. May need hints about celebrities. Solid API and data model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L5:&lt;/strong&gt; Everything above, plus drives the conversation unprompted, uses the fan-out number from estimation to justify the hybrid model, handles hot keys and read-your-writes, and walks through failures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L6:&lt;/strong&gt; Everything above, plus questions the requirements ("Is chronological really what the product wants?"), discusses cost (Redis memory, Kafka throughput), plans how to roll out ranking safely, and is explicit about what to build in v1 versus later.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Want more problems worked through this way?&lt;/strong&gt; &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt; applies this same framework to the classic questions, including &lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/designing-facebooks-newsfeed" rel="noopener noreferrer"&gt;Designing Facebook's Newsfeed&lt;/a&gt;, &lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/designing-twitter" rel="noopener noreferrer"&gt;Designing Twitter&lt;/a&gt;, and &lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/designing-instagram" rel="noopener noreferrer"&gt;Designing Instagram&lt;/a&gt;. If you're targeting L5/L6 roles, &lt;a href="https://www.designgurus.io/course/grokking-system-design-interview-ii" rel="noopener noreferrer"&gt;Grokking the System Design Interview, Volume II&lt;/a&gt; goes deeper into harder problems like payment systems and notification systems, with more advanced trade-offs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Bonus: A Template for AI System Design Questions
&lt;/h2&gt;

&lt;p&gt;Because AI questions are now common in general backend loops, here's a compact template for prompts like "Design a customer support chatbot over our docs" or "Design ChatGPT."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements to clarify:&lt;/strong&gt; Who are the users and what's the volume (requests/day, tokens per request)? Latency target for the first token versus the full response? Accuracy expectations, and is a wrong answer worse than "I don't know"? Data freshness? Privacy and tenant isolation? Budget per request?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The core components:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Ingestion pipeline:&lt;/strong&gt; pull documents, clean them, split them into chunks, and create embeddings. This is batch or streaming work, usually triggered by a queue.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vector store + metadata store:&lt;/strong&gt; store embeddings for semantic search, with filters (tenant, permissions, freshness).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval + reranking:&lt;/strong&gt; hybrid search (vector + keyword), then a reranker to pick the best few chunks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LLM gateway:&lt;/strong&gt; routes to the right model, enforces rate limits and quotas, retries, and falls back to cheaper or alternate models.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generation with streaming:&lt;/strong&gt; stream tokens to the client (SSE or WebSockets) so the user sees the first token quickly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Guardrails:&lt;/strong&gt; input and output filtering, PII redaction, prompt-injection defenses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching:&lt;/strong&gt; exact-match and semantic caching of common questions to cut cost and latency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evaluation + feedback loop:&lt;/strong&gt; offline eval sets, online thumbs up/down, tracing of every request (prompt, retrieved chunks, output).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The numbers that matter:&lt;/strong&gt; tokens per request, tokens per second per GPU, cost per 1K tokens, time to first token, and GPU utilization. A quick estimate like "1M requests/day × 2K tokens = 2B tokens/day" immediately tells you whether to self-host or call a hosted API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The trade-offs to discuss:&lt;/strong&gt; bigger model versus smaller model + better retrieval; latency versus quality (reranking adds tens to hundreds of milliseconds); freshness versus indexing cost; and how to fail safely when retrieval finds nothing.&lt;/p&gt;

&lt;p&gt;I go into these question types in &lt;a href="https://dev.to/arslan_ah/ai-system-design-interview-questions-chatgpt-rag-llm-inference-and-agents-1doi"&gt;AI System Design Interview Questions: ChatGPT, RAG, LLM Inference, and Agents&lt;/a&gt;. For full, structured coverage, &lt;a href="https://www.designgurus.io/course/grokking-the-ai-system-design-interview" rel="noopener noreferrer"&gt;Grokking the AI System Design Interview&lt;/a&gt; covers ML product design, LLM and RAG architectures, and agentic systems, and there's a dedicated walkthrough of &lt;a href="https://www.designgurus.io/course-play/system-design-interview-crash-course/doc/design-chatgpt" rel="noopener noreferrer"&gt;Design ChatGPT&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Most Common System Design Interview Questions
&lt;/h2&gt;

&lt;p&gt;You can't practice every question, but you can practice the patterns behind them. Most questions fall into a handful of families. Master one or two from each and you'll recognize the shape of almost anything you're asked.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern family&lt;/th&gt;
&lt;th&gt;Representative questions&lt;/th&gt;
&lt;th&gt;Key concept tested&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Read-heavy + caching&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.designgurus.io/blog/url-shortening" rel="noopener noreferrer"&gt;URL shortener&lt;/a&gt;, Pastebin, typeahead&lt;/td&gt;
&lt;td&gt;Caching, ID generation, key-value stores&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Feeds + fan-out&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;News feed, Twitter timeline, &lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/designing-instagram" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;Push vs pull, hot keys&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Real-time messaging&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/638c0b65ac93e7ae59a1afe5" rel="noopener noreferrer"&gt;Facebook Messenger&lt;/a&gt;, Slack, presence&lt;/td&gt;
&lt;td&gt;WebSockets, ordering, delivery guarantees&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Media + storage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/638c0b68ac93e7ae59a1b009" rel="noopener noreferrer"&gt;YouTube / Netflix&lt;/a&gt;, Dropbox&lt;/td&gt;
&lt;td&gt;Object storage, CDN, chunked upload, transcoding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Geospatial&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/638c0b75ac93e7ae59a1b081" rel="noopener noreferrer"&gt;Uber backend&lt;/a&gt;, Yelp, food delivery&lt;/td&gt;
&lt;td&gt;Geohash/quadtree, location updates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Contention + correctness&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/designing-ticketmaster" rel="noopener noreferrer"&gt;Ticketmaster&lt;/a&gt;, &lt;a href="https://www.designgurus.io/course-play/grokking-system-design-interview-ii/doc/design-payment-system" rel="noopener noreferrer"&gt;payment system&lt;/a&gt;, flash sales&lt;/td&gt;
&lt;td&gt;Locking, idempotency, strong consistency&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Infrastructure&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.designgurus.io/course-play/grokking-the-system-design-interview/doc/designing-an-api-rate-limiter" rel="noopener noreferrer"&gt;Rate limiter&lt;/a&gt;, key-value store, distributed queue&lt;/td&gt;
&lt;td&gt;Partitioning, replication, consensus&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Async pipelines&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.designgurus.io/course-play/grokking-system-design-interview-ii/doc/designing-a-notification-system" rel="noopener noreferrer"&gt;Notification system&lt;/a&gt;, web crawler, ad click aggregator&lt;/td&gt;
&lt;td&gt;Queues, retries, stream processing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AI systems&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;ChatGPT, RAG chatbot, recommendation feed&lt;/td&gt;
&lt;td&gt;Retrieval, model serving, cost&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For a full list ordered by difficulty, see &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m"&gt;64 System Design Interview Questions, Ranked From Easiest to Hardest&lt;/a&gt;, and for how to approach the most-asked ones, &lt;a href="https://www.designgurus.io/blog/system-design-interview-questions" rel="noopener noreferrer"&gt;Top System Design Interview Questions and How to Tackle Them&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  12 Mistakes That Sink Strong Candidates
&lt;/h2&gt;

&lt;p&gt;I've seen excellent engineers fail system design rounds for reasons that had nothing to do with their ability. These are the most common ones.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Jumping straight into boxes.&lt;/strong&gt; Designing before clarifying requirements is the most common mistake, and interviewers notice it in the first two minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asking questions without proposing answers.&lt;/strong&gt; "How many users?" is fine. "I'll assume 100M DAU, read-heavy, does that sound right?" is better.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Estimation theater.&lt;/strong&gt; Ten minutes of arithmetic that never influences a decision.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Buzzword architecture.&lt;/strong&gt; Kafka, Kubernetes, and microservices everywhere, with no reason given. Every component needs a "because."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Going deep too early.&lt;/strong&gt; Spending 20 minutes on database internals before you have an end-to-end design.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Staying shallow everywhere.&lt;/strong&gt; The opposite problem: a complete diagram with no depth anywhere. Pick two or three areas and go deep.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Presenting one option as the only option.&lt;/strong&gt; Senior candidates compare alternatives before committing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring failure.&lt;/strong&gt; Never asking "what happens when this dies?"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting the data model.&lt;/strong&gt; Many designs fall apart because nobody decided how data is keyed and partitioned.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not listening to hints.&lt;/strong&gt; When the interviewer says "What about users with millions of followers?", that's not small talk. It's the deep dive they want.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Going silent.&lt;/strong&gt; The interviewer can only grade what they hear. Think out loud.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memorizing instead of understanding.&lt;/strong&gt; A memorized answer collapses the moment the interviewer adds a twist ("Now make it work across three regions").&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I cover the misconceptions behind many of these in &lt;a href="https://dev.to/arslan_ah/the-9-things-engineers-get-wrong-about-the-system-design-interview-and-the-185-articles-i-wrote-to-22p1"&gt;The 9 Things Engineers Get Wrong About the System Design Interview&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  An 8-Week Preparation Plan
&lt;/h2&gt;

&lt;p&gt;Here's a realistic plan for a working engineer with about 6 to 8 hours a week. If you already build distributed systems at work, you can compress it to about four weeks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4tozpphc7qfefp897dpe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4tozpphc7qfefp897dpe.png" alt="An 8-week system design interview preparation plan" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Weeks 1–2: Fundamentals.&lt;/strong&gt; Work through the 15 concepts in this guide. For each, make sure you can explain what it is, when to use it, and what it costs. Use the &lt;a href="https://www.designgurus.io/blog/system-design-cheat-sheet" rel="noopener noreferrer"&gt;System Design Cheat Sheet&lt;/a&gt; as a checklist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Weeks 3–4: Framework + classics.&lt;/strong&gt; Practice the 7-step framework on four or five classic problems: URL shortener, rate limiter, news feed, chat, and file storage. Do one estimation drill (about 10 minutes) every day. After each problem, write a one-page summary of the key decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Weeks 5–6: Depth + modern topics.&lt;/strong&gt; Move to harder problems (Ticketmaster, payments, notifications, a distributed key-value store) and modern topics (stream processing, sagas, AI systems). Focus on deep dives and failure handling. If you're preparing for microservices-heavy roles, &lt;a href="https://www.designgurus.io/course/grokking-microservices-for-system-design-interviews" rel="noopener noreferrer"&gt;Grokking Microservices for System Design Interviews&lt;/a&gt; covers when microservices are (and aren't) the right call and how to defend that choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Weeks 7–8: Mocks + polish.&lt;/strong&gt; Do two or three timed mock interviews a week, ideally with someone who has interviewed candidates before. Record yourself. Practice the first five minutes until they're automatic. If you don't have a practice partner, our &lt;a href="https://www.designgurus.io/mock-interviews" rel="noopener noreferrer"&gt;mock interviews&lt;/a&gt; pair you with engineers from big tech companies who give you rubric-based feedback.&lt;/p&gt;

&lt;p&gt;For more detail on timelines by experience level, read &lt;a href="https://www.designgurus.io/blog/how-long-to-prepare-for-system-design-interview" rel="noopener noreferrer"&gt;How Long Does It Take to Prepare for a System Design Interview?&lt;/a&gt;. And if you're starting from zero, &lt;a href="https://dev.to/arslan_ah/how-to-learn-system-design-from-scratch-with-no-distributed-systems-experience-1591"&gt;How to Learn System Design From Scratch&lt;/a&gt; is a good first read.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Resources to Prepare
&lt;/h2&gt;

&lt;p&gt;These are the resources I'd recommend, grouped by where you are in your prep. Full disclosure again: the courses are ours at DesignGurus.io, and I built them for exactly this interview.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Courses&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt;:&lt;/strong&gt; the original course. It teaches the 7-step framework and applies it to the classic questions. Start here if you have an interview coming up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.designgurus.io/course/grokking-system-design-fundamentals" rel="noopener noreferrer"&gt;Grokking System Design Fundamentals&lt;/a&gt;:&lt;/strong&gt; for beginners. Covers scaling, load balancing, caching, databases, and CAP from the ground up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.designgurus.io/course/grokking-scalable-systems-for-interviews" rel="noopener noreferrer"&gt;Grokking Scalable Systems for Interviews&lt;/a&gt;:&lt;/strong&gt; for people who know the definitions but struggle to apply them. Caching, sharding, replication, observability, and fault tolerance as design decisions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.designgurus.io/course/grokking-system-design-interview-ii" rel="noopener noreferrer"&gt;Grokking the System Design Interview, Volume II&lt;/a&gt;:&lt;/strong&gt; for L5/L6 candidates. Harder problems and deeper trade-offs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.designgurus.io/course/grokking-the-ai-system-design-interview" rel="noopener noreferrer"&gt;Grokking the AI System Design Interview&lt;/a&gt;:&lt;/strong&gt; ML products, LLM and RAG architectures, and agentic systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.designgurus.io/course/grokking-microservices-for-system-design-interviews" rel="noopener noreferrer"&gt;Grokking Microservices for System Design Interviews&lt;/a&gt;:&lt;/strong&gt; when microservices are the right call, and how to defend that choice in an interview.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Free articles from the DesignGurus.io blog&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/step-by-step-guide" rel="noopener noreferrer"&gt;System Design Interview Guide – 7 Steps to Ace It&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/back-of-the-envelope-system-design-interview" rel="noopener noreferrer"&gt;Back-of-the-Envelope Estimation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/complex-system-design-tradeoffs" rel="noopener noreferrer"&gt;System Design Trade-Offs: How to Navigate Them Like a Senior Engineer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/consistency-patterns-distributed-systems" rel="noopener noreferrer"&gt;Consistency Patterns in Distributed Systems&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/system-design-patterns-complete-guide" rel="noopener noreferrer"&gt;System Design Patterns: The Complete Guide (60+ Patterns)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/system-design-cheat-sheet" rel="noopener noreferrer"&gt;System Design Cheat Sheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/url-shortening" rel="noopener noreferrer"&gt;How to Design a URL Shortener: A Step-by-Step Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Related guide:&lt;/strong&gt; &lt;a href="https://arslan-ahmad.medium.com/the-complete-system-design-interview-guide-for-2027-85a1ab94ace7" rel="noopener noreferrer"&gt;The Complete System Design Interview Guide for 2027&lt;/a&gt;, my complete write-up of the 2027 interview: the framework, what interviewers score, and a full worked example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Video:&lt;/strong&gt; the &lt;a href="https://www.youtube.com/channel/UCupx1O-omoKq73JS3p6jlvQ" rel="noopener noreferrer"&gt;Design Gurus YouTube channel&lt;/a&gt; has short explainers on caching, Kafka, consistent hashing, idempotency, and more, plus full walkthroughs like &lt;a href="https://www.youtube.com/watch?v=zFXUxjlOCoo" rel="noopener noreferrer"&gt;How to answer any system design interview question&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Books and papers:&lt;/strong&gt; &lt;em&gt;Designing Data-Intensive Applications&lt;/em&gt; by Martin Kleppmann is the best single book on the underlying concepts. The Amazon Dynamo, Google Bigtable, and Google Spanner papers are worth skimming once you know the basics.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How long should I prepare for a system design interview?
&lt;/h3&gt;

&lt;p&gt;Most working engineers need 4 to 8 weeks at 6 to 8 hours a week. If you already work on distributed systems, 2 to 4 weeks of focused practice on the framework and mock interviews is often enough. If you're new to backend systems, plan for 8 to 12 weeks and start with fundamentals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need distributed systems experience to pass?
&lt;/h3&gt;

&lt;p&gt;No. Interviewers test reasoning, not résumé items. Many candidates pass after learning the building blocks and practicing the framework on 10–15 problems. What you can't fake is the ability to explain &lt;em&gt;why&lt;/em&gt; you chose something, so focus on trade-offs, not memorization.&lt;/p&gt;

&lt;h3&gt;
  
  
  Are system design interviews asked for junior and new-grad roles?
&lt;/h3&gt;

&lt;p&gt;Less often, and with a lower bar. Some companies include a lighter design round or an object-oriented design round for new grads. For mid-level (L4) roles and above, expect at least one system design round. For senior and staff roles, it's often the most important round in the loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  What if I don't know a specific technology the interviewer mentions?
&lt;/h3&gt;

&lt;p&gt;Say so, and reason from first principles. "I haven't used Cassandra in production, but if it's a leaderless, partitioned wide-column store, then I'd expect writes to be cheap and cross-partition queries to be expensive, so I'd model the data around the partition key." That's a strong answer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I memorize designs for popular questions?
&lt;/h3&gt;

&lt;p&gt;Memorize patterns, not answers. Know the shape of a feed, a chat system, a rate limiter, and a booking system. Then adapt to the specific requirements you're given. Interviewers often add a twist precisely to see whether you're reciting.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I practice system design on my own?
&lt;/h3&gt;

&lt;p&gt;Pick a question, set a 45-minute timer, and talk through it out loud while drawing (recording yourself helps a lot). Then compare your design with a reference solution and note what you missed. Do at least a few mocks with another person, because handling interruptions and hints is a separate skill.&lt;/p&gt;

&lt;h3&gt;
  
  
  How are AI tools changing the system design interview?
&lt;/h3&gt;

&lt;p&gt;Two ways. First, AI system design questions (RAG, LLM serving, agents) are now common, so learn the basic components and cost math. Second, some companies have started allowing AI assistance in parts of their loops. Rules vary by company, so ask your recruiter. Either way, the judgment calls (what to build, what to trade off, and why) are still yours to make and explain.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's the single most important thing to get right?
&lt;/h3&gt;

&lt;p&gt;The first 15 minutes. Clear requirements, quick estimates, a clean API, and a sensible data model make everything after them easier, and they're the part most candidates rush.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;The system design interview rewards a specific kind of thinking: start from requirements, let numbers guide decisions, keep the design as simple as the problem allows, and be honest about trade-offs. That's also what good engineering looks like on the job, which is why companies keep using this interview.&lt;/p&gt;

&lt;p&gt;If you take one thing from this playbook, make it the framework. Practice it on ten problems, out loud, under a timer. By the tenth, you'll notice that the questions stop feeling like ten different problems and start looking like variations on a few patterns you already know.&lt;/p&gt;

&lt;p&gt;Good luck. If this helped, share it with someone who's preparing, and tell me in the comments which question you'd like me to work through next.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;— Arslan&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>interview</category>
      <category>career</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Grokking the System Design Interview: How to Design a Rate Limiter (Step by Step)</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Tue, 06 Oct 2026 08:09:16 +0000</pubDate>
      <link>https://dev.to/arslan_ah/grokking-the-system-design-interview-how-to-design-a-rate-limiter-step-by-step-5g25</link>
      <guid>https://dev.to/arslan_ah/grokking-the-system-design-interview-how-to-design-a-rate-limiter-step-by-step-5g25</guid>
      <description>&lt;p&gt;"Design a rate limiter."&lt;/p&gt;

&lt;p&gt;It sounds small. It is not.&lt;/p&gt;

&lt;p&gt;This question shows up at Stripe, Google, Amazon, Cloudflare, and almost every company that runs a public API. It is short enough to fit in 45 minutes. But it is deep enough to separate a junior answer from a senior one.&lt;/p&gt;

&lt;p&gt;In this post, I will walk through the problem the way we teach it in Grokking the System Design Interview. Step by step. Requirements first, then estimates, then algorithms, then architecture, then the hard parts. If you are new to this interview format, &lt;a href="https://arslan-ahmad.medium.com/the-complete-system-design-interview-guide-for-2027-85a1ab94ace7" rel="noopener noreferrer"&gt;The Complete System Design Interview Guide for 2027&lt;/a&gt; covers the full framework; this post applies it to one question.&lt;/p&gt;

&lt;p&gt;Let's go.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is a Rate Limiter?
&lt;/h2&gt;

&lt;p&gt;A rate limiter controls how many requests a client can send in a given time window.&lt;/p&gt;

&lt;p&gt;If a user is allowed 100 requests per minute, request number 101 gets rejected. Usually with an HTTP &lt;code&gt;429 Too Many Requests&lt;/code&gt; response.&lt;/p&gt;

&lt;p&gt;Think of it like a nightclub bouncer with a clicker. The club holds 200 people. The bouncer counts everyone who walks in. When the counter hits 200, the next person waits outside. Nobody is being rude. The building just has a limit.&lt;/p&gt;

&lt;p&gt;Rate limiters exist for three main reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Protect your servers.&lt;/strong&gt; One buggy script or one bad actor should not take down the whole service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Control costs.&lt;/strong&gt; If every request hits a paid third-party API, unlimited traffic means an unlimited bill.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep things fair.&lt;/strong&gt; One heavy user should not slow the system down for everyone else.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Clarify the Requirements
&lt;/h2&gt;

&lt;p&gt;Never start drawing boxes right away. Ask questions first. In a real interview, this is where you earn your first points.&lt;/p&gt;

&lt;p&gt;Here are the questions I would ask:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Client-side or server-side?&lt;/strong&gt; Server-side. Client-side limits are easy to bypass.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What do we limit by?&lt;/strong&gt; User ID, IP address, API key, or a mix. Let's support all of them through configurable rules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What scale?&lt;/strong&gt; Think large. Millions of users, a few hundred thousand requests per second at peak.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distributed?&lt;/strong&gt; Yes. Many API servers sit behind a load balancer. The limit must hold across all of them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What happens when a request is throttled?&lt;/strong&gt; Return &lt;code&gt;429&lt;/code&gt; with headers that tell the client when to retry.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hard or soft limit?&lt;/strong&gt; Mostly hard. A tiny overshoot during a race is acceptable if it keeps latency low.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;From those answers, we can write the requirements down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functional requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limit requests per client based on configurable rules (for example, 100 requests per minute per user).&lt;/li&gt;
&lt;li&gt;Return &lt;code&gt;429&lt;/code&gt; when a client exceeds the limit.&lt;/li&gt;
&lt;li&gt;Tell the client its remaining quota through response headers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Non-functional requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Low latency.&lt;/strong&gt; The check sits on every request. It must add only a millisecond or two.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Highly available.&lt;/strong&gt; If the rate limiter breaks, the API should not break with it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accurate enough.&lt;/strong&gt; Small errors are fine. Letting 10x the limit through is not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalable.&lt;/strong&gt; Works across many servers and regions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Back-of-the-Envelope Estimates
&lt;/h2&gt;

&lt;p&gt;Let's keep the math simple.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;10 million daily active users.&lt;/li&gt;
&lt;li&gt;Peak traffic of 200,000 requests per second.&lt;/li&gt;
&lt;li&gt;Each counter needs a key (about 50 bytes) plus a count and a timestamp (about 16 bytes). Call it roughly 100 bytes with overhead.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Memory for 10 million active counters:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;10,000,000 x 100 bytes = 1 GB&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That fits in memory on a single Redis node. But 200,000 checks per second, with a read and a write each, is better spread across a small Redis cluster. That also gives us replication for availability.&lt;/p&gt;

&lt;p&gt;The takeaway: &lt;strong&gt;storage is cheap here. Latency and coordination are the real problems.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Pick a Rate Limiting Algorithm
&lt;/h2&gt;

&lt;p&gt;This is the heart of the interview. There are five classic algorithms. You do not need all of them in detail, but you should know the trade-offs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgcw2l2j55go1y27dupdd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgcw2l2j55go1y27dupdd.png" alt="5 rate limiting algorithms compared: token bucket, leaky bucket, fixed window, sliding window log, sliding window counter" width="800" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Token Bucket
&lt;/h3&gt;

&lt;p&gt;A bucket holds tokens. Tokens refill at a fixed rate. Every request takes one token. No token, no entry.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bucket size = how big a burst you allow.&lt;/li&gt;
&lt;li&gt;Refill rate = your long-term average limit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Simple. Memory efficient. Allows short bursts, which matches real user behavior.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Two parameters to tune.&lt;/p&gt;

&lt;p&gt;This is what Amazon API Gateway and Stripe use. It is the safest default in an interview.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkswaava0r9wo66c0hxdg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkswaava0r9wo66c0hxdg.png" alt="Token bucket flow: refill, check tokens, allow or reject with 429" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Leaky Bucket
&lt;/h3&gt;

&lt;p&gt;Requests enter a queue. The queue drains at a fixed rate, like water leaking from a hole in a bucket. If the queue is full, new requests are dropped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Produces a perfectly smooth output rate.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Bursts of traffic fill the queue with old requests. Recent requests get starved.&lt;/p&gt;

&lt;p&gt;Good for systems that need steady processing, like a payment processor that calls a bank API.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Fixed Window Counter
&lt;/h3&gt;

&lt;p&gt;Split time into fixed windows, like one minute each. Keep one counter per window. Reject when the counter passes the limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Very simple. One counter per user.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; The edge problem. A user can send 100 requests at 12:00:59 and another 100 at 12:01:00. That is 200 requests in two seconds, double the limit.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Sliding Window Log
&lt;/h3&gt;

&lt;p&gt;Store the timestamp of every request. On each new request, drop timestamps older than the window and count what is left.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Perfectly accurate.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Memory heavy. A limit of 1,000 requests per hour means storing up to 1,000 timestamps per user.&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Sliding Window Counter
&lt;/h3&gt;

&lt;p&gt;A hybrid. Keep counters for the current and previous window. Estimate the count with a weighted average.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;estimate = current_count + previous_count x (overlap percentage of previous window)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If we are 30% into the current minute, the previous minute still overlaps by 70%. So with 80 requests last minute and 20 so far this minute:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;20 + 80 x 0.7 = 76&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Smooths out the edge problem. Memory efficient.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; It is an approximation. Cloudflare measured it at about 0.003% error across 400 million requests, which is more than good enough.&lt;/p&gt;
&lt;h3&gt;
  
  
  Quick Comparison
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;th&gt;Accuracy&lt;/th&gt;
&lt;th&gt;Allows bursts&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Token bucket&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Good&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;General API limits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Leaky bucket&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Good&lt;/td&gt;
&lt;td&gt;No (smooths)&lt;/td&gt;
&lt;td&gt;Steady downstream calls&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fixed window&lt;/td&gt;
&lt;td&gt;Very low&lt;/td&gt;
&lt;td&gt;Weak at edges&lt;/td&gt;
&lt;td&gt;Yes, at edges&lt;/td&gt;
&lt;td&gt;Simple, low-stakes limits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sliding window log&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Exact&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Strict, low-volume limits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sliding window counter&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Very good&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;td&gt;High-scale APIs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;What I would say in the interview:&lt;/strong&gt; "I will go with the token bucket as the default because it is cheap, handles bursts, and is used in production by large API providers. If the business needs strict smoothing, I would switch to sliding window counter."&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: High-Level Design
&lt;/h2&gt;

&lt;p&gt;Now we draw boxes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fua1m757ptus9q5n3p0i1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fua1m757ptus9q5n3p0i1.png" alt="Rate limiter high-level design with API gateway, Redis cluster and rules service" width="799" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Client&lt;/strong&gt; sends a request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API Gateway / Rate Limiter middleware&lt;/strong&gt; receives it. This is where the check happens.&lt;/li&gt;
&lt;li&gt;The middleware builds a key, like &lt;code&gt;rate:user:42&lt;/code&gt;, and checks the counter in &lt;strong&gt;Redis&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rules Service&lt;/strong&gt; stores the limits (for example, free tier gets 100 per minute, paid tier gets 1,000). The middleware caches these rules locally and refreshes them every few seconds.&lt;/li&gt;
&lt;li&gt;If the client is under the limit, the request goes to the &lt;strong&gt;API servers&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;If not, the middleware returns &lt;code&gt;429&lt;/code&gt; right away. The backend never sees it.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Where should the rate limiter live?
&lt;/h3&gt;

&lt;p&gt;Three options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inside each service.&lt;/strong&gt; Simple, but every team rebuilds the same logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In the API gateway.&lt;/strong&gt; Central and consistent. This is the common choice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;As a separate service.&lt;/strong&gt; Flexible, but adds a network hop to every request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I would pick the API gateway. If the company already runs a gateway like Kong, Envoy, or AWS API Gateway, rate limiting is a plugin away.&lt;/p&gt;
&lt;h3&gt;
  
  
  Why Redis?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In-memory, so reads and writes take under a millisecond.&lt;/li&gt;
&lt;li&gt;Built-in &lt;code&gt;INCR&lt;/code&gt; and &lt;code&gt;EXPIRE&lt;/code&gt; commands.&lt;/li&gt;
&lt;li&gt;Supports Lua scripts, which run atomically. That matters a lot. More on that next.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Response headers
&lt;/h3&gt;

&lt;p&gt;Be kind to clients. Tell them where they stand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;429&lt;/span&gt; &lt;span class="ne"&gt;Too Many Requests&lt;/span&gt;
&lt;span class="na"&gt;X-RateLimit-Limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;100&lt;/span&gt;
&lt;span class="na"&gt;X-RateLimit-Remaining&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0&lt;/span&gt;
&lt;span class="na"&gt;X-RateLimit-Reset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1696608000&lt;/span&gt;
&lt;span class="na"&gt;Retry-After&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good clients read these headers and back off on their own. That reduces load before the limiter even has to say no.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Deep Dives (Where Senior Candidates Shine)
&lt;/h2&gt;

&lt;p&gt;A basic design gets you to "hire" at the mid level. These deep dives push you toward senior and staff.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Dive 1: Race Conditions
&lt;/h3&gt;

&lt;p&gt;Picture two API servers handling requests from the same user at the same moment.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Server A reads the counter: 99.&lt;/li&gt;
&lt;li&gt;Server B reads the counter: 99.&lt;/li&gt;
&lt;li&gt;Both see "under 100" and allow the request.&lt;/li&gt;
&lt;li&gt;Both write 100.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two requests went through. The counter says one. Do this at scale and limits leak badly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; Make read-check-write a single atomic step. In Redis, use a Lua script. Redis runs each script start to finish without interruption.&lt;/p&gt;

&lt;p&gt;Here is a token bucket in Lua:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- KEYS[1] = bucket key&lt;/span&gt;
&lt;span class="c1"&gt;-- ARGV[1] = capacity, ARGV[2] = refill rate per second, ARGV[3] = now (ms)&lt;/span&gt;
&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;bucket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"HMGET"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s2"&gt;"tokens"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ts"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;
&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;

&lt;span class="c1"&gt;-- refill based on elapsed time&lt;/span&gt;
&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;elapsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;math.max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;
&lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;math.min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;elapsed&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="n"&gt;allowed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"HMSET"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s2"&gt;"tokens"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"EXPIRE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nb"&gt;math.ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;capacity&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;rate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;math.floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One network round trip. No races. No locks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Dive 2: Scaling Redis
&lt;/h3&gt;

&lt;p&gt;One Redis node will not last forever. Shard the keys across a Redis cluster using consistent hashing on the client key. All counters for &lt;code&gt;user:42&lt;/code&gt; land on the same shard, so the Lua script still works.&lt;/p&gt;

&lt;p&gt;Add a replica per shard for failover.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Dive 3: What If Redis Goes Down?
&lt;/h3&gt;

&lt;p&gt;This is a favorite follow-up. You have two choices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fail open.&lt;/strong&gt; Let all requests through. The API stays up, but you lose protection for a while.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fail closed.&lt;/strong&gt; Reject all requests. You stay protected, but your API is effectively down.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For most products, &lt;strong&gt;fail open&lt;/strong&gt; is the right call. A short window without limits hurts less than a full outage. Pair it with a local in-memory fallback limiter on each gateway node, so you still get rough protection.&lt;/p&gt;

&lt;p&gt;For security-critical limits, like login attempts, fail closed may be the safer choice. Say this trade-off out loud. Interviewers love it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Dive 4: Multi-Region
&lt;/h3&gt;

&lt;p&gt;If you run in three regions, a global limit gets tricky. Syncing every counter across regions on every request adds too much latency.&lt;/p&gt;

&lt;p&gt;Common approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local limits per region.&lt;/strong&gt; Split the global limit (for example, 1,000 per minute becomes about 333 per region). Simple, slightly inaccurate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async sync.&lt;/strong&gt; Each region counts locally and syncs totals every second or so. Accepts a small overshoot for much lower latency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most real systems choose eventual consistency here. Perfect global accuracy is rarely worth the cost.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Dive 5: Reducing Load on Redis
&lt;/h3&gt;

&lt;p&gt;At very high traffic, even Redis can become a hot spot. Two tricks help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local pre-check.&lt;/strong&gt; Each gateway keeps a small in-memory counter and only syncs with Redis in batches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hot key handling.&lt;/strong&gt; A single huge customer can overload one shard. Split their key into sub-keys (&lt;code&gt;rate:user:42:0&lt;/code&gt; to &lt;code&gt;rate:user:42:3&lt;/code&gt;) and divide their limit across them.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What Interviewers Actually Look For
&lt;/h2&gt;

&lt;p&gt;Here is how I would grade this question, based on years of running these interviews.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Level&lt;/th&gt;
&lt;th&gt;What a strong answer includes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Junior / Mid&lt;/td&gt;
&lt;td&gt;Clear requirements, one algorithm explained well, gateway plus Redis design&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Senior&lt;/td&gt;
&lt;td&gt;Compares algorithms with trade-offs, solves race conditions, discusses fail open vs fail closed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Staff&lt;/td&gt;
&lt;td&gt;Multi-region strategy, hot keys, rule management, and how clients should react to &lt;code&gt;429&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You do not need every deep dive. Pick two and go deep. Depth beats breadth.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes to Avoid
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Jumping to Redis before asking a single question.&lt;/li&gt;
&lt;li&gt;Explaining five algorithms and never picking one.&lt;/li&gt;
&lt;li&gt;Forgetting the race condition.&lt;/li&gt;
&lt;li&gt;Ignoring what happens when the rate limiter itself fails.&lt;/li&gt;
&lt;li&gt;Storing counters in a relational database. Too slow for a per-request check.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A rate limiter caps how many requests a client can make in a time window.&lt;/li&gt;
&lt;li&gt;Always clarify: what to limit by, scale, distributed or not, hard or soft limits.&lt;/li&gt;
&lt;li&gt;Token bucket is the best default. Sliding window counter is great for high-scale accuracy.&lt;/li&gt;
&lt;li&gt;Put the limiter in the API gateway and store counters in Redis.&lt;/li&gt;
&lt;li&gt;Use Lua scripts to make the check atomic and avoid race conditions.&lt;/li&gt;
&lt;li&gt;Fail open for most APIs. Fail closed for security-critical limits.&lt;/li&gt;
&lt;li&gt;For multiple regions, accept small inaccuracy in exchange for low latency.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What HTTP status code should a rate limiter return?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;429 Too Many Requests&lt;/code&gt;, along with a &lt;code&gt;Retry-After&lt;/code&gt; header that tells the client when to try again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which rate limiting algorithm is best?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
There is no single best one. Token bucket is the most common default because it is simple, cheap, and allows short bursts. Sliding window counter is better when you need smoother limits at scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use Redis instead of a database?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The check runs on every single request. Redis is in-memory and answers in under a millisecond. A disk-based database would add too much latency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the difference between token bucket and leaky bucket?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Token bucket allows bursts up to the bucket size. Leaky bucket smooths everything into a steady output rate, even if requests arrive in bursts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Should the rate limiter fail open or fail closed?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Usually fail open, so a limiter outage does not become an API outage. For login or payment endpoints, failing closed can be safer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How long should I spend on this in a 45-minute interview?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
About 5 minutes on requirements, 5 on estimates, 10 on algorithms, 10 on the high-level design, and the rest on one or two deep dives.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;The rate limiter is a great interview question because it looks easy. The candidates who stand out are the ones who slow down, ask the right questions, and talk openly about trade-offs.&lt;/p&gt;

&lt;p&gt;If you want the full picture of how this round is scored in 2027, from the framework to the level-by-level expectations, read &lt;a href="https://arslan-ahmad.medium.com/the-complete-system-design-interview-guide-for-2027-85a1ab94ace7" rel="noopener noreferrer"&gt;The Complete System Design Interview Guide for 2027&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want more walkthroughs like this one, including URL shorteners, news feeds, and chat systems, they are all covered in &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Which system design question should I break down next? Let me know in the comments.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>interview</category>
      <category>backend</category>
    </item>
    <item>
      <title>LeetCode Patterns: The Complete List of 20 to Master (With Examples)</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Tue, 06 Oct 2026 04:55:28 +0000</pubDate>
      <link>https://dev.to/arslan_ah/leetcode-patterns-the-complete-list-of-20-to-master-with-examples-nff</link>
      <guid>https://dev.to/arslan_ah/leetcode-patterns-the-complete-list-of-20-to-master-with-examples-nff</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The complete list of 20 LeetCode patterns. Each one carries the signal that identifies it in a problem statement, a code template you can reuse, and three practice problems on LeetCode. Pattern problem counts come from LeetCode's own topic tags.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;LeetCode has 4,073 problems. Nobody solves them all, and nobody needs to.&lt;/p&gt;

&lt;p&gt;The questions are generated from a much smaller set of reusable approaches. Learn to recognize those, and a problem you have never seen becomes a variation of one you have. Miss them, and every question feels new, which is why solving hundreds of problems at random produces so little.&lt;/p&gt;

&lt;p&gt;This guide covers all 20 patterns. For each one you get the cue that gives it away, why it works, a short template in Python, and three real LeetCode problems to practice on. The order is by what each pattern returns against LeetCode's actual problem distribution, so the earliest entries are the ones worth learning first.&lt;/p&gt;

&lt;p&gt;You will see these called LeetCode patterns, LC patterns, coding patterns, or DSA patterns. They are the same thing: a reusable approach that pairs an algorithmic technique with the data structure it runs on. A single LeetCode pattern is worth more than a hundred solved problems, because the pattern transfers and the solved problem does not.&lt;/p&gt;

&lt;p&gt;If you want the same 20 as a short reference instead, see the &lt;a href="https://www.designgurus.io/blog/grokking-the-coding-interview-patterns?utm_source=devto" rel="noopener noreferrer"&gt;coding interview patterns catalog&lt;/a&gt;. If you want to train the recognition skill itself rather than read the list, see &lt;a href="https://www.grokkingthecodinginterview.com/blog/leetcode-patterns" rel="noopener noreferrer"&gt;how to read a problem statement and name the pattern&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  All 20 LeetCode Patterns
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Two Pointers&lt;/li&gt;
&lt;li&gt;Sliding Window&lt;/li&gt;
&lt;li&gt;Modified Binary Search&lt;/li&gt;
&lt;li&gt;Tree Depth First Search&lt;/li&gt;
&lt;li&gt;Tree Breadth First Search&lt;/li&gt;
&lt;li&gt;Island (Matrix Traversal)&lt;/li&gt;
&lt;li&gt;0/1 Knapsack (Dynamic Programming)&lt;/li&gt;
&lt;li&gt;Top 'K' Elements&lt;/li&gt;
&lt;li&gt;Backtracking&lt;/li&gt;
&lt;li&gt;Subsets&lt;/li&gt;
&lt;li&gt;Bitwise XOR&lt;/li&gt;
&lt;li&gt;Fast &amp;amp; Slow Pointers&lt;/li&gt;
&lt;li&gt;Merge Intervals&lt;/li&gt;
&lt;li&gt;Monotonic Stack&lt;/li&gt;
&lt;li&gt;Topological Sort&lt;/li&gt;
&lt;li&gt;In-place Reversal of a Linked List&lt;/li&gt;
&lt;li&gt;Two Heaps&lt;/li&gt;
&lt;li&gt;Cyclic Sort&lt;/li&gt;
&lt;li&gt;K-way Merge&lt;/li&gt;
&lt;li&gt;Multi-threaded&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fos2dv7d7x2t9n7q0rh0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fos2dv7d7x2t9n7q0rh0g.png" alt="The 20 LeetCode patterns at a glance" width="800" height="724"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The 20 Patterns at a Glance
&lt;/h2&gt;

&lt;p&gt;Problem counts are LeetCode topic-tag totals, pulled from LeetCode. A few patterns share a tag and two have no dedicated tag, which is noted rather than guessed.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Recognize it by&lt;/th&gt;
&lt;th&gt;Time&lt;/th&gt;
&lt;th&gt;LeetCode problems&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1. Two Pointers
&lt;/td&gt;
&lt;td&gt;sorted input, find a pair or triplet&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;263&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2. Sliding Window
&lt;/td&gt;
&lt;td&gt;longest or shortest contiguous run&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;175&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3. Modified Binary Search
&lt;/td&gt;
&lt;td&gt;sorted or rotated, or a testable answer&lt;/td&gt;
&lt;td&gt;O(log n) time&lt;/td&gt;
&lt;td&gt;356&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4. Tree Depth First Search
&lt;/td&gt;
&lt;td&gt;root-to-leaf path, or a subtree answer&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;349&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5. Tree Breadth First Search
&lt;/td&gt;
&lt;td&gt;levels, or fewest steps&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;260&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6. Island (Matrix Traversal)
&lt;/td&gt;
&lt;td&gt;a grid, count connected regions&lt;/td&gt;
&lt;td&gt;O(m*n) time&lt;/td&gt;
&lt;td&gt;285&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7. 0/1 Knapsack (Dynamic Programming)
&lt;/td&gt;
&lt;td&gt;pick a subset under a capacity&lt;/td&gt;
&lt;td&gt;O(n*C) time&lt;/td&gt;
&lt;td&gt;684&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8. Top 'K' Elements
&lt;/td&gt;
&lt;td&gt;k largest, smallest, or most frequent&lt;/td&gt;
&lt;td&gt;O(n log k) time&lt;/td&gt;
&lt;td&gt;222&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9. Backtracking
&lt;/td&gt;
&lt;td&gt;list every valid configuration&lt;/td&gt;
&lt;td&gt;O(b^d) time&lt;/td&gt;
&lt;td&gt;114&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10. Subsets
&lt;/td&gt;
&lt;td&gt;every combination or power set&lt;/td&gt;
&lt;td&gt;O(n * 2^n) time&lt;/td&gt;
&lt;td&gt;114&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11. Bitwise XOR
&lt;/td&gt;
&lt;td&gt;values pair off, find the odd one out&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;297&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12. Fast &amp;amp; Slow Pointers
&lt;/td&gt;
&lt;td&gt;cycle, middle, or kth from the end&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;263&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13. Merge Intervals
&lt;/td&gt;
&lt;td&gt;ranges or time slots that overlap&lt;/td&gt;
&lt;td&gt;O(n log n) time&lt;/td&gt;
&lt;td&gt;no dedicated tag&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;14. Monotonic Stack
&lt;/td&gt;
&lt;td&gt;next greater or next smaller element&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;76&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;15. Topological Sort
&lt;/td&gt;
&lt;td&gt;prerequisites, ordering, cycle check&lt;/td&gt;
&lt;td&gt;O(V+E) time&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16. In-place Reversal of a Linked List
&lt;/td&gt;
&lt;td&gt;reverse a list without new memory&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;82&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;17. Two Heaps
&lt;/td&gt;
&lt;td&gt;running median, or a split set&lt;/td&gt;
&lt;td&gt;O(log n) insert&lt;/td&gt;
&lt;td&gt;222&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;18. Cyclic Sort
&lt;/td&gt;
&lt;td&gt;a permutation of 1..n&lt;/td&gt;
&lt;td&gt;O(n) time&lt;/td&gt;
&lt;td&gt;no dedicated tag&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;19. K-way Merge
&lt;/td&gt;
&lt;td&gt;k sorted lists to combine&lt;/td&gt;
&lt;td&gt;O(n log k) time&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20. Multi-threaded
&lt;/td&gt;
&lt;td&gt;coordinate or order concurrent work&lt;/td&gt;
&lt;td&gt;depends on the coordination primitive&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  The Most Common LeetCode Patterns
&lt;/h2&gt;

&lt;p&gt;If you only have time for part of this list, the eight most common LeetCode patterns are the first eight above: Two Pointers, Sliding Window, Modified Binary Search, Tree Depth First Search, Tree Breadth First Search, Island (Matrix Traversal), 0/1 Knapsack, and Top 'K' Elements.&lt;/p&gt;

&lt;p&gt;Those eight are also the most important ones to get automatic, because they are the patterns an interviewer is most likely to reach for and the ones whose variations show up across the widest range of questions. Together they account for the large majority of what gets asked in a standard coding loop.&lt;/p&gt;

&lt;p&gt;One warning about reading tag counts straight. Bitwise XOR carries 297 tagged problems, which is more than Sliding Window's 175, but almost all of those are narrow puzzles rather than interview staples. A large tag means the technique is common in the problem set, not that it is common in interviews. The order on this page accounts for that; a raw tag ranking does not.&lt;/p&gt;

&lt;h2&gt;
  
  
  LeetCode Patterns Cheat Sheet: What the Wording Tells You
&lt;/h2&gt;

&lt;p&gt;Pattern recognition is mostly vocabulary. The same phrases appear in problem statements again and again, and each one points at a small number of patterns. Use this as a lookup while you practice, then stop using it once the mapping is automatic.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;If the problem says&lt;/th&gt;
&lt;th&gt;Reach for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;"sorted array" plus "find a pair / triplet"&lt;/td&gt;
&lt;td&gt;Two Pointers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"longest" or "shortest" plus "substring" or "subarray"&lt;/td&gt;
&lt;td&gt;Sliding Window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"at most K" or "exactly K distinct"&lt;/td&gt;
&lt;td&gt;Sliding Window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"rotated sorted array"&lt;/td&gt;
&lt;td&gt;Modified Binary Search&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"minimum / maximum value such that ..."&lt;/td&gt;
&lt;td&gt;Modified Binary Search&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"root-to-leaf" or "path sum"&lt;/td&gt;
&lt;td&gt;Tree Depth First Search&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"level order" or "level by level"&lt;/td&gt;
&lt;td&gt;Tree Breadth First Search&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"shortest number of steps" on a graph or grid&lt;/td&gt;
&lt;td&gt;Tree Breadth First Search&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"grid" plus "connected" or "regions" or "islands"&lt;/td&gt;
&lt;td&gt;Island (Matrix Traversal)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"can you partition" or "reach exactly this total"&lt;/td&gt;
&lt;td&gt;0/1 Knapsack (Dynamic Programming)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"fewest coins" or "ways to make up"&lt;/td&gt;
&lt;td&gt;0/1 Knapsack (Dynamic Programming)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"top K" or "K most frequent" or "K closest"&lt;/td&gt;
&lt;td&gt;Top 'K' Elements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"all permutations" or "all valid boards"&lt;/td&gt;
&lt;td&gt;Backtracking&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"all subsets" or "power set" or "all combinations"&lt;/td&gt;
&lt;td&gt;Subsets&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"every element appears twice except one"&lt;/td&gt;
&lt;td&gt;Bitwise XOR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"cycle", "middle node", or "Nth from the end"&lt;/td&gt;
&lt;td&gt;Fast &amp;amp; Slow Pointers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"intervals", "meetings", or "time slots"&lt;/td&gt;
&lt;td&gt;Merge Intervals&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"next greater" or "next smaller" element&lt;/td&gt;
&lt;td&gt;Monotonic Stack&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"prerequisites", "course order", or "build order"&lt;/td&gt;
&lt;td&gt;Topological Sort&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"reverse the list" with O(1) extra space&lt;/td&gt;
&lt;td&gt;In-place Reversal of a Linked List&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"median" of a stream or a window&lt;/td&gt;
&lt;td&gt;Two Heaps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"numbers from 1 to n" with one missing or duplicated&lt;/td&gt;
&lt;td&gt;Cyclic Sort&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"K sorted lists" or "K sorted arrays"&lt;/td&gt;
&lt;td&gt;K-way Merge&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"threads must run in order"&lt;/td&gt;
&lt;td&gt;Multi-threaded&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two cautions. A problem can carry more than one of these signals, in which case the patterns usually compose rather than compete, such as a sliding window over a monotonic stack. And a phrase is evidence, not proof; confirm against the constraints before you commit to an approach.&lt;/p&gt;

&lt;p&gt;If you want to train this recognition rather than look it up, &lt;a href="https://www.grokkingthecodinginterview.com/blog/leetcode-patterns" rel="noopener noreferrer"&gt;this walkthrough reads a problem statement and names the pattern step by step&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two Pointers
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the input is sorted, or you need a pair, triplet, or subsequence that satisfies a condition.&lt;/p&gt;

&lt;p&gt;Two indices moving toward each other turn an O(n^2) scan of every pair into a single O(n) pass, because a sorted order tells you which pointer to move.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn5giwje193fmzergasz4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn5giwje193fmzergasz4.png" alt="Two Pointers pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;two_sum_sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;          &lt;span class="c1"&gt;# need a bigger sum
&lt;/span&gt;        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;          &lt;span class="c1"&gt;# need a smaller sum
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(1) space. LeetCode tags &lt;strong&gt;263&lt;/strong&gt; problems with &lt;code&gt;two-pointers&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/" rel="noopener noreferrer"&gt;Two Sum II - Input Array Is Sorted&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/3sum/" rel="noopener noreferrer"&gt;3Sum&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/container-with-most-water/" rel="noopener noreferrer"&gt;Container With Most Water&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sliding Window
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the question asks for the longest, shortest, or best contiguous subarray or substring.&lt;/p&gt;

&lt;p&gt;The window expands to include new elements and contracts to restore the constraint, so each element is visited at most twice instead of being re-scanned for every start index.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5zs61jhytwpv2eh711wg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5zs61jhytwpv2eh711wg.png" alt="Sliding Window pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;longest_unique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;best&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;      &lt;span class="c1"&gt;# contract past the duplicate
&lt;/span&gt;        &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;
        &lt;span class="n"&gt;best&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;best&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;best&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(k) space. LeetCode tags &lt;strong&gt;175&lt;/strong&gt; problems with &lt;code&gt;sliding-window&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/longest-substring-without-repeating-characters/" rel="noopener noreferrer"&gt;Longest Substring Without Repeating Characters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/minimum-window-substring/" rel="noopener noreferrer"&gt;Minimum Window Substring&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/maximum-average-subarray-i/" rel="noopener noreferrer"&gt;Maximum Average Subarray I&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Modified Binary Search
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the input is sorted or rotated, or the answer itself is a number you can test for feasibility.&lt;/p&gt;

&lt;p&gt;Any question where a candidate answer can be checked in O(n) becomes O(n log n) by binary searching the answer space rather than the array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fizrcka6maa6q4ff626x3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fizrcka6maa6q4ff626x3.png" alt="Modified Binary Search pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;search_rotated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;            &lt;span class="c1"&gt;# left half is sorted
&lt;/span&gt;            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
                &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;                                &lt;span class="c1"&gt;# right half is sorted
&lt;/span&gt;            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
                &lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(log n) time, O(1) space. LeetCode tags &lt;strong&gt;356&lt;/strong&gt; problems with &lt;code&gt;binary-search&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/search-in-rotated-sorted-array/" rel="noopener noreferrer"&gt;Search in Rotated Sorted Array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/" rel="noopener noreferrer"&gt;Find Minimum in Rotated Sorted Array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/koko-eating-bananas/" rel="noopener noreferrer"&gt;Koko Eating Bananas&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tree Depth First Search
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the answer depends on a full root-to-leaf path, or on information returned from a subtree.&lt;/p&gt;

&lt;p&gt;Recursion carries state down the path and returns an answer back up, which is exactly the shape of path sums, depths, and subtree validity checks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs1dwkormqexigp9ei1aq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs1dwkormqexigp9ei1aq.png" alt="Tree Depth First Search pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;has_path_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="c1"&gt;# leaf
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;has_path_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nf"&gt;has_path_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(h) space. LeetCode tags &lt;strong&gt;349&lt;/strong&gt; problems with &lt;code&gt;depth-first-search&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/maximum-depth-of-binary-tree/" rel="noopener noreferrer"&gt;Maximum Depth of Binary Tree&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/path-sum/" rel="noopener noreferrer"&gt;Path Sum&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/validate-binary-search-tree/" rel="noopener noreferrer"&gt;Validate Binary Search Tree&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tree Breadth First Search
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the question mentions levels, or asks for the shortest number of steps.&lt;/p&gt;

&lt;p&gt;A queue visits every node at distance k before any node at distance k+1, so the first time you reach a target you have reached it by the shortest route.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqlqfxx8lfcl35owkey3q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqlqfxx8lfcl35owkey3q.png" alt="Tree Breadth First Search pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;deque&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;level_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nf"&gt;deque&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;              &lt;span class="c1"&gt;# freeze the level width
&lt;/span&gt;            &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;popleft&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(w) space. LeetCode tags &lt;strong&gt;260&lt;/strong&gt; problems with &lt;code&gt;breadth-first-search&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/binary-tree-level-order-traversal/" rel="noopener noreferrer"&gt;Binary Tree Level Order Traversal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/" rel="noopener noreferrer"&gt;Binary Tree Zigzag Level Order Traversal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/minimum-depth-of-binary-tree/" rel="noopener noreferrer"&gt;Minimum Depth of Binary Tree&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Island (Matrix Traversal)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the input is a grid and you need to find or count connected regions.&lt;/p&gt;

&lt;p&gt;A grid is a graph whose neighbors are implicit, so one flood fill per unvisited cell counts regions in a single pass over the matrix.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F59g0frlilbx7zkayori3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F59g0frlilbx7zkayori3.png" alt="Island (Matrix Traversal) pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;num_islands&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cols&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;cols&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;                     &lt;span class="c1"&gt;# mark visited in place
&lt;/span&gt;        &lt;span class="nf"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cols&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
                &lt;span class="nf"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(m*n) time, O(m*n) space. LeetCode tags &lt;strong&gt;285&lt;/strong&gt; problems with &lt;code&gt;matrix&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/number-of-islands/" rel="noopener noreferrer"&gt;Number of Islands&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/max-area-of-island/" rel="noopener noreferrer"&gt;Max Area of Island&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/surrounded-regions/" rel="noopener noreferrer"&gt;Surrounded Regions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  0/1 Knapsack (Dynamic Programming)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; you must choose a subset under a capacity or budget, and subproblems repeat.&lt;/p&gt;

&lt;p&gt;Each item is either taken or skipped, so the answer for a capacity depends only on smaller capacities, which a table fills once instead of re-deriving exponentially.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc7o34m6houkwa0odfuk5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc7o34m6houkwa0odfuk5.png" alt="0/1 Knapsack (Dynamic Programming) pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;can_partition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="n"&gt;dp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;   &lt;span class="c1"&gt;# backwards: each item once
&lt;/span&gt;            &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n*C) time, O(C) space. LeetCode tags &lt;strong&gt;684&lt;/strong&gt; problems with &lt;code&gt;dynamic-programming&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/partition-equal-subset-sum/" rel="noopener noreferrer"&gt;Partition Equal Subset Sum&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/coin-change/" rel="noopener noreferrer"&gt;Coin Change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/target-sum/" rel="noopener noreferrer"&gt;Target Sum&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Top 'K' Elements
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the question asks for the k largest, k smallest, k most frequent, or k closest.&lt;/p&gt;

&lt;p&gt;A heap of size k keeps only the candidates that can still win, which costs O(n log k) instead of the O(n log n) of sorting everything.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffmq44i3tet1hk3kkjin4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffmq44i3tet1hk3kkjin4.png" alt="Top 'K' Elements pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;heapq&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;kth_largest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;heap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;              &lt;span class="c1"&gt;# drop the smallest candidate
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n log k) time, O(k) space. LeetCode tags &lt;strong&gt;222&lt;/strong&gt; problems with &lt;code&gt;heap-priority-queue&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/kth-largest-element-in-an-array/" rel="noopener noreferrer"&gt;Kth Largest Element in an Array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/top-k-frequent-elements/" rel="noopener noreferrer"&gt;Top K Frequent Elements&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/k-closest-points-to-origin/" rel="noopener noreferrer"&gt;K Closest Points to Origin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Backtracking
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the question asks for all valid configurations, not just a count or a best one.&lt;/p&gt;

&lt;p&gt;You build a candidate one choice at a time and undo the choice on the way out, which explores the whole space while holding only one path in memory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbzb2vp0ggs3qv7p7pydp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbzb2vp0ggs3qv7p7pydp.png" alt="Backtracking pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;permute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;used&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;[:])&lt;/span&gt;              &lt;span class="c1"&gt;# copy, the path mutates
&lt;/span&gt;            &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;used&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;
            &lt;span class="n"&gt;used&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;used&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;      &lt;span class="c1"&gt;# undo
&lt;/span&gt;    &lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(b^d) time, O(d) space. LeetCode tags &lt;strong&gt;114&lt;/strong&gt; problems with &lt;code&gt;backtracking&lt;/code&gt;, and it shares the backtracking tag with Subsets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/permutations/" rel="noopener noreferrer"&gt;Permutations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/n-queens/" rel="noopener noreferrer"&gt;N-Queens&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/word-search/" rel="noopener noreferrer"&gt;Word Search&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Subsets
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; you need every combination, subset, or power set of the input.&lt;/p&gt;

&lt;p&gt;Each element is in or out, so the answer set doubles per element, and you can build it iteratively by cloning what you already have.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5bm86mvcqzdnw73mcvcj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5bm86mvcqzdnw73mcvcj.png" alt="Subsets pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;subsets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[]]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cur&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;    &lt;span class="c1"&gt;# clone everything, add n
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n * 2^n) time, O(n * 2^n) space. LeetCode tags &lt;strong&gt;114&lt;/strong&gt; problems with &lt;code&gt;backtracking&lt;/code&gt;, and it shares the backtracking tag with Backtracking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/subsets/" rel="noopener noreferrer"&gt;Subsets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/subsets-ii/" rel="noopener noreferrer"&gt;Subsets II&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/letter-combinations-of-a-phone-number/" rel="noopener noreferrer"&gt;Letter Combinations of a Phone Number&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bitwise XOR
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; elements pair up and cancel, or you are asked to find a single missing or unique value.&lt;/p&gt;

&lt;p&gt;XOR of a value with itself is zero and XOR is order independent, so every duplicate cancels and the lone survivor is the answer in O(1) space.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk7bs3qc1tq79k0oafmbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk7bs3qc1tq79k0oafmbn.png" alt="Bitwise XOR pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;single_number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;^=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;                             &lt;span class="c1"&gt;# pairs cancel to 0
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(1) space. LeetCode tags &lt;strong&gt;297&lt;/strong&gt; problems with &lt;code&gt;bit-manipulation&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/single-number/" rel="noopener noreferrer"&gt;Single Number&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/missing-number/" rel="noopener noreferrer"&gt;Missing Number&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-the-duplicate-number/" rel="noopener noreferrer"&gt;Find the Duplicate Number&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fast &amp;amp; Slow Pointers
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the input is a linked list or an implicit sequence, and you need a cycle, a middle, or a kth-from-end node.&lt;/p&gt;

&lt;p&gt;Two pointers at different speeds meet inside a cycle and land the slow one at the middle on a straight run, with no extra memory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq61l2z27thpciyxvwuev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq61l2z27thpciyxvwuev.png" alt="Fast &amp;amp; Slow Pointers pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;has_cycle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;fast&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;fast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;slow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;                     &lt;span class="c1"&gt;# one step
&lt;/span&gt;        &lt;span class="n"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;                &lt;span class="c1"&gt;# two steps
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;slow&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;fast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(1) space. LeetCode tags &lt;strong&gt;263&lt;/strong&gt; problems with &lt;code&gt;two-pointers&lt;/code&gt;, and it shares the two-pointers tag with Two Pointers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/linked-list-cycle/" rel="noopener noreferrer"&gt;Linked List Cycle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/middle-of-the-linked-list/" rel="noopener noreferrer"&gt;Middle of the Linked List&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/happy-number/" rel="noopener noreferrer"&gt;Happy Number&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Merge Intervals
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the input is a list of ranges, meetings, or time slots that may overlap.&lt;/p&gt;

&lt;p&gt;Once intervals are sorted by start, every overlap is adjacent, so one pass merges or counts them without comparing all pairs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv3ig0elbis0uey4gw9j8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv3ig0elbis0uey4gw9j8.png" alt="Merge Intervals pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intervals&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;intervals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;iv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;iv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;intervals&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;      &lt;span class="c1"&gt;# overlaps the previous
&lt;/span&gt;            &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n log n) time, O(n) space. LeetCode has no dedicated tag for this one; these sit under array and sorting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/merge-intervals/" rel="noopener noreferrer"&gt;Merge Intervals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/insert-interval/" rel="noopener noreferrer"&gt;Insert Interval&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/non-overlapping-intervals/" rel="noopener noreferrer"&gt;Non-overlapping Intervals&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Monotonic Stack
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; you need the next greater or next smaller element, or the span a value dominates.&lt;/p&gt;

&lt;p&gt;A stack kept in sorted order discards elements that can never be an answer again, so every element is pushed and popped at most once.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F81dbkercuxvoeoi9exdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F81dbkercuxvoeoi9exdl.png" alt="Monotonic Stack pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;daily_temperatures&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temps&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temps&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;        &lt;span class="c1"&gt;# stack holds indices
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temps&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;stack&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;temps&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;
        &lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(n) space. LeetCode tags &lt;strong&gt;76&lt;/strong&gt; problems with &lt;code&gt;monotonic-stack&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/next-greater-element-i/" rel="noopener noreferrer"&gt;Next Greater Element I&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/daily-temperatures/" rel="noopener noreferrer"&gt;Daily Temperatures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/largest-rectangle-in-histogram/" rel="noopener noreferrer"&gt;Largest Rectangle in Histogram&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Topological Sort
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; tasks, courses, or builds have prerequisites, and you need a valid order or a cycle check.&lt;/p&gt;

&lt;p&gt;Repeatedly removing nodes with no remaining prerequisites produces a legal order, and a leftover node proves a cycle exists.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F48yknse4eosqm7ca49ki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F48yknse4eosqm7ca49ki.png" alt="Topological Sort pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;deque&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;find_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prereqs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indeg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;course&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;need&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;prereqs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;need&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;course&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;indeg&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;course&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;deque&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;indeg&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;popleft&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;nxt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
            &lt;span class="n"&gt;indeg&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;nxt&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;indeg&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;nxt&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nxt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;      &lt;span class="c1"&gt;# short means a cycle
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(V+E) time, O(V+E) space. LeetCode tags &lt;strong&gt;40&lt;/strong&gt; problems with &lt;code&gt;topological-sort&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/course-schedule/" rel="noopener noreferrer"&gt;Course Schedule&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/course-schedule-ii/" rel="noopener noreferrer"&gt;Course Schedule II&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/minimum-height-trees/" rel="noopener noreferrer"&gt;Minimum Height Trees&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  In-place Reversal of a Linked List
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; you must reverse a list or a sublist without allocating a new one.&lt;/p&gt;

&lt;p&gt;Rewiring the next pointer of each node as you walk reverses the list in one pass and O(1) extra space.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx1zr7ysr4hlnwzohnfpp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx1zr7ysr4hlnwzohnfpp.png" alt="In-place Reversal of a Linked List pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;reverse_list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;nxt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;                       &lt;span class="c1"&gt;# save before overwriting
&lt;/span&gt;        &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;
        &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nxt&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(1) space. LeetCode tags &lt;strong&gt;82&lt;/strong&gt; problems with &lt;code&gt;linked-list&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/reverse-linked-list/" rel="noopener noreferrer"&gt;Reverse Linked List&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/reverse-linked-list-ii/" rel="noopener noreferrer"&gt;Reverse Linked List II&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/reverse-nodes-in-k-group/" rel="noopener noreferrer"&gt;Reverse Nodes in k-Group&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Two Heaps
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; you need a running median, or to keep a set split into a smaller half and a larger half.&lt;/p&gt;

&lt;p&gt;A max-heap over the low half and a min-heap over the high half put the middle value at the two tops, so the median is O(1) to read.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpdh697xlipxlqy7w8atk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpdh697xlipxlqy7w8atk.png" alt="Two Heaps pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;heapq&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MedianFinder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;high&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;         &lt;span class="c1"&gt;# low is a max-heap (negated)
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;high&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;high&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;high&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;median&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;high&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;high&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(log n) insert, O(1) median. LeetCode tags &lt;strong&gt;222&lt;/strong&gt; problems with &lt;code&gt;heap-priority-queue&lt;/code&gt;, and it shares the heap tag with Top 'K' Elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-median-from-data-stream/" rel="noopener noreferrer"&gt;Find Median from Data Stream&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/sliding-window-median/" rel="noopener noreferrer"&gt;Sliding Window Median&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/ipo/" rel="noopener noreferrer"&gt;IPO&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cyclic Sort
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the input is a permutation of numbers in a known range such as 1 to n.&lt;/p&gt;

&lt;p&gt;When a value implies its own index, swapping each number home sorts the array in O(n) with no extra space, which exposes missing and duplicate values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvtvwh7dyi5zza59u5x7u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvtvwh7dyi5zza59u5x7u.png" alt="Cyclic Sort pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cyclic_sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;home&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;                   &lt;span class="c1"&gt;# value n belongs at index n-1
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;home&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
            &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n) time, O(1) space. LeetCode has no dedicated tag for this one; these sit under array and sorting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/missing-number/" rel="noopener noreferrer"&gt;Missing Number&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/" rel="noopener noreferrer"&gt;Find All Numbers Disappeared in an Array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/first-missing-positive/" rel="noopener noreferrer"&gt;First Missing Positive&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  K-way Merge
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; you are given k sorted lists, arrays, or streams to combine or search across.&lt;/p&gt;

&lt;p&gt;A heap holding one candidate from each list always exposes the global smallest next element, so the merge costs O(n log k).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7e3jwm7i0yvkvc01y0vi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7e3jwm7i0yvkvc01y0vi.png" alt="K-way Merge pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;heapq&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;merge_k_sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lists&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;heap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[(&lt;/span&gt;&lt;span class="n"&gt;lst&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lst&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lists&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;lst&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heapify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lists&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;]):&lt;/span&gt;         &lt;span class="c1"&gt;# refill from the same list
&lt;/span&gt;            &lt;span class="n"&gt;heapq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;heappush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lists&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; O(n log k) time, O(k) space. LeetCode tags &lt;strong&gt;17&lt;/strong&gt; problems with &lt;code&gt;merge-sort&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/merge-k-sorted-lists/" rel="noopener noreferrer"&gt;Merge k Sorted Lists&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/" rel="noopener noreferrer"&gt;Kth Smallest Element in a Sorted Matrix&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-k-pairs-with-smallest-sums/" rel="noopener noreferrer"&gt;Find K Pairs with Smallest Sums&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Multi-threaded
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use it when&lt;/strong&gt; the question asks you to coordinate concurrent work, or to enforce an order between threads.&lt;/p&gt;

&lt;p&gt;The algorithm is usually trivial; what is graded is whether you reach for the right primitive and avoid a race or a deadlock.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx8k53ci8oxph6jaubt3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx8k53ci8oxph6jaubt3p.png" alt="Multi-threaded pattern diagram" width="800" height="329"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;second&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Semaphore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;third&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Semaphore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;printFirst&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;printFirst&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;release&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;                &lt;span class="c1"&gt;# unblock the next stage
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;second_&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;printSecond&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;acquire&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;printSecond&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;third&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;release&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;third_&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;printThird&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;third&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;acquire&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;printThird&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; depends on the coordination primitive. LeetCode tags &lt;strong&gt;9&lt;/strong&gt; problems with &lt;code&gt;concurrency&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice on LeetCode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/print-in-order/" rel="noopener noreferrer"&gt;Print in Order&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/print-foobar-alternately/" rel="noopener noreferrer"&gt;Print FooBar Alternately&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/building-h2o/" rel="noopener noreferrer"&gt;Building H2O&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Which LeetCode Patterns Are Most Important
&lt;/h2&gt;

&lt;p&gt;This is the part most pattern lists leave out. Not every pattern earns the same return, because LeetCode's own problems are not evenly spread across them.&lt;/p&gt;

&lt;p&gt;Every question on LeetCode carries one or more topic tags. Counting those tags shows where the problems actually are, which is a better guide to study order than any opinion. Here are the 20 largest tags across the 4,073 problems.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;LeetCode topic tag&lt;/th&gt;
&lt;th&gt;Problems&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;td&gt;2273&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;895&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hash Table&lt;/td&gt;
&lt;td&gt;843&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dynamic Programming&lt;/td&gt;
&lt;td&gt;684&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sorting&lt;/td&gt;
&lt;td&gt;540&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Greedy&lt;/td&gt;
&lt;td&gt;483&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Binary Search&lt;/td&gt;
&lt;td&gt;356&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Depth-First Search&lt;/td&gt;
&lt;td&gt;349&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bit Manipulation&lt;/td&gt;
&lt;td&gt;297&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Matrix&lt;/td&gt;
&lt;td&gt;285&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Prefix Sum&lt;/td&gt;
&lt;td&gt;277&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tree&lt;/td&gt;
&lt;td&gt;270&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Two Pointers&lt;/td&gt;
&lt;td&gt;263&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Breadth-First Search&lt;/td&gt;
&lt;td&gt;260&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Heap (Priority Queue)&lt;/td&gt;
&lt;td&gt;222&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Graph&lt;/td&gt;
&lt;td&gt;190&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stack&lt;/td&gt;
&lt;td&gt;182&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sliding Window&lt;/td&gt;
&lt;td&gt;175&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Backtracking&lt;/td&gt;
&lt;td&gt;114&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Union Find&lt;/td&gt;
&lt;td&gt;98&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three things follow from this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array, String, and Hash Table are not patterns, they are the surface.&lt;/strong&gt; They head the list because almost everything is phrased in terms of them. What matters is the technique applied to them, which is why Two Pointers and Sliding Window carry so much weight despite smaller tag counts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A small set of patterns covers most of the volume.&lt;/strong&gt; Two Pointers, Sliding Window, Modified Binary Search, the two tree traversals, and Dynamic Programming together account for more tagged problems than the rest of this list combined. If your preparation time is short, those are the ones to install first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The long tail is still worth knowing, but last.&lt;/strong&gt; K-way Merge has 17 tagged problems and Multi-threaded has 9. They are rare, and they are also the ones candidates most often have no answer for. Learn them when the common patterns are automatic, not before.&lt;/p&gt;

&lt;h2&gt;
  
  
  How This Compares With the Other LeetCode Pattern Lists
&lt;/h2&gt;

&lt;p&gt;Three resources come up whenever people look for this, and they are all worth knowing about. They do different jobs, and two of them are free.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sean Prashad's Leetcode Patterns
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://seanprashad.com/leetcode-patterns/" rel="noopener noreferrer"&gt;seanprashad.com/leetcode-patterns&lt;/a&gt; is a free, open source list, and it is the most widely used of the three. Its repository describes it as "a pattern-based approach to learn technical interview questions" and carries 14,117 stars.&lt;/p&gt;

&lt;p&gt;What it gives you is a curated set of &lt;strong&gt;179 problems&lt;/strong&gt; you can filter by difficulty, by company, and by pattern, plus a condition-to-approach table that maps a problem characteristic to a suggested technique. It is excellent for deciding what to solve next, and for working a company-specific list before an onsite.&lt;/p&gt;

&lt;p&gt;What it does not do is teach the patterns. The labels it sorts by are mostly LeetCode's own topic tags, around 75 of them, so "Array" and "Hash Table" sit alongside "Sliding Window". If you already know the patterns, that is exactly what you want. If you are trying to learn them, a list cannot explain why a window contracts or when binary search applies to an answer rather than an array.&lt;/p&gt;

&lt;h3&gt;
  
  
  AlgoMaster's 15 Patterns
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://blog.algomaster.io/p/15-leetcode-patterns" rel="noopener noreferrer"&gt;AlgoMaster's post&lt;/a&gt; covers 15 patterns, each with a diagram, a one-line note on when to use it, and three linked LeetCode problems. It is well made and it is the piece most people have read on this topic.&lt;/p&gt;

&lt;p&gt;It stops short of code. There is no template for any of the 15, so you get the idea of a pattern without the implementation you would actually write under time pressure.&lt;/p&gt;

&lt;h3&gt;
  
  
  NeetCode
&lt;/h3&gt;

&lt;p&gt;NeetCode is a roadmap built around curated problem lists with solution walkthroughs, and it is the strongest option if you prefer to learn by watching rather than reading. We cover it separately rather than summarize it here: &lt;a href="https://www.grokkingthecodinginterview.com/blog/neetcode-roadmap" rel="noopener noreferrer"&gt;the NeetCode roadmap on one page&lt;/a&gt; maps the pattern behind each topic, and &lt;a href="https://www.grokkingthecodinginterview.com/blog/neetcode-vs-leetcode" rel="noopener noreferrer"&gt;NeetCode compared with LeetCode&lt;/a&gt; puts the numbers side by side.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where this page fits
&lt;/h3&gt;

&lt;p&gt;This one is the explained version. Every pattern gets the cue that identifies it, why the technique works, a template in Python, a diagram, and three problems, so you can go from never having seen a pattern to writing it from memory without leaving the page.&lt;/p&gt;

&lt;p&gt;Use whichever fits what you need right now. If you want a filterable queue of problems, use Sean Prashad's list. If you want video, use NeetCode. If you want to understand the 20 patterns well enough to recognize them on a question you have never seen, read this page and then practice against one of those lists. They work well together, and a free list plus a real explanation beats either on its own.&lt;/p&gt;

&lt;p&gt;For a wider view of the paid and free options, including the video courses, see &lt;a href="https://www.grokkingthecodinginterview.com/blog/best-dsa-courses" rel="noopener noreferrer"&gt;the best DSA courses compared&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use This List
&lt;/h2&gt;

&lt;p&gt;Work one pattern at a time rather than one problem at a time. Read the cue, write the template from memory, then solve the three linked problems in a row. Practicing LeetCode problems pattern wise, meaning grouped by the pattern that solves them rather than in list order, teaches you more than solving ten unrelated ones, because the third problem in a group is where recognition starts to happen on its own.&lt;/p&gt;

&lt;p&gt;That is why the 60 problems on this page are grouped under their pattern instead of being given as one flat list. A flat list trains you to grind. Problems grouped by pattern train you to recognize.&lt;/p&gt;

&lt;p&gt;When a problem defeats you, do not jump straight to the solution. Ask which of these 20 it resembles first. If you can name the pattern and still cannot finish, that is a template problem and it is quick to fix. If you cannot name the pattern at all, that is the skill actually being tested, and it is the one worth practicing.&lt;/p&gt;

&lt;p&gt;The full curriculum, with each pattern taught in six languages and grouped practice problems, is in &lt;a href="https://www.designgurus.io/course/grokking-the-coding-interview?utm_source=devto" rel="noopener noreferrer"&gt;Grokking the Coding Interview&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Check out &lt;a href="https://www.designgurus.io/blind75?utm_source=devto" rel="noopener noreferrer"&gt;Blind75&lt;/a&gt; for more problems. If you are choosing a course to learn these patterns from, &lt;a href="https://www.grokkingthecodinginterview.com/blog/best-dsa-courses" rel="noopener noreferrer"&gt;The Best DSA Courses Compared: Paid, Free, and YouTube&lt;/a&gt; reviews the main options side by side.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQs - LeetCode Patterns and Interview Prep
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Q1. What are LeetCode patterns?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;LeetCode patterns&lt;/strong&gt; are common coding techniques or strategies that repeatedly show up in LeetCode problems and technical interviews. Instead of solving every problem from scratch, learning these patterns helps you recognize how to approach and solve new problems based on familiar logic (e.g., Two Pointers, Sliding Window, DFS, etc.).&lt;/p&gt;

&lt;h3&gt;
  
  
  Q2. Why should I learn LeetCode patterns instead of solving random problems?
&lt;/h3&gt;

&lt;p&gt;Focusing on patterns helps you avoid burnout and prepares you faster. Each pattern unlocks the ability to solve dozens of problems, which is much more efficient than solving 500+ random questions without structure. Interviewers often test your ability to apply known patterns to new scenarios, not just memorize solutions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q3. How many LeetCode patterns should I learn for FAANG interviews?
&lt;/h3&gt;

&lt;p&gt;Learn all &lt;strong&gt;20&lt;/strong&gt;, in the order on this page. The first six, Two Pointers, Sliding Window, Modified Binary Search, the two tree traversals, and Dynamic Programming, cover the largest share of what gets asked, so start there if your time is short. The remaining fourteen are what separate a candidate who handles the common question from one who is not stopped by an unusual one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q4. Do LeetCode patterns actually help in real interviews?
&lt;/h3&gt;

&lt;p&gt;Yes, most FAANG interview questions map to well-known patterns. Recognizing the right pattern during an interview helps you solve problems faster and with more confidence, especially under time pressure. It also shows your structured thinking, which is exactly what interviewers want.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q5. Where can I practice LeetCode patterns?
&lt;/h3&gt;

&lt;p&gt;You can start with categorized problem lists on LeetCode itself, or check out structured resources like &lt;strong&gt;&lt;a href="https://www.designgurus.io/course/grokking-the-coding-interview?utm_source=devto" rel="noopener noreferrer"&gt;Grokking the Coding Interview&lt;/a&gt;&lt;/strong&gt;, which teaches these patterns with guided explanations and practice problems grouped by pattern.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q6. Are LeetCode patterns the same as algorithms?
&lt;/h3&gt;

&lt;p&gt;Not exactly. Algorithms are step-by-step procedures for solving specific types of problems (like Dijkstra’s or Merge Sort). &lt;strong&gt;Patterns&lt;/strong&gt; are reusable problem-solving approaches, like frameworks, that help you decide &lt;em&gt;how&lt;/em&gt; to apply different algorithms or data structures depending on the question.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q7. How do I identify which pattern a question belongs to?
&lt;/h3&gt;

&lt;p&gt;Look at the problem constraints and the goal. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Need to find a subarray or substring? → Try &lt;strong&gt;Sliding Window&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Working with sorted data or binary decisions? → Use &lt;strong&gt;Binary Search&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Need to explore all paths or combinations? → Think &lt;strong&gt;DFS&lt;/strong&gt; or &lt;strong&gt;Backtracking&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The more patterns you practice, the easier it becomes to recognize which one fits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q8. Is mastering patterns enough to crack coding interviews?
&lt;/h3&gt;

&lt;p&gt;Patterns are your foundation, but combine them with good communication, mock interviews, and time management. You should also review system design (for senior roles), &lt;a href="https://www.designgurus.io/blog/tech-interview-behavioral-questions?utm_source=devto" rel="noopener noreferrer"&gt;behavioral interview questions&lt;/a&gt;, and understand the company’s specific process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q9. What are the best LeetCode patterns to know?
&lt;/h3&gt;

&lt;p&gt;The best LeetCode patterns to focus on are the ones that appear most frequently in coding interviews and help solve a wide variety of problems. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Two Pointers&lt;/strong&gt; – great for arrays and strings&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sliding Window&lt;/strong&gt; – ideal for subarray/substring problems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Depth-First Search (DFS)&lt;/strong&gt; – for tree and graph traversal&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Breadth-First Search (BFS)&lt;/strong&gt; – used in shortest path and level order problems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Binary Search&lt;/strong&gt; – for problems with sorted data or monotonic conditions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Merge Intervals&lt;/strong&gt; – useful in scheduling and overlapping intervals&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Programming (DP)&lt;/strong&gt; – for optimization and counting problems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recursion &amp;amp; Backtracking&lt;/strong&gt; – perfect for exhaustive search and decision trees&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monotonic Stack&lt;/strong&gt; – for next greater/smaller element problems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Union-Find (DSU)&lt;/strong&gt; – for detecting cycles and grouping connected components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mastering these patterns allows you to recognize problem types quickly and apply efficient solutions, critical for success in FAANG interviews.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q10. Why study coding patterns for interviews?
&lt;/h3&gt;

&lt;p&gt;Studying coding patterns helps you avoid random practice and prepare more strategically. Instead of solving every problem from scratch, patterns teach you how to &lt;strong&gt;recognize the underlying structure&lt;/strong&gt; of a problem and &lt;strong&gt;reuse proven techniques&lt;/strong&gt;. This saves time, builds confidence, and dramatically improves your problem-solving skills.&lt;/p&gt;

&lt;p&gt;Most interview problems are variations of core patterns. &lt;/p&gt;

&lt;p&gt;By mastering them, you’ll be able to tackle new problems more quickly, reduce anxiety during live interviews, and demonstrate structured thinking, something interviewers love to see. In short, patterns are the shortcut to smarter and faster coding interview prep.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Go deeper:&lt;/strong&gt; for the expanded version of this pattern-first approach, see the &lt;a href="https://www.grokkingthecodinginterview.com/blog/leetcode-patterns" rel="noopener noreferrer"&gt;complete guide to all 42 coding interview patterns&lt;/a&gt;, which includes the tell that identifies each pattern from the problem statement, a printable cheat sheet, and free pattern-by-pattern deep dives.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q11. How many LeetCode patterns are there?
&lt;/h3&gt;

&lt;p&gt;There is no official count, because LeetCode does not publish one. This guide uses &lt;strong&gt;20&lt;/strong&gt;, which is the set that covers the overwhelming majority of interview questions without padding the list. Other lists quote 14, 15, or 23; the differences are mostly about whether closely related techniques are split apart or grouped together, not about the underlying ideas.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q12. Are LeetCode patterns the same as design patterns or pattern matching?
&lt;/h3&gt;

&lt;p&gt;No, and the three get confused often.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design patterns&lt;/strong&gt; are object-oriented structures such as Singleton, Factory, and Observer. They belong to object-oriented design and low level design rounds, not to the algorithmic patterns on this page. LeetCode does have a separate &lt;strong&gt;Design&lt;/strong&gt; tag, with 134 problems like LRU Cache and Design Twitter, which asks you to build a data structure to a specification. That is a different skill again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pattern matching&lt;/strong&gt; means string matching, regular expressions, and problems like Regular Expression Matching or Wildcard Matching. It is a problem topic, not a solving strategy.&lt;/p&gt;

&lt;p&gt;The 20 on this page are &lt;strong&gt;coding patterns&lt;/strong&gt;, also called DSA patterns: reusable strategies for recognizing and solving algorithm questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related questions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/answers/detail/which-is-better-codechef-or-leetcode-or-hackerrank"&gt;Which is better CodeChef or LeetCode or HackerRank?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/answers/detail/how-many-leetcode-problems-should-i-do-per-day"&gt;How many LeetCode problems should I do per day?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/answers/detail/what-is-a-good-rank-on-leetcode"&gt;What is a good rank on LeetCode?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/answers/detail/how-much-leetcode-is-enough-for-google"&gt;How much LeetCode is enough for Google?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/answers/detail/do-faang-companies-ask-leetcode-hard"&gt;Do Faang companies ask LeetCode hard?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/answers/detail/what-is-a-good-acceptance-rate-on-leetcode"&gt;What is a good acceptance rate on LeetCode?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/answers/detail/what-is-the-most-used-language-on-leetcode"&gt;What is the most used language on LeetCode?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.designgurus.io/blog/top-lc-patterns?utm_source=devto" rel="noopener noreferrer"&gt;DesignGurus.io&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>algorithms</category>
      <category>interview</category>
      <category>programming</category>
    </item>
    <item>
      <title>System Design Patterns: The Complete Guide (60+ Patterns Explained Simply)</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Sun, 19 Jul 2026 06:41:18 +0000</pubDate>
      <link>https://dev.to/arslan_ah/system-design-patterns-the-complete-guide-60-patterns-explained-simply-1ckk</link>
      <guid>https://dev.to/arslan_ah/system-design-patterns-the-complete-guide-60-patterns-explained-simply-1ckk</guid>
      <description>&lt;p&gt;Every system you admire is built from parts you can name. The feed that loads in 80 milliseconds, the checkout that survives a datacenter failure, the chatbot that answers from yesterday's documentation: each one is a composition of the same recurring solutions, applied in the right places. Those recurring solutions are &lt;strong&gt;system design patterns&lt;/strong&gt;, and there are roughly sixty of them worth knowing.&lt;/p&gt;

&lt;p&gt;This guide covers all of them. For each pattern you will get three things: the problem it solves, the core move it makes, and the price you pay for using it. By the end, you should be able to look at any architecture, or any interview prompt, and see the parts.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What Are System Design Patterns?
&lt;/h2&gt;

&lt;p&gt;A system design pattern is a named, reusable solution to a problem that recurs when you build distributed systems. "Reads are overwhelming my database" is a recurring problem; &lt;strong&gt;primary-replica replication&lt;/strong&gt; is its named solution. "A retry charged the customer twice" is a recurring problem; &lt;strong&gt;idempotency&lt;/strong&gt; is its named solution.&lt;/p&gt;

&lt;p&gt;Two clarifications before we start.&lt;/p&gt;

&lt;p&gt;First, system design patterns are not the same as the classic "design patterns" from the Gang of Four book. Those are code-level patterns (Singleton, Observer, Factory) for organizing classes inside one program. System design patterns are architecture-level: they describe how databases, queues, caches, and services work together across many machines. In a system design interview, the interviewer means the architecture-level kind.&lt;/p&gt;

&lt;p&gt;Second, a pattern is not a technology. Kafka is a product; the &lt;strong&gt;message queue&lt;/strong&gt; and the &lt;strong&gt;append-only log&lt;/strong&gt; are the patterns inside it. Redis is a product; &lt;strong&gt;cache-aside&lt;/strong&gt; is the pattern you use it for. Learn the pattern and you can evaluate any product. Learn only the product and you are lost when the stack changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Why Patterns Beat Memorizing Architectures
&lt;/h2&gt;

&lt;p&gt;There are thousands of possible system designs, and you cannot memorize them all. You do not need to. Architectures are sentences; patterns are the words. Once you own the vocabulary, "design Instagram" stops being a memory test and becomes a composition exercise.&lt;/p&gt;

&lt;p&gt;Working with patterns is three habits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Diagnosis.&lt;/strong&gt; Recognize which problem you are actually looking at. Dashboards are green but one feature is starving: that is the bulkhead problem. Two teams' metrics disagree: that is the same question with two authors. Most of system design skill is matching symptoms to shapes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Composition.&lt;/strong&gt; Combine patterns, and handle the seams between them. Retries demand idempotency. Caches demand a stampede plan. Sagas demand designed compensations. The seams are where real engineering lives.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pricing.&lt;/strong&gt; Every pattern is a purchase. Sharding buys write scale and costs you cross-shard queries. Caching buys speed and costs you staleness. Saying the cost out loud, in the same breath as the pattern, is what separates senior answers from buzzword answers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keep those three habits in mind as you read the catalog below. Each entry is deliberately structured as diagnosis (the problem), composition material (the move), and price (the cost).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(I teach all sixty of these patterns in depth, each one through a real production incident, in my course &lt;a href="https://www.designgurus.io/course/system-design-patterns?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=sdp-cluster&amp;amp;utm_content=system-design-patterns-complete-guide" rel="noopener noreferrer"&gt;System Design Patterns: From Fundamentals to Real Systems&lt;/a&gt;. This guide is the map; the course is the territory.)&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The Complete List: 60+ System Design Patterns by Category
&lt;/h2&gt;

&lt;p&gt;The patterns fall into ten categories. Use the list below to jump around, or read straight through: the order follows how problems actually arrive as a system grows.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Communication patterns (7)&lt;/li&gt;
&lt;li&gt;Storage and replication patterns (6)&lt;/li&gt;
&lt;li&gt;Caching patterns (5)&lt;/li&gt;
&lt;li&gt;Reliability patterns (7)&lt;/li&gt;
&lt;li&gt;Scaling patterns (5)&lt;/li&gt;
&lt;li&gt;Consistency patterns (4)&lt;/li&gt;
&lt;li&gt;API and edge patterns (9)&lt;/li&gt;
&lt;li&gt;Operations and delivery patterns (5)&lt;/li&gt;
&lt;li&gt;Data-intensive patterns (7)&lt;/li&gt;
&lt;li&gt;AI-era patterns (7)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fktifelms1rsc0n9zmr9h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fktifelms1rsc0n9zmr9h.png" alt="The System Design Pattern Map: 60+ patterns in ten categories" width="799" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Communication Patterns: Moving Data Between Services
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Request-Response.&lt;/strong&gt; The default: a client asks, a server answers, someone waits. It is the right choice whenever a user is waiting for the answer. Its weakness is coupling: the caller's fate is tied to the callee's speed and health, which is why half the reliability patterns below exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Message Queue.&lt;/strong&gt; Work that nobody needs to wait on goes into a queue, and workers process it at their own pace. Traffic spikes become backlog instead of outages. The price: delivery is at-least-once, so consumers must handle duplicates, and the queue's depth becomes a metric you must watch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Publish-Subscribe.&lt;/strong&gt; One event, many independent consumers. The order service announces "order placed" once; email, analytics, and inventory each react without knowing about each other. The price: your event schema becomes a public contract, and changing it becomes a negotiation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event-Driven Architecture.&lt;/strong&gt; The pub-sub idea promoted to an architectural style: services react to facts instead of calling each other. You gain loose coupling and independent scaling. You pay in governance: who consumes what, and how a business flow is traced across five reacting services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Webhooks.&lt;/strong&gt; Events delivered across company boundaries as HTTP POSTs. The receiving discipline: verify the signature, save the raw event, respond in milliseconds, process later behind your own queue, and reconcile with a polling loop, because the worst webhook failure looks exactly like a quiet day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server-Sent Events (SSE).&lt;/strong&gt; One HTTP response that never ends: the server pushes updates down it as they happen. It is why LLM chat apps show words one at a time. One direction only, and the browser handles reconnection for you. When the client needs to talk back continuously, you have outgrown it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bidirectional Streaming (WebSockets).&lt;/strong&gt; A true two-way conversation on one connection: chat, collaborative editing, multiplayer games. The price is stateful, sticky connections and reconnection logic you now own. The rule: escalate to it on need, never on fashion.&lt;/p&gt;

&lt;h3&gt;
  
  
  Storage and Replication Patterns: Where Truth Lives
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Primary-Replica Replication.&lt;/strong&gt; One machine takes all writes and streams its change log to replicas that serve reads. Read capacity scales by adding copies, and a dead primary is replaced by promoting a replica. The price: replicas lag slightly, so a user can miss their own write, and replicas add zero write capacity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sharding.&lt;/strong&gt; When writes or data size outgrow one machine, split the table's rows across machines by a shard key. The key is the whole game: it should appear in nearly every query, spread load evenly, and keep related rows together. The price: cross-shard queries, cross-shard transactions, and hot keys become your problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consistent Hashing.&lt;/strong&gt; The routing rule that lets a cluster change size gracefully. With naive modulo routing, adding a fifth shard moves 80% of all data. On the hash ring, it moves about 20%: only the slice the new server takes over. Virtual nodes keep the slices even and spread a dead server's load across everyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write-Ahead Log (WAL).&lt;/strong&gt; Before touching any data structure, the database appends one record describing the change to a log and forces it to disk. Only then does it say "saved." Crash recovery is replaying the log. This one mechanism also powers replication and point-in-time recovery, which makes the append-only log the most important structure in the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event Sourcing.&lt;/strong&gt; Store what happened, not what is. Every change is an immutable business event (OrderPlaced, OrderCancelled), and current state is derived by replaying them. Perfect audit trails and time travel, at the cost of projections for queries and event schemas that live forever. The default answer is no; the exception is ledger-shaped domains: money, orders, inventory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CQRS.&lt;/strong&gt; When reads and writes want different shapes, split the model: a lean, validated write model, and read models shaped for each question (a pre-joined table, a search index, an aggregates store), kept in sync from a change stream. Never sync them by writing to both from application code: dual writes drift silently.&lt;/p&gt;

&lt;h3&gt;
  
  
  Caching Patterns: Serving Data Fast
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Cache-Aside.&lt;/strong&gt; The default cache: the application checks the cache, loads from the database on a miss, and stores the result. Two numbers rule everything: the hit ratio and the staleness budget. Invalidation is your job, and the TTL is your safety net.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read-Through.&lt;/strong&gt; The cache itself loads misses from the database, so application code just reads. Cleaner call sites, at the cost of a smarter cache layer in your read path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write-Through.&lt;/strong&gt; Writes go to the cache and the store together, so reads are always warm and never stale. The price: every write pays for both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write-Behind.&lt;/strong&gt; Writes land in the cache and flush to the store later, in batches. Enormous write throughput, with a window where acknowledged data exists only in memory. Never for money.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cache Stampede Prevention.&lt;/strong&gt; When a popular key expires, a thousand requests can miss at once and crush the database together. The cures: let one request rebuild while others wait (single flight), add jitter to expiry times, and refresh hot keys before they expire.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reliability Patterns: Surviving Failure
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Timeout.&lt;/strong&gt; No wait is allowed to be unbounded. Every network call gets a deadline, chosen from the callee's real latency profile. The subtlety: a timeout means "I stopped waiting," never "it did not happen." The work may have finished after you gave up, which is why idempotency exists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retry with Exponential Backoff.&lt;/strong&gt; Transient failures deserve a second try, with increasing delays and randomness (jitter) so a thousand clients do not retry in lockstep and finish off a struggling server. Retries without backoff, jitter, and a budget are how outages get worse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Idempotency.&lt;/strong&gt; The same request processed twice must have the effect of once. The client generates a unique key per operation, and the server remembers keys it has seen. This is the pattern that makes retries safe, and the reason a double-clicked "Pay" button charges once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Circuit Breaker.&lt;/strong&gt; When a dependency keeps failing, stop calling it. Fail fast, give it time to recover, and probe occasionally to see if it is back. This turns a slow, cascading failure into a fast, contained one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bulkhead.&lt;/strong&gt; Partition your resources so one workload cannot starve the rest. Separate connection pools, thread pools, or fleets per feature. The symptom it prevents: dashboards green overall while one feature quietly consumed every thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dead Letter Queue.&lt;/strong&gt; A message that fails repeatedly gets moved aside into a quarantine queue, so it stops blocking everything behind it. The DLQ needs an owner and an alert, or it becomes a place where problems go to be forgotten.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Graceful Degradation.&lt;/strong&gt; Decide in advance what each feature does when its dependencies fail: serve stale data, show a smaller answer, or refuse. Availability features fail open; money and authorization fail closed. The worst answer is the one nobody designed: a blank error page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scaling Patterns: Growing Under Load
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vertical Scaling.&lt;/strong&gt; A bigger machine. No new failure modes, no code changes, and it buys you time. It has a ceiling, and at the top of the catalog the prices climb steeply. Exhaust the simple win before taking on distributed problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Horizontal Scaling.&lt;/strong&gt; Many identical, stateless copies behind a load balancer. The catch is the word stateless: sessions, counters, and files must move out of the server first, or each copy holds a different fraction of the truth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Load Balancing.&lt;/strong&gt; Spreading requests across those copies, informed by health checks and actual load. Draining connections before removing a server is the difference between a deploy and an incident.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Auto-Scaling.&lt;/strong&gt; Capacity that follows demand: scheduled scaling for the load you can predict (most of it), reactive scaling for the surprise. Reaction takes minutes, so headroom is part of the design, and the maximum is a safety limit you set on purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connection Pooling.&lt;/strong&gt; Opening a database connection is expensive; reuse a small pool of warm ones instead. The quiet trap: pool size multiplies across your fleet, and 50 servers with modest pools can exhaust a database's connection limit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Consistency Patterns: Keeping Data Correct Across Machines
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Two-Phase Commit (2PC).&lt;/strong&gt; The coordinator asks all participants to prepare, then tells them all to commit: atomicity across machines. The price: everyone blocks if the coordinator dies at the wrong moment. It works inside one trust boundary; it does not cross companies. Often the best move is designing the transaction away entirely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Saga.&lt;/strong&gt; A long business transaction as a sequence of local steps, each with a designed compensation (undo) if a later step fails. Book the flight, book the hotel; if the hotel fails, unbook the flight. Order the irreversible steps last. This is how money moves between systems that share no database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quorum.&lt;/strong&gt; Decisions by majority: with three or five copies, require agreement from more than half before an answer counts. Majorities prevent split brain, because two disagreeing majorities cannot exist. The price is latency, and a minority partition that goes read-only on purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vector Clocks.&lt;/strong&gt; A way to track causality so the system can tell "this edit came after that one" apart from "these two edits happened concurrently and neither saw the other." Concurrent edits become explicit conflicts to resolve rather than silent overwrites.&lt;/p&gt;

&lt;h3&gt;
  
  
  API and Edge Patterns: The Front Door
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Reverse Proxy.&lt;/strong&gt; One front door for your servers: it terminates TLS, routes requests, and shields the fleet behind it. Nearly every pattern in this category is a specialized reverse proxy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CDN.&lt;/strong&gt; Copies of your content cached at the edge, near users. The two disciplines: getting invalidation right, and never letting private, per-user responses into a shared cache.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Gateway.&lt;/strong&gt; Cross-cutting policy enforced once: authentication, rate limits, routing to services. The discipline is staying thin. The moment business logic moves in, you have rebuilt the monolith in the doorway.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backend for Frontend (BFF).&lt;/strong&gt; A thin backend per client type (web, mobile) that composes reads into exactly the shape that client needs. Presentation composes reads; the domain services keep owning writes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rate Limiting.&lt;/strong&gt; Protecting capacity by refusing excess politely: token buckets that allow bursts but cap sustained rates, tiered by customer. A 429 with a Retry-After header is a feature, not a failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cursor-Based Pagination.&lt;/strong&gt; Page through data by position ("after item X") instead of offset ("items 51-100"), so results stay stable while new data arrives. The price: no jumping to page seven.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Versioning.&lt;/strong&gt; Changing an API without breaking its clients: additive changes where possible, versioned contracts where not. Every field you publish is a promise someone will hold you to for years.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sidecar.&lt;/strong&gt; Cross-cutting concerns (TLS, retries, telemetry) packaged as a helper process that runs beside every service instance, in any language. The building block that makes the next pattern possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Service Mesh.&lt;/strong&gt; Sidecars on every service plus a control plane: mutual TLS, retries, timeouts, and telemetry for all service-to-service traffic, without touching application code. A heavy platform. Adopt it when the service count and compliance needs clear the bar, not before.&lt;/p&gt;

&lt;h3&gt;
  
  
  Operations and Delivery Patterns: Shipping Without Breaking
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Health Check Endpoint.&lt;/strong&gt; The difference between "the process is running" (liveness) and "the process can do useful work" (readiness), exposed as endpoints that load balancers and deploys consult. Shallow checks lie; check the dependencies that matter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Distributed Tracing.&lt;/strong&gt; One request's story across every service it touched, stitched together by a trace ID. When the checkout is slow, the trace shows which of the nine hops ate the time. Instrumentation costs effort; debugging without it costs more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blue-Green Deployment.&lt;/strong&gt; Two identical environments; switch traffic instantly, switch back instantly if something breaks. The catch everyone learns once: the database does not blue-green. Schema changes need the expand-contract discipline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Canary Deployment.&lt;/strong&gt; Release to a small slice first, judge it against the current version on real metrics, then widen. The judging is the pattern: a canary without honest verdict metrics is theater.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feature Flags.&lt;/strong&gt; Separate deploying code from releasing behavior. The code ships dark; the behavior turns on with a flag, per cohort, reversible in seconds. The debt: flags must be deleted after they win, or the codebase fills with dead switches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data-Intensive Patterns: Batch and Streaming
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;MapReduce.&lt;/strong&gt; The batch shape: process a huge dataset by working on pieces in parallel where the data lives (map), regrouping by key (shuffle), and merging (reduce). You will never write raw MapReduce, and you will never escape its shape: it is the physics under every warehouse and Spark job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stream Processing.&lt;/strong&gt; A job that runs forever, holding running counts keyed by the thing being watched, answering while the data is still arriving. Its hard ideas: event time versus arrival time, watermarks that decide when a window may close, and answers that may be amended when stragglers arrive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lambda and Kappa Architectures.&lt;/strong&gt; Two answers to batch and streaming both computing the same numbers. Lambda runs both, with batch overwriting the stream's results on schedule. Kappa keeps one streaming codebase over a replayable log and re-runs history when logic changes. The rule either way: every metric gets exactly one definition of truth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change Data Capture (CDC).&lt;/strong&gt; Tail the database's own write-ahead log and publish every committed change as an event. It cannot miss: bulk imports and manual fixes flow through the same log as app writes. This is how search indexes, caches, and warehouses stay in sync without fragile dual writes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exactly-Once Semantics.&lt;/strong&gt; Counting things once despite crashes and retries. Delivery can never be exactly-once; the effect can be, by moving the processing state and the outputs together with the log position. Reserve the heavy machinery for numbers with auditors: billing, ledgers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backpressure.&lt;/strong&gt; When a producer outruns a consumer, something must give: a bounded buffer absorbs bursts, a drop policy sheds what is worthless when stale, or the producer is slowed. The one wrong answer is the unbounded buffer, which schedules an out-of-memory crash instead of surfacing the mismatch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Partitioned Consumption.&lt;/strong&gt; Order per key, parallelism across keys: every event for a given customer lands in the same partition, each partition has exactly one consumer, so a refund can never be processed before its charge. The partition count is a ceiling chosen in advance, and one hot key can still make one partition burn.&lt;/p&gt;

&lt;h3&gt;
  
  
  AI-Era Patterns: LLM and ML Infrastructure
&lt;/h3&gt;

&lt;p&gt;Nothing in the AI stack is architecturally new; every pattern here is one of the above operating under changed constants. But the changed constants matter enough that these seven deserve their own names.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feature Store.&lt;/strong&gt; Define each ML feature once, and let a platform compute it both offline for training and online for serving. This kills training/serving skew: the silent bug where a model learns from one definition of a number and gets served another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model Serving and Batching.&lt;/strong&gt; At batch-of-one, a GPU serving an LLM runs at single-digit utilization, because each token step streams the whole model's weights to do almost no math. Continuous batching lets dozens of requests share each weight-pass, multiplying throughput 20-30x. It is the difference between a viable AI feature and an absurd bill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GPU Auto-Scaling.&lt;/strong&gt; Web autoscaling with both dials at 100x: idle GPUs cost a hundred times more, and cold starts take minutes, not seconds. The answers: scale on queue depth (never CPU), keep warm pools as priced insurance, pre-warm on the calendar, and fall back to a smaller model when capacity gaps hit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LLM Gateway.&lt;/strong&gt; One internal door for all model traffic: it holds the provider keys, meters every token against budgets with hard caps, routes logical model names to physical providers, and runs the failover ladder when a provider browns out. The API gateway pattern, pointed outward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Semantic Caching.&lt;/strong&gt; Forty percent of user questions are rephrasings of known questions, but exact-match caching catches almost none of them. Key the cache by meaning instead: embed the query and match by similarity, with a conservative threshold, because a false hit serves a confidently wrong answer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vector Database Sharding.&lt;/strong&gt; Similarity search breaks normal sharding's best rule: a nearest-neighbor query has no shard key, so the default is asking every shard and merging. The escape: when every query is tenant-scoped, the tenant filter becomes the shard key and single-shard routing returns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RAG Pipeline.&lt;/strong&gt; Knowledge in model weights has no update path, no citations, and no access control. Retrieval-Augmented Generation fixes all three: keep documents in an index that updates in seconds, retrieve only what the asker is permitted to read, and require the model to answer from the retrieved text with citations. The model reasons; the index remembers.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. How Patterns Compose: A News Feed in Ten Patterns
&lt;/h2&gt;

&lt;p&gt;A pattern list becomes useful when you see composition. Take the classic prompt: design a social feed. Watch the patterns snap together.&lt;/p&gt;

&lt;p&gt;Reads outnumber writes about 50 to 1, so the feed is a read-serving problem. Precompute each user's feed at write time and serve it like a &lt;strong&gt;cache&lt;/strong&gt;: this is &lt;strong&gt;CQRS&lt;/strong&gt;, with the feed as a read model. Posting fans out through a &lt;strong&gt;message queue&lt;/strong&gt; with &lt;strong&gt;partitioned consumption&lt;/strong&gt;, fed reliably by an &lt;strong&gt;outbox (CDC)&lt;/strong&gt; so a committed post always reaches the pipeline. The feed store is a &lt;strong&gt;sharded&lt;/strong&gt;, &lt;strong&gt;consistent-hashed&lt;/strong&gt; cluster of lists, evicted and rebuilt like any cache. Celebrities with 50 million followers would break write-time fan-out, so their posts merge at read time from a hot cache with &lt;strong&gt;stampede prevention&lt;/strong&gt;. Fan-out workers &lt;strong&gt;auto-scale&lt;/strong&gt; on backlog age. Appends are &lt;strong&gt;idempotent&lt;/strong&gt; so at-least-once delivery cannot duplicate a post. When parts fail, the feed &lt;strong&gt;degrades gracefully&lt;/strong&gt;: slightly stale beats blank.&lt;/p&gt;

&lt;p&gt;Ten-plus patterns, one design, and every choice justified by a number or a failure mode. That is what interviewers mean when they say a candidate "thinks in systems." It is also the skill this entire catalog exists to build: not knowing sixty definitions, but composing the right eight of them under pressure.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. How to Learn These Patterns Properly
&lt;/h2&gt;

&lt;p&gt;Reading a list is recognition. Interviews and production require recall and application. Three suggestions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Learn each pattern through its failure story.&lt;/strong&gt; Every pattern above exists because something broke at 2 AM. "Cache stampede prevention" is forgettable; "a thousand requests missed the same expired key at once and crushed the database" is not. Attach each pattern to its incident.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Always learn the price and the "when not."&lt;/strong&gt; A pattern you cannot argue against is a pattern you do not understand. Sharding from day one, CQRS on a settings page, and event sourcing everywhere are the classic ways to pay real complexity for imaginary scale.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice composition on full designs.&lt;/strong&gt; Run the classic prompts (a feed, a ride-sharing dispatch, a payment platform) and force yourself to name every pattern you use and what it costs, out loud.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is exactly how my course, &lt;strong&gt;&lt;a href="https://www.designgurus.io/course/system-design-patterns?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=sdp-cluster&amp;amp;utm_content=system-design-patterns-complete-guide" rel="noopener noreferrer"&gt;System Design Patterns: From Fundamentals to Real Systems&lt;/a&gt;&lt;/strong&gt;, is built. All sixty-plus patterns above get a full lesson: a real production incident, the naive fixes and why they fail, a walkthrough with real numbers, the trade-offs, when NOT to use it, and a 30-second interview answer you can say under pressure. The course ends with four complete interview walkthroughs (a news feed, ride-sharing dispatch, a payment platform, and an AI copilot) where you watch the sixty patterns compose into real systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Frequently Asked Questions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What are system design patterns?&lt;/strong&gt;&lt;br&gt;
System design patterns are named, reusable solutions to problems that recur in distributed systems: scaling reads, surviving failures, keeping data consistent across machines, and moving data between services. They are architecture-level building blocks, used to design systems like feeds, payment platforms, and chat applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How many system design patterns are there?&lt;/strong&gt;&lt;br&gt;
Around sixty patterns cover essentially everything asked in interviews and used in production, spanning communication, storage, caching, reliability, scaling, consistency, APIs, operations, data engineering, and AI infrastructure. This guide lists all of them by category.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Are system design patterns the same as design patterns?&lt;/strong&gt;&lt;br&gt;
No. Classic design patterns (from the Gang of Four book) organize code inside one program: Singleton, Observer, Factory. System design patterns organize infrastructure across many machines: sharding, caching, circuit breakers, sagas. In system design interviews, the interviewer means the architecture-level kind.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which system design patterns matter most for interviews?&lt;/strong&gt;&lt;br&gt;
Eight patterns appear in the overwhelming majority of interview questions: cache-aside, sharding, message queues, circuit breakers, idempotency, sagas, CQRS, and rate limiting. Learn those deeply first, then broaden. The highest-scoring skill is not naming patterns but stating each one's cost as you use it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do AI systems need new system design patterns?&lt;/strong&gt;&lt;br&gt;
Mostly no, and that is good news. The LLM gateway is the API gateway pattern pointed outward, semantic caching is cache-aside with similarity instead of equality, and GPU autoscaling is standard autoscaling with far harsher constants. An engineer who knows the classic sixty walks into AI infrastructure already knowing the building.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Arslan Ahmad is the author of &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt; and founder of DesignGurus.io. His new course, &lt;a href="https://www.designgurus.io/course/system-design-patterns?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=sdp-cluster&amp;amp;utm_content=system-design-patterns-complete-guide" rel="noopener noreferrer"&gt;System Design Patterns: From Fundamentals to Real Systems&lt;/a&gt;, teaches all sixty-plus patterns in this guide through real production incidents.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.designgurus.io/blog/system-design-patterns-complete-guide" rel="noopener noreferrer"&gt;DesignGurus.io&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>programming</category>
      <category>interview</category>
    </item>
    <item>
      <title>I've taught system design to hundreds of engineers. Here's where I tell them all to start.</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Sat, 04 Jul 2026 03:54:11 +0000</pubDate>
      <link>https://dev.to/arslan_ah/ive-taught-system-design-to-hundreds-of-engineers-heres-where-i-tell-them-all-to-start-3p7g</link>
      <guid>https://dev.to/arslan_ah/ive-taught-system-design-to-hundreds-of-engineers-heres-where-i-tell-them-all-to-start-3p7g</guid>
      <description>&lt;p&gt;Somewhere around the hundredth engineer I coached, I noticed something. Nobody was struggling with system design because it was too hard. They were struggling because they started in the wrong place.&lt;/p&gt;

&lt;p&gt;The pattern was always the same. A smart engineer with two or three years of experience decides it's time to learn system design. They search YouTube, land on "Design Instagram in 45 minutes," and watch someone draw fifteen boxes connected by arrows. They understand maybe four of the boxes. They finish the video feeling like they learned something, try to design anything on their own, and produce a server, a database, and silence.&lt;/p&gt;

&lt;p&gt;Then they conclude system design is a genius-only club, and they either give up or start memorizing diagrams.&lt;/p&gt;

&lt;p&gt;If that's you, nothing is wrong with you. You just entered the building through the roof.&lt;/p&gt;

&lt;h2&gt;
  
  
  The lie that keeps beginners stuck
&lt;/h2&gt;

&lt;p&gt;Here's what I wish someone had told me when I was coming up through Microsoft and Facebook: &lt;strong&gt;system design is not as big as it looks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It looks infinite because content about it has no agreed-upon sequence. Every blog post assumes you already know whatever the last blog post covered. Every video introduces five terms it never defines. There's no "chapter one" anywhere on the front page of Google.&lt;/p&gt;

&lt;p&gt;But strip the noise away and the field that matters for interviews and for real engineering work reduces to roughly 12 recurring patterns, combined in different ways. Netflix is not magic. Uber is not magic. They're the same dozen ideas arranged for different constraints.&lt;/p&gt;

&lt;p&gt;You cannot see that from the roof. You can only see it from the foundation.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 5 concepts I make everyone learn first
&lt;/h2&gt;

&lt;p&gt;When someone asks me where to start, I give them the same assignment every time: learn these five things, and don't touch a case study until you can explain each one to a non-engineer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The client-server model.&lt;/strong&gt; A client asks, a server answers. Every system you will ever design begins with "the client sends a request to our API server." If this sentence isn't boring and obvious to you yet, everything downstream will feel like fog.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Databases.&lt;/strong&gt; Where data lives when the power goes out. You need exactly one distinction at this stage: SQL databases are structured and relational, NoSQL databases are flexible and easier to scale horizontally. That's it. Do not fall down the "PostgreSQL vs Cassandra vs DynamoDB" rabbit hole in week one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. APIs.&lt;/strong&gt; The contracts that let pieces of software talk to each other without knowing each other's internals. In a design discussion, APIs are the seams of your architecture: where you cut, and where things can change independently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Load balancing.&lt;/strong&gt; One server can't handle a million users, so you run fifty servers, and something has to decide which request goes where. That something is a load balancer, and it appears in every design answer you will ever give. Think of a restaurant hostess distributing guests across tables so no waiter drowns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Caching.&lt;/strong&gt; Databases are slow compared to memory. If a million people request the same homepage feed, computing it a million times is waste. Store the answer once in RAM, serve it a million times in microseconds. Most of "making systems fast" is some version of this idea.&lt;/p&gt;

&lt;p&gt;That's the whole first week. Five concepts. Engineers are usually suspicious of how small this list is, and then a month later they tell me it's the reason the rest finally made sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this order beats the "just watch case studies" approach
&lt;/h2&gt;

&lt;p&gt;Case studies are the best part of learning system design. They're also nearly worthless if you do them first.&lt;/p&gt;

&lt;p&gt;When you watch "Design a URL Shortener" without knowing the building blocks, you're memorizing a specific answer. When the constraints change ("what if reads are 100x writes?"), the memorized answer shatters, because you never knew &lt;em&gt;why&lt;/em&gt; the cache was there in the first place.&lt;/p&gt;

&lt;p&gt;When you do the same case study &lt;em&gt;after&lt;/em&gt; learning the blocks, you're doing something completely different: you're practicing selection. You know what a cache does, so the question becomes "does this system need one, and where?" That's the actual skill interviewers grade. It's also the actual skill your job requires.&lt;/p&gt;

&lt;p&gt;Same video. Same diagram. Entirely different learning outcome, purely based on what you knew walking in.&lt;/p&gt;

&lt;h2&gt;
  
  
  The sequence that works
&lt;/h2&gt;

&lt;p&gt;After the first five concepts, the path I give people looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Learn the next 7 building blocks&lt;/strong&gt;: sharding, replication, consistency models, message queues, CDNs, indexing, and back-of-the-envelope estimation. Same rule as before: understand what problem each one solves, skip the depth.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Learn a framework.&lt;/strong&gt; Requirements, estimation, API, data model, high-level architecture, deep dives, trade-offs. In that order, every time. A framework turns "design Twitter" from a blank-whiteboard panic into a sequence of small, answerable questions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Now do case studies.&lt;/strong&gt; Start with the URL shortener, then a chat app, then a news feed. Attempt each one yourself, out loud, for 45 minutes before you look at any solution. The gap between your answer and the reference answer is your personalized curriculum.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice out loud, with a human if possible.&lt;/strong&gt; System design interviews are conversations, not exams. I've seen engineers who knew plenty fail because the first time they'd ever articulated a trade-off verbally was in the actual interview.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spread over eight weeks at an hour or two a day, this takes someone from "what's a load balancer?" to holding a coherent 45-minute design conversation. I've written the full week-by-week version, with links for every concept, in my &lt;a href="https://www.designgurus.io/blog/system-design-for-beginners" rel="noopener noreferrer"&gt;system design roadmap for beginners&lt;/a&gt; if you want the detailed plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three failure modes to watch for
&lt;/h2&gt;

&lt;p&gt;After enough repetitions, I can predict how someone will get stuck before they start:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The memorizer&lt;/strong&gt; collects architecture diagrams like trading cards and freezes the moment an interviewer changes one constraint. Fix: for every component in a design, force yourself to answer "what breaks if I remove this?"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The roof-jumper&lt;/strong&gt; goes straight to "Design WhatsApp" content and drowns in jargon. Fix: the five concepts above, first, no exceptions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The passive consumer&lt;/strong&gt; watches 30 hours of videos, feels fluent, and can't produce a design from a blank page. Fix: never end a study session without explaining what you learned out loud, to a rubber duck if necessary.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All three failure modes share a root cause: consuming content feels like progress, and applying concepts feels like struggle. The struggle is the part that works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start smaller than feels reasonable
&lt;/h2&gt;

&lt;p&gt;If you take one thing from this post, make it this: the engineers who get good at system design are not the ones who were smarter. They're the ones who started with embarrassingly basic material and actually practiced it, while everyone else skipped ahead and silently churned.&lt;/p&gt;

&lt;p&gt;Client-server. Databases. APIs. Load balancing. Caching. Learn those five this week, explain each one out loud to someone patient, and you'll be ahead of most people grinding case study videos.&lt;/p&gt;

&lt;p&gt;And when you're ready for the structured version of the whole journey, the &lt;a href="https://www.designgurus.io/blog/system-design-for-beginners" rel="noopener noreferrer"&gt;full 8-week roadmap&lt;/a&gt; is free, and my &lt;a href="https://www.designgurus.io/course/grokking-system-design-fundamentals" rel="noopener noreferrer"&gt;System Design Fundamentals&lt;/a&gt; course covers the building-blocks phase in one sequenced curriculum if you'd rather not assemble it yourself.&lt;/p&gt;

&lt;p&gt;You don't need to be a distributed-systems wizard to start. You need chapter one. Now you have it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What tripped you up when you started learning system design? I read every comment.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>beginners</category>
      <category>architecture</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>System Design Fundamentals: The 10 Building Blocks to Learn First</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Thu, 02 Jul 2026 12:57:22 +0000</pubDate>
      <link>https://dev.to/arslan_ah/system-design-fundamentals-the-10-building-blocks-to-learn-first-2754</link>
      <guid>https://dev.to/arslan_ah/system-design-fundamentals-the-10-building-blocks-to-learn-first-2754</guid>
      <description>&lt;p&gt;Most people learn system design backwards. They start by reading how Netflix or Uber is built, memorize the finished architecture, and then freeze the moment they're asked to design something slightly different.&lt;/p&gt;

&lt;p&gt;The fix is to learn the &lt;em&gt;parts&lt;/em&gt; before the &lt;em&gt;whole&lt;/em&gt;. Every large system is assembled from a small set of reusable building blocks. Once you understand each block on its own, designing a full system becomes an exercise in choosing which blocks to combine and why. This post covers the 10 to learn first, in a sensible order, so you have the vocabulary before you attempt your first design. If you want to see where these fit in the bigger picture, here's a structured roadmap to &lt;a href="https://www.designgurus.io/learn-system-design" rel="noopener noreferrer"&gt;learn system design&lt;/a&gt; at your level.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to study each block: solves, costs, when
&lt;/h2&gt;

&lt;p&gt;Do not just memorize what each component &lt;em&gt;is&lt;/em&gt;. For every block, learn three things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What it solves.&lt;/strong&gt; The specific problem that makes you reach for it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What it costs.&lt;/strong&gt; The new problem it introduces (every block adds one).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When to use it.&lt;/strong&gt; The signal in a design that says "now I need this."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That third habit is what separates people who can design real systems from people who can only recite them. Keep those three columns in mind as you read.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Load Balancer
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; A traffic cop that sits in front of multiple servers and spreads incoming requests across them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; A single server can only handle so much. A load balancer lets you run many identical servers and distribute load, which gives you both scale and redundancy (if one server dies, traffic routes to the others).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; It becomes a component you have to make highly available itself, and it forces your servers to be stateless (or you have to deal with sticky sessions).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; The moment you say "one server isn't enough" or "what happens if this server goes down."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuarnmfttxhmx0aib1hq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuarnmfttxhmx0aib1hq1.png" alt="Load Balancer" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Caching
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; A fast, temporary store for data you access often, sitting between your app and a slower source (like a database).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; Latency and load. Reading from memory is orders of magnitude faster than hitting a database, and it takes pressure off your data store.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; Staleness. The cached copy can drift from the source of truth, so now you own cache invalidation, famously one of the hard problems in computing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; Read-heavy workloads, or any time the same data is requested over and over.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiypoupn9xzwnf2k8vb7z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiypoupn9xzwnf2k8vb7z.png" alt="Caching" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Database Replication
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Keeping copies of your database on multiple machines, usually one primary (writes) and several replicas (reads).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; Read scalability and availability. You can spread reads across replicas, and if the primary fails, a replica can take over.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; Replication lag. Replicas can be slightly behind the primary, so a user might not immediately see their own write. That's the consistency trade-off.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; When reads vastly outnumber writes, or when you can't afford to lose the database if one machine fails.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Database Sharding
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Splitting one large database into smaller pieces (shards), each holding a subset of the data, spread across machines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; Write scalability and storage limits. When the data or write volume outgrows a single machine, sharding partitions the load.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; A large jump in complexity. Cross-shard queries get hard, and choosing a bad shard key creates "hot" shards that defeat the whole purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; When a single database server can no longer hold your data or absorb your writes, and only then. Replication first, sharding later.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Message Queue
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; A buffer that holds messages so one part of your system can hand off work to another without waiting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; Decoupling and load smoothing. Producers and consumers work at their own pace, and traffic spikes get absorbed by the queue instead of crushing a service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; Added latency (work is now asynchronous) and new failure modes (duplicate messages, ordering, what happens when the queue backs up).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; When work can happen later rather than instantly (sending emails, processing uploads, generating notifications).&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Consistent Hashing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; A clever way to distribute data across a changing set of servers so that adding or removing a server only moves a small fraction of the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; The rehashing problem. With naive hashing, adding one server reshuffles almost everything. Consistent hashing keeps that disruption minimal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; Conceptual complexity, and the need for tricks like virtual nodes to keep the distribution even.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; Any time you're distributing data or requests across a cluster whose size changes (caches, sharded stores). I broke this one down step by step in &lt;a href="https://dev.to/arslan_ah/how-to-use-consistent-hashing-in-a-system-design-interview-33ge"&gt;consistent hashing in a system design interview&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. CDN (Content Delivery Network)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; A globally distributed network of servers that cache your static content close to users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; Latency for a global audience. Serving an image or video from a city near the user is far faster than from one origin server across the world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; Cost, plus cache invalidation again (pushing updates to edge locations takes time).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; When you serve static assets (images, video, JS/CSS) to users spread across regions.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Rate Limiter
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; A guard that caps how many requests a client can make in a given window.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; Abuse and overload. It protects your system from being overwhelmed, whether by malicious traffic, buggy clients, or a single user hammering an endpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; You have to store and check counters fast (often in a cache), and you have to decide what to do with rejected requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; Any public API, login endpoint, or any resource you need to protect from spikes and abuse.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Database Indexing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; A data structure that lets the database find rows without scanning the entire table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; Slow reads. An index turns a full-table scan into a fast lookup, dramatically speeding up queries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; Slower writes (every write must update the index) and extra storage. Over-indexing is a real mistake.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; When a query is slow and it filters or sorts on a specific column. This is often the cheapest performance win available.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Data Modeling
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Deciding how your data is structured and stored: relational tables versus documents, how entities relate, what you optimize for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it solves:&lt;/strong&gt; Almost everything downstream. The right model makes your common queries easy and fast; the wrong one makes every later decision harder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it costs:&lt;/strong&gt; Time and foresight up front, and the reality that changing the model later is painful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to reach for it:&lt;/strong&gt; First. Before you pick components, understand your data and its access patterns. This is the foundation the other nine blocks sit on.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the blocks combine
&lt;/h2&gt;

&lt;p&gt;Here's the payoff. Take a simple service and watch the blocks appear as constraints arrive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with one server and a database (data modeling).&lt;/li&gt;
&lt;li&gt;Traffic grows, so you add more servers behind a &lt;strong&gt;load balancer&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Reads are slow, so you add a &lt;strong&gt;cache&lt;/strong&gt; and some &lt;strong&gt;indexes&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Reads still outpace one database, so you add &lt;strong&gt;replication&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The data outgrows one machine, so you &lt;strong&gt;shard&lt;/strong&gt; it (using &lt;strong&gt;consistent hashing&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;Some work doesn't need to be instant, so you offload it to a &lt;strong&gt;message queue&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Users are global, so static assets move to a &lt;strong&gt;CDN&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The public API needs protection, so you add a &lt;strong&gt;rate limiter&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every block entered the design because a specific problem demanded it, not because a checklist said so. That's exactly how you should reason in a real design.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;Learn these 10 in roughly the order above (data modeling first, sharding and consistent hashing last, since they're the most advanced). Write your own three-line summary for each: solves, costs, when. Then start composing them into full systems.&lt;/p&gt;

&lt;p&gt;If you're brand new and even the prerequisites feel shaky, start with &lt;a href="https://dev.to/arslan_ah/how-to-learn-system-design-from-scratch-with-no-distributed-systems-experience-1591"&gt;learning system design from scratch&lt;/a&gt;. And when you're ready to see how deep each block should go at your career stage, follow the full path in this &lt;a href="https://dev.to/arslan_ah/how-to-learn-system-design-a-roadmap-by-career-level-3e01"&gt;roadmap by career level&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Master the parts, and the whole stops being intimidating. Every "complex" architecture you've ever admired is just these blocks, combined to answer specific constraints.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>How to Learn System Design From Scratch (With No Distributed Systems Experience)</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Tue, 30 Jun 2026 21:24:53 +0000</pubDate>
      <link>https://dev.to/arslan_ah/how-to-learn-system-design-from-scratch-with-no-distributed-systems-experience-1591</link>
      <guid>https://dev.to/arslan_ah/how-to-learn-system-design-from-scratch-with-no-distributed-systems-experience-1591</guid>
      <description>&lt;p&gt;If you have ever opened a system design article, seen a diagram with twelve boxes, three databases, a message queue, and the words "eventually consistent," and quietly closed the tab, this post is for you.&lt;/p&gt;

&lt;p&gt;There is a myth that you need years of experience running large systems before you can learn system design. You don't. Plenty of engineers learn it before they have ever deployed anything bigger than a side project. What you actually need is the right starting point and a way to build intuition without access to production-scale traffic. That is exactly what this guide gives you.&lt;/p&gt;

&lt;h2&gt;
  
  
  "But I've never built anything at scale"
&lt;/h2&gt;

&lt;p&gt;Good news: neither had most people the first time they learned this. System design is not a memory test about how Uber works. It is a &lt;em&gt;thinking&lt;/em&gt; skill: given a vague problem and some constraints, make a sequence of reasonable trade-offs and explain them clearly.&lt;/p&gt;

&lt;p&gt;That skill does not require having operated a system serving millions of users. It requires understanding what the moving parts do and practicing the reasoning. The experience helps later, but it is not the price of entry. So drop the idea that you are "not ready." You are ready to start today.&lt;/p&gt;

&lt;h2&gt;
  
  
  The honest minimum prerequisites
&lt;/h2&gt;

&lt;p&gt;You do not need much, but you do need these four things. If any feels shaky, spend a few days here first; it will save you weeks of confusion later.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What happens when you load a web page.&lt;/strong&gt; Client sends a request, DNS resolves a name to an address, a server responds. If you can sketch that, you're fine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The two kinds of databases.&lt;/strong&gt; Relational (tables, rows, SQL) versus non-relational (documents, key-value). You don't need to be an expert, just know they exist and roughly when each fits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What an index is.&lt;/strong&gt; A way to find data fast without scanning everything. That one sentence is enough to begin.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Basic estimation.&lt;/strong&gt; If something gets a million requests a day, roughly how many is that per second? (About 12, for the record.) The ability to do rough math out loud matters more than precision.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Notice what is &lt;em&gt;not&lt;/em&gt; on this list: Kubernetes, Kafka, distributed consensus, the CAP theorem. Beginners reach for those far too early. You will learn them when a problem actually demands them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The mindset shift that unlocks everything
&lt;/h2&gt;

&lt;p&gt;Beginners try to learn system design by collecting answers: how is Instagram's feed built, how does WhatsApp deliver messages, how does YouTube store video. They memorize a dozen "reference architectures" and feel productive.&lt;/p&gt;

&lt;p&gt;Then they get asked to design something slightly different, and nothing transfers.&lt;/p&gt;

&lt;p&gt;The fix is to learn &lt;em&gt;reasoning&lt;/em&gt;, not answers. For every component you study, learn two things: &lt;strong&gt;what problem it solves&lt;/strong&gt; and &lt;strong&gt;what new problem it creates.&lt;/strong&gt; A cache makes reads fast (solves latency) but can serve stale data (creates a consistency problem). A queue smooths traffic spikes (solves load) but adds delay and complexity (creates new failure modes). Once you think in those trade-offs, you can design things you have never seen before. That is the whole game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your first design: build it, don't read it
&lt;/h2&gt;

&lt;p&gt;Reading designs builds recognition. Building one builds competence. So for your very first system, pick something small enough to finish in one sitting and deep enough to teach the core ideas. The classic choice is a URL shortener (think bit.ly), and it is the perfect no-experience starter.&lt;/p&gt;

&lt;p&gt;Here is the trick that makes it work: &lt;strong&gt;start with the dumbest possible version, then break it on purpose.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Version 1, the naive design.&lt;/strong&gt; One server, one database. A user submits a long URL, you generate a short code, store the pair, and redirect on lookup. That's it. It works for ten users. Congratulations, you have designed a system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Now add a constraint.&lt;/strong&gt; "It needs to handle 100 million redirects a day." Suddenly your single database read on every redirect is a problem. What solves slow reads? A cache. So you add one. (And now you own the staleness trade-off you just learned about.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add another.&lt;/strong&gt; "Short codes must never collide." Now you have to think about how codes are generated: random with a uniqueness check, or a counter, or a hash. Each has trade-offs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add one more.&lt;/strong&gt; "One database server can't hold all the data." Now you need to split it across machines, which is your gentle introduction to sharding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See what happened? Each constraint forced &lt;em&gt;exactly one&lt;/em&gt; new idea, and you learned that idea because you needed it, not because a textbook listed it. That is how real systems grow, and it is how you should learn. For a full worked version of this exact problem, see my walkthrough of &lt;a href="https://dev.to/arslan_ah/system-design-interview-question-designing-a-url-shortening-service-4029"&gt;designing a URL shortening service&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to build intuition without a production system
&lt;/h2&gt;

&lt;p&gt;You can't experiment on real traffic yet, so build intuition these three ways instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Read with a question, not a highlighter.&lt;/strong&gt; When you read how a real system works, stop at each component and ask "what would break if they removed this?" If you can answer, you understand it. If you can't, that's the part to study next.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build small versions for real.&lt;/strong&gt; A rate limiter is a weekend project. A simple key-value cache is a weekend project. A basic message queue is a weekend project. Building a tiny version teaches you more than reading about the big version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reason about apps you already use.&lt;/strong&gt; Every time you use an app, ask one design question. Why does the like count sometimes look slightly off? (Probably caching.) Why can you send a message offline and it sends later? (Probably a queue.) You are surrounded by free case studies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A 4-week beginner ramp
&lt;/h2&gt;

&lt;p&gt;If you want a path instead of a pile of topics, here is a realistic one. Forty focused minutes a day beats a frantic weekend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 1: Foundations.&lt;/strong&gt; One building block per day: load balancer, cache, database replication, sharding, message queue. For each, write three sentences (what it solves, what it costs, when to use it).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 2: Your first systems.&lt;/strong&gt; Design the URL shortener end to end, evolving it under constraints as shown above. Then do a second small one (a pastebin or a basic image host) the same way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 3: A bigger system.&lt;/strong&gt; Attempt a news feed or a chat app. You will get stuck. That is the point; the stuck moments tell you exactly what to study next.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 4: Practice out loud.&lt;/strong&gt; Re-design two earlier systems from a blank page, talking through every decision as if explaining to someone. If you can't explain a choice, you haven't learned it yet.&lt;/p&gt;

&lt;p&gt;After four weeks you won't be a senior architect, but you will no longer be a beginner, and you will know how to keep going.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beginner mistakes to skip
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Starting with the "impressive" architecture.&lt;/strong&gt; Microservices and Kafka on day one is a red flag, not a flex. Start simple, justify every addition.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memorizing reference designs.&lt;/strong&gt; You will be asked something off-script. Learn the reasoning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Studying components you never use.&lt;/strong&gt; You don't need to deeply understand distributed consensus to design a URL shortener. Learn things when a problem demands them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practicing silently.&lt;/strong&gt; System design is a communication skill. If you only think it through in your head, you are training the wrong muscle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skipping the math.&lt;/strong&gt; "It scales" is not an answer. Rough numbers are what justify your choices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Do I really not need experience with big systems?&lt;/strong&gt;&lt;br&gt;
Correct. Experience accelerates intuition later, but the building-block-then-composition path works fine without it. Many engineers learn system design before ever operating one at scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How long until I'm "good"?&lt;/strong&gt;&lt;br&gt;
For a solid beginner foundation, about 4 weeks of consistent practice. Genuine mastery is a multi-year, on-the-job journey, and that's normal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is this only useful for interviews?&lt;/strong&gt;&lt;br&gt;
No. The same skill (making and defending trade-offs) is exactly what you do when designing real systems at work. Interview prep is just a concentrated version of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to go next
&lt;/h2&gt;

&lt;p&gt;Once the fundamentals click, the natural next step is to study what depth is expected at each stage of your career. When you're ready, here's &lt;a href="https://www.designgurus.io/learn-system-design" rel="noopener noreferrer"&gt;where to start learning system design&lt;/a&gt; with a level-by-level path, and a companion roadmap that lays out the same journey &lt;a href="https://dev.to/arslan_ah/how-to-learn-system-design-a-roadmap-by-career-level-3e01"&gt;as a roadmap by career level&lt;/a&gt;. And when the interview itself is on the calendar, &lt;a href="https://arslan-ahmad.medium.com/the-complete-system-design-interview-guide-for-2027-85a1ab94ace7" rel="noopener noreferrer"&gt;The Complete System Design Interview Guide for 2027&lt;/a&gt; covers the framework, the scoring signals, and a full worked example.&lt;/p&gt;

&lt;p&gt;The engineers who get good at this are not the ones who read the most. They are the ones who designed the most systems out loud, starting with the dumbest possible version and letting the constraints teach them. You can start that today, with zero experience. Pick the URL shortener, build the naive version, then break it.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>beginners</category>
      <category>career</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Learn System Design: A Roadmap by Career Level</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Mon, 29 Jun 2026 10:53:47 +0000</pubDate>
      <link>https://dev.to/arslan_ah/how-to-learn-system-design-a-roadmap-by-career-level-3e01</link>
      <guid>https://dev.to/arslan_ah/how-to-learn-system-design-a-roadmap-by-career-level-3e01</guid>
      <description>&lt;p&gt;Most engineers do not struggle with system design because they lack intelligence. They struggle because the topic has no obvious starting point and no obvious finish line. Coding has LeetCode. System design has... a thousand blog posts, a few thick books, and a lot of hand-waving about "scalability."&lt;/p&gt;

&lt;p&gt;This guide fixes the starting-point problem. It lays out how to learn system design as a sequence: what to learn first, what to learn next, and what "good enough" looks like at each stage of your career. If you want the fuller, continuously updated version, Design Gurus maintains a structured guide on &lt;a href="https://www.designgurus.io/learn-system-design" rel="noopener noreferrer"&gt;how to learn system design&lt;/a&gt; organized by career level. This article gives you the condensed roadmap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning system design is not memorizing architectures
&lt;/h2&gt;

&lt;p&gt;The most common mistake is treating system design like trivia: memorize how Twitter's feed works, how Uber matches drivers, how a URL shortener generates keys. You can recite all of it and still freeze when asked to design something you have not seen.&lt;/p&gt;

&lt;p&gt;System design is a &lt;em&gt;skill&lt;/em&gt;, not a &lt;em&gt;fact set&lt;/em&gt;. The skill is this: given a vague problem and real constraints, make a sequence of defensible trade-offs and communicate them clearly. Everything below is built to train that skill, not to pad your memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites: what you need before you start
&lt;/h2&gt;

&lt;p&gt;You do not need to be a senior engineer to begin, but you do need a few fundamentals. If any of these are shaky, shore them up first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Networking basics:&lt;/strong&gt; what happens when a client calls a server (DNS, TCP, HTTP, status codes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Databases:&lt;/strong&gt; the difference between a relational and a non-relational store, what an index is, what a transaction is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Concurrency basics:&lt;/strong&gt; what a race condition is, why shared state is hard.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Back-of-the-envelope math:&lt;/strong&gt; powers of two, latency numbers, how to estimate QPS and storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you can comfortably explain those at a whiteboard, you are ready.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three-phase learning path
&lt;/h2&gt;

&lt;p&gt;Every effective learning sequence I have seen follows the same arc. Skipping a phase is the fastest way to plateau.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 1: Foundations (learn the building blocks in isolation)
&lt;/h3&gt;

&lt;p&gt;Before you compose a system, you need to understand its parts well enough to know when each one applies. Learn these one at a time, and for each, learn &lt;em&gt;what problem it solves&lt;/em&gt; and &lt;em&gt;what it costs&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Load balancers&lt;/li&gt;
&lt;li&gt;Caching (and cache invalidation strategies)&lt;/li&gt;
&lt;li&gt;Database replication and sharding&lt;/li&gt;
&lt;li&gt;Message queues and asynchronous processing&lt;/li&gt;
&lt;li&gt;Consistent hashing&lt;/li&gt;
&lt;li&gt;CDNs&lt;/li&gt;
&lt;li&gt;Rate limiting&lt;/li&gt;
&lt;li&gt;Indexing and data modeling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not move on until you can answer, for each: "When would I add this, and what new problem does adding it create?" Caching, for example, solves latency but creates staleness. That trade-off framing is the entire game.&lt;/p&gt;

&lt;p&gt;For a deeper breakdown of each block (what it solves, what it costs, and when to reach for it), see &lt;a href="https://dev.to/arslan_ah/system-design-fundamentals-the-10-building-blocks-to-learn-first-2754"&gt;the 10 system design building blocks to learn first&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 2: Composition (assemble blocks into systems)
&lt;/h3&gt;

&lt;p&gt;Now combine the blocks. Take a classic prompt and build it up incrementally. A good first target is a URL shortener: simple enough to finish, deep enough to touch key generation, storage, caching, and read/write skew.&lt;/p&gt;

&lt;p&gt;The key habit here is to &lt;strong&gt;start simple and evolve under pressure&lt;/strong&gt;. Begin with the naive single-server design, then introduce a constraint ("now it serves 100M requests a day") and react to it. Each constraint should force exactly one architectural change. That is how real systems grow, and it is how interviewers expect you to think.&lt;/p&gt;

&lt;p&gt;Work through 8 to 12 canonical systems this way: a news feed, a chat app, a rate limiter, a typeahead service, a video platform, a ride-sharing matcher, a notification system. The repetition builds pattern recognition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 3: Practice (perform under realistic conditions)
&lt;/h3&gt;

&lt;p&gt;Reading designs builds recognition. Producing them under a clock builds competence. In this phase you design out loud, on a timer, ideally with someone pushing back. The full &lt;a href="https://www.designgurus.io/learn-system-design" rel="noopener noreferrer"&gt;system design learning roadmap by level&lt;/a&gt; breaks down how much practice each career stage actually needs, but the principle is constant: you only own a concept once you can explain it without notes.&lt;/p&gt;

&lt;p&gt;The most realistic version of this is a full mock interview. This &lt;a href="https://www.designgurus.io/blog/system-design-mock-interview" rel="noopener noreferrer"&gt;guide to system design mock interviews&lt;/a&gt; explains how a 45-minute mock is structured and scored, and compares solo, peer, expert, and AI practice options.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn at each career level
&lt;/h2&gt;

&lt;p&gt;"Learn system design" means different things depending on where you are. Calibrate your depth to your target level so you neither under-prepare nor waste months on staff-level concerns you will not be asked about.&lt;/p&gt;

&lt;h3&gt;
  
  
  Junior (L3)
&lt;/h3&gt;

&lt;p&gt;The bar is fundamentals, not novel architecture. You should be able to design a basic CRUD service, expose a clean API, pick a reasonable database, and explain a single caching layer. Depth of building blocks matters more than breadth of systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mid-level (L4)
&lt;/h3&gt;

&lt;p&gt;Now you compose. You should design a complete system end to end, identify bottlenecks, and reason about scaling reads vs writes. You are expected to know when to shard, when to add a queue, and what consistency model fits the use case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Senior (L5)
&lt;/h3&gt;

&lt;p&gt;The focus shifts to trade-offs and justification. Two valid designs exist for almost every problem; your job is to pick one and defend it against the alternative. Expect deep dives: "Walk me through exactly how you keep the cache consistent here." Non-functional requirements (availability, latency targets, cost) drive your decisions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Staff and above (L6+)
&lt;/h3&gt;

&lt;p&gt;The scope widens beyond one system to platforms and organizations. You reason about evolvability, migration paths, failure domains, multi-region strategy, and the human cost of operating what you propose. The question is less "does it work" and more "will this still be the right call in three years."&lt;/p&gt;

&lt;h2&gt;
  
  
  A concrete weekly cadence
&lt;/h2&gt;

&lt;p&gt;If you want a plan rather than a pile of topics, here is a sustainable rhythm:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Weeks 1 to 2:&lt;/strong&gt; One building block per day from Phase 1. Write a three-sentence summary of each (problem it solves, cost it adds, when to reach for it).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weeks 3 to 5:&lt;/strong&gt; One full system every two days from Phase 2, evolving each from naive to scaled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weeks 6 onward:&lt;/strong&gt; Timed mock designs from Phase 3, two per week, reviewed honestly afterward.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consistency beats intensity. Forty focused minutes a day will outperform a frantic weekend cram every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes that stall people
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Jumping to the "impressive" architecture immediately.&lt;/strong&gt; Start with the simplest thing that works, then justify each addition. Leading with Kafka and microservices for a problem that needs neither is a red flag.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memorizing reference designs.&lt;/strong&gt; You will be asked something off-script. Learn the reasoning, not the diagram.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring requirements.&lt;/strong&gt; Spending zero time clarifying scope and then designing the wrong system is the most common failure mode, and the most avoidable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practicing silently.&lt;/strong&gt; System design is a communication exercise. If you only practice in your head, you are training the wrong muscle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skipping the math.&lt;/strong&gt; "It scales" is not an answer. Numbers (QPS, storage, bandwidth) are what justify your choices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How long does it take to learn system design?&lt;/strong&gt;&lt;br&gt;
For interview readiness, most engineers need 4 to 8 weeks of consistent practice on top of solid fundamentals. Genuine mastery is a multi-year, on-the-job process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need real distributed-systems experience first?&lt;/strong&gt;&lt;br&gt;
No. Experience helps, but the building-block-then-composition path works without it. Plenty of engineers learn this before they have ever operated a large system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is system design only for interviews?&lt;/strong&gt;&lt;br&gt;
No. The same skill (making and defending architectural trade-offs) is exactly what you do when designing real systems at work. Interview prep is just a focused version of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need real distributed-systems experience first?&lt;/strong&gt;&lt;br&gt;
No. Experience helps, but the building-block-then-composition path works without it. Plenty of engineers learn this before they have ever operated a large system. If you're starting from zero, I wrote a companion guide on &lt;a href="https://dev.to/arslan_ah/how-to-learn-system-design-from-scratch-with-no-distributed-systems-experience-1591"&gt;learning system design from scratch with no experience&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to go next
&lt;/h2&gt;

&lt;p&gt;Pick your level, start at Phase 1, and do not skip ahead. If you want the structured, regularly updated version of this path with level-specific checklists, work through Design Gurus' guide on &lt;a href="https://www.designgurus.io/learn-system-design" rel="noopener noreferrer"&gt;how to learn system design&lt;/a&gt;. And when you are ready to drill full problems with worked solutions, &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt; walks through the canonical systems end to end.&lt;/p&gt;

&lt;p&gt;The engineers who get good at this are not the ones who read the most. They are the ones who designed the most systems out loud. Start today, start simple, and let the constraints teach you.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>programming</category>
      <category>interview</category>
      <category>career</category>
    </item>
    <item>
      <title>Must-do system design questions.</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Thu, 25 Jun 2026 11:39:21 +0000</pubDate>
      <link>https://dev.to/arslan_ah/must-do-system-design-questions-4n46</link>
      <guid>https://dev.to/arslan_ah/must-do-system-design-questions-4n46</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m" class="crayons-story__hidden-navigation-link"&gt;64 System Design Interview Questions, Ranked From Easiest to Hardest&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/arslan_ah" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F34147%2F2974e0a5-f688-45b5-a4c9-5fa49c257854.jpg" alt="arslan_ah profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/arslan_ah" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Arslan Ahmad
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Arslan Ahmad
                
              
              &lt;div id="story-author-preview-content-3488973" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/arslan_ah" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F34147%2F2974e0a5-f688-45b5-a4c9-5fa49c257854.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Arslan Ahmad&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Apr 12&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m" id="article-link-3488973"&gt;
          64 System Design Interview Questions, Ranked From Easiest to Hardest
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/systemdesign"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;systemdesign&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/softwaredevelopment"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;softwaredevelopment&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/interview"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;interview&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;16&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            19 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>architecture</category>
      <category>career</category>
      <category>interview</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>AI System Design Interview Questions: ChatGPT, RAG, LLM Inference, and Agents</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Thu, 25 Jun 2026 11:38:22 +0000</pubDate>
      <link>https://dev.to/arslan_ah/ai-system-design-interview-questions-chatgpt-rag-llm-inference-and-agents-1doi</link>
      <guid>https://dev.to/arslan_ah/ai-system-design-interview-questions-chatgpt-rag-llm-inference-and-agents-1doi</guid>
      <description>&lt;p&gt;System design interviews are changing.&lt;/p&gt;

&lt;p&gt;Traditional questions such as “Design Twitter,” “Design Uber,” and “Design YouTube” are still important. They test whether you understand databases, caching, partitioning, replication, messaging, and high availability.&lt;/p&gt;

&lt;p&gt;But engineers working on modern platforms now encounter a different category of problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Design a ChatGPT-like conversational assistant.&lt;/li&gt;
&lt;li&gt;Design a retrieval-augmented generation system.&lt;/li&gt;
&lt;li&gt;Design an LLM inference platform.&lt;/li&gt;
&lt;li&gt;Design an AI agent that can call external tools.&lt;/li&gt;
&lt;li&gt;Design an enterprise AI assistant for private documents.&lt;/li&gt;
&lt;li&gt;Design an evaluation platform for generative AI applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions still require classical distributed-systems knowledge. An AI product needs APIs, queues, storage, authentication, observability, rate limiting, and reliable deployment.&lt;/p&gt;

&lt;p&gt;The difference is that it also introduces expensive accelerators, probabilistic output, long-running requests, model routing, vector retrieval, prompt construction, safety controls, and quality evaluation.&lt;/p&gt;

&lt;p&gt;This guide explains the most important AI system design interview questions and what a strong candidate should discuss for each.&lt;/p&gt;

&lt;p&gt;For a broader preparation roadmap covering traditional and modern problems, see &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m"&gt;64 System Design Interview Questions, Ranked From Easiest to Hardest&lt;/a&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why AI System Design Is Different
&lt;/h1&gt;

&lt;p&gt;A conventional service usually transforms an input into a deterministic output.&lt;/p&gt;

&lt;p&gt;If a user requests order number 123, the service should retrieve order 123. Two identical requests should usually return the same underlying information.&lt;/p&gt;

&lt;p&gt;Generative AI systems behave differently.&lt;/p&gt;

&lt;p&gt;A model may produce different responses to the same prompt. A response can be grammatically convincing while being factually wrong. Latency depends on the number of generated tokens. Serving capacity is constrained by accelerator memory, not merely CPU utilization. Product quality may depend on prompts, retrieved context, model versions, safety filters, and external tools.&lt;/p&gt;

&lt;p&gt;This creates several new design dimensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Quality is part of the architecture
&lt;/h2&gt;

&lt;p&gt;Traditional systems are often measured using availability, latency, throughput, and error rate.&lt;/p&gt;

&lt;p&gt;AI systems need those metrics, but they also need measures such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer correctness&lt;/li&gt;
&lt;li&gt;Relevance&lt;/li&gt;
&lt;li&gt;Groundedness&lt;/li&gt;
&lt;li&gt;Retrieval quality&lt;/li&gt;
&lt;li&gt;Hallucination rate&lt;/li&gt;
&lt;li&gt;Tool-use success&lt;/li&gt;
&lt;li&gt;Safety-policy compliance&lt;/li&gt;
&lt;li&gt;User satisfaction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A system that returns a response in 200 milliseconds is not useful if that response is wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Requests are computationally expensive
&lt;/h2&gt;

&lt;p&gt;An ordinary API server may process thousands of lightweight requests per second.&lt;/p&gt;

&lt;p&gt;An LLM request can occupy expensive GPU memory while processing a long prompt and generating hundreds of tokens. The architecture must therefore optimize batching, memory utilization, model placement, and request scheduling.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Latency is experienced as a stream
&lt;/h2&gt;

&lt;p&gt;Users do not normally wait for an entire answer before seeing anything. Tokens are streamed as they are generated.&lt;/p&gt;

&lt;p&gt;This introduces at least two important latency measurements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time to first token:&lt;/strong&gt; How quickly generation begins.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inter-token latency:&lt;/strong&gt; How smoothly subsequent tokens arrive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A system may have acceptable total latency but still feel slow if the first token takes too long.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Data enters the system in several ways
&lt;/h2&gt;

&lt;p&gt;An AI application may depend on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model-training data&lt;/li&gt;
&lt;li&gt;User prompts&lt;/li&gt;
&lt;li&gt;Conversation history&lt;/li&gt;
&lt;li&gt;Retrieved documents&lt;/li&gt;
&lt;li&gt;Tool results&lt;/li&gt;
&lt;li&gt;Feedback&lt;/li&gt;
&lt;li&gt;Evaluation datasets&lt;/li&gt;
&lt;li&gt;Safety policies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each data type has distinct requirements for retention, privacy, freshness, and consistency.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Failure is not always binary
&lt;/h2&gt;

&lt;p&gt;A traditional request may succeed or fail.&lt;/p&gt;

&lt;p&gt;An AI request can technically succeed but produce a low-quality answer, retrieve the wrong documents, call the wrong tool, exceed a cost budget, or violate a safety rule.&lt;/p&gt;

&lt;p&gt;The architecture must detect and respond to these softer failure modes.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Framework for Answering Any AI System Design Question
&lt;/h1&gt;

&lt;p&gt;Before considering individual questions, use a consistent interview structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Clarify the product
&lt;/h2&gt;

&lt;p&gt;Ask what the system is expected to do.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Is the assistant general-purpose or domain-specific?&lt;/li&gt;
&lt;li&gt;Does it need private enterprise data?&lt;/li&gt;
&lt;li&gt;Can it take actions or only provide answers?&lt;/li&gt;
&lt;li&gt;Does it support text only, or also images, audio, and files?&lt;/li&gt;
&lt;li&gt;Are responses expected in real time?&lt;/li&gt;
&lt;li&gt;Does the system need citations?&lt;/li&gt;
&lt;li&gt;Which decisions require human approval?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without this clarification, “Design an AI assistant” is too broad.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Define scale and service-level objectives
&lt;/h2&gt;

&lt;p&gt;Estimate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Daily and peak requests&lt;/li&gt;
&lt;li&gt;Average prompt size&lt;/li&gt;
&lt;li&gt;Average output length&lt;/li&gt;
&lt;li&gt;Concurrent users&lt;/li&gt;
&lt;li&gt;Required time to first token&lt;/li&gt;
&lt;li&gt;Model size&lt;/li&gt;
&lt;li&gt;GPU-memory requirements&lt;/li&gt;
&lt;li&gt;Availability target&lt;/li&gt;
&lt;li&gt;Cost per request&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI systems are often constrained by cost as much as by technical capacity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Separate the application layer from the model layer
&lt;/h2&gt;

&lt;p&gt;The application layer may include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Billing&lt;/li&gt;
&lt;li&gt;Conversation history&lt;/li&gt;
&lt;li&gt;File management&lt;/li&gt;
&lt;li&gt;User preferences&lt;/li&gt;
&lt;li&gt;Rate limiting&lt;/li&gt;
&lt;li&gt;Analytics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The AI layer may include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prompt construction&lt;/li&gt;
&lt;li&gt;Retrieval&lt;/li&gt;
&lt;li&gt;Model routing&lt;/li&gt;
&lt;li&gt;Inference scheduling&lt;/li&gt;
&lt;li&gt;Safety checks&lt;/li&gt;
&lt;li&gt;Tool execution&lt;/li&gt;
&lt;li&gt;Evaluation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeping these concerns separate makes the design easier to explain and evolve.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Trace the complete request path
&lt;/h2&gt;

&lt;p&gt;Describe what happens from the moment a user submits a prompt until the final result is displayed.&lt;/p&gt;

&lt;p&gt;A typical path may be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Authenticate the request.&lt;/li&gt;
&lt;li&gt;Enforce quotas.&lt;/li&gt;
&lt;li&gt;Load conversation state.&lt;/li&gt;
&lt;li&gt;Retrieve relevant context.&lt;/li&gt;
&lt;li&gt;Construct the model prompt.&lt;/li&gt;
&lt;li&gt;Run input-safety checks.&lt;/li&gt;
&lt;li&gt;Select a model.&lt;/li&gt;
&lt;li&gt;Schedule inference.&lt;/li&gt;
&lt;li&gt;Stream tokens.&lt;/li&gt;
&lt;li&gt;Run output-safety checks.&lt;/li&gt;
&lt;li&gt;Store the response.&lt;/li&gt;
&lt;li&gt;Record metrics and feedback.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 5: Discuss failure, quality, and cost
&lt;/h2&gt;

&lt;p&gt;A strong answer should explain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What happens when the primary model is overloaded?&lt;/li&gt;
&lt;li&gt;What happens when retrieval returns no useful documents?&lt;/li&gt;
&lt;li&gt;How are duplicate tool calls prevented?&lt;/li&gt;
&lt;li&gt;How does the system degrade gracefully?&lt;/li&gt;
&lt;li&gt;How are model changes evaluated?&lt;/li&gt;
&lt;li&gt;How is tenant data isolated?&lt;/li&gt;
&lt;li&gt;How are expensive requests controlled?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These discussions distinguish a production design from a demo.&lt;/p&gt;




&lt;h1&gt;
  
  
  Question 1: Design ChatGPT
&lt;/h1&gt;

&lt;p&gt;A ChatGPT-like system is one of the most comprehensive AI system design questions.&lt;/p&gt;

&lt;p&gt;The functional requirements may include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starting a conversation&lt;/li&gt;
&lt;li&gt;Sending prompts&lt;/li&gt;
&lt;li&gt;Receiving streamed responses&lt;/li&gt;
&lt;li&gt;Viewing conversation history&lt;/li&gt;
&lt;li&gt;Regenerating an answer&lt;/li&gt;
&lt;li&gt;Uploading files&lt;/li&gt;
&lt;li&gt;Choosing among models&lt;/li&gt;
&lt;li&gt;Enforcing free and paid usage limits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A useful high-level architecture contains the following components.&lt;/p&gt;

&lt;h2&gt;
  
  
  API gateway
&lt;/h2&gt;

&lt;p&gt;The gateway handles authentication, request routing, rate limiting, quotas, and basic validation.&lt;/p&gt;

&lt;p&gt;Long-running generation requests may use Server-Sent Events or WebSockets to stream tokens to clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conversation service
&lt;/h2&gt;

&lt;p&gt;This service manages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conversations&lt;/li&gt;
&lt;li&gt;Messages&lt;/li&gt;
&lt;li&gt;User preferences&lt;/li&gt;
&lt;li&gt;Message ordering&lt;/li&gt;
&lt;li&gt;Conversation titles&lt;/li&gt;
&lt;li&gt;Retention and deletion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Conversation metadata can live in a transactional database, while large attachments may be placed in object storage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Context builder
&lt;/h2&gt;

&lt;p&gt;Models have finite context windows. The context builder decides what information should be included in the next request.&lt;/p&gt;

&lt;p&gt;It may combine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The system prompt&lt;/li&gt;
&lt;li&gt;Recent conversation messages&lt;/li&gt;
&lt;li&gt;A summary of older messages&lt;/li&gt;
&lt;li&gt;Retrieved documents&lt;/li&gt;
&lt;li&gt;User preferences&lt;/li&gt;
&lt;li&gt;Tool outputs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simply sending the entire conversation forever is expensive and eventually impossible. Older content may need summarization or selective retrieval.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model gateway
&lt;/h2&gt;

&lt;p&gt;The model gateway provides a single interface to multiple model backends.&lt;/p&gt;

&lt;p&gt;It can route requests based on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Task type&lt;/li&gt;
&lt;li&gt;Required quality&lt;/li&gt;
&lt;li&gt;User subscription&lt;/li&gt;
&lt;li&gt;Context length&lt;/li&gt;
&lt;li&gt;Latency target&lt;/li&gt;
&lt;li&gt;Current capacity&lt;/li&gt;
&lt;li&gt;Cost budget&lt;/li&gt;
&lt;li&gt;Model availability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simple request may use a smaller, faster model, while complex reasoning may be routed to a more capable one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inference scheduler
&lt;/h2&gt;

&lt;p&gt;The scheduler assigns requests to model replicas running on accelerators.&lt;/p&gt;

&lt;p&gt;It should consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Available GPU memory&lt;/li&gt;
&lt;li&gt;Model placement&lt;/li&gt;
&lt;li&gt;Prompt length&lt;/li&gt;
&lt;li&gt;Output-token budget&lt;/li&gt;
&lt;li&gt;Priority&lt;/li&gt;
&lt;li&gt;Batch compatibility&lt;/li&gt;
&lt;li&gt;Tenant quotas&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A naive first-in, first-out scheduler can allow a few extremely long prompts to delay many short requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Streaming layer
&lt;/h2&gt;

&lt;p&gt;Generated tokens should be forwarded incrementally to the user.&lt;/p&gt;

&lt;p&gt;The system must also handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client disconnections&lt;/li&gt;
&lt;li&gt;User cancellation&lt;/li&gt;
&lt;li&gt;Partial responses&lt;/li&gt;
&lt;li&gt;Network retries&lt;/li&gt;
&lt;li&gt;Moderation during generation&lt;/li&gt;
&lt;li&gt;Final persistence after streaming completes&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Safety layer
&lt;/h2&gt;

&lt;p&gt;Input and output policies may detect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prompt injection&lt;/li&gt;
&lt;li&gt;Sensitive information&lt;/li&gt;
&lt;li&gt;Disallowed requests&lt;/li&gt;
&lt;li&gt;Malicious files&lt;/li&gt;
&lt;li&gt;Unsafe tool instructions&lt;/li&gt;
&lt;li&gt;Data leakage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Safety should not be treated as one filter placed at the end. Different checks may be required before retrieval, before tool execution, before inference, and before returning the final response.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important deep dives
&lt;/h2&gt;

&lt;p&gt;An interviewer may ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How would you reduce time to first token?&lt;/li&gt;
&lt;li&gt;How would you support 100 million users?&lt;/li&gt;
&lt;li&gt;How would you prevent one tenant from consuming all GPU capacity?&lt;/li&gt;
&lt;li&gt;How would you summarize long conversations?&lt;/li&gt;
&lt;li&gt;How would you route between multiple models?&lt;/li&gt;
&lt;li&gt;How would you preserve availability during GPU shortages?&lt;/li&gt;
&lt;li&gt;How would you limit the cost for free users?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://www.designgurus.io/course-play/system-design-interview-crash-course/doc/design-chatgpt" rel="noopener noreferrer"&gt;Design ChatGPT walkthrough&lt;/a&gt; provides a structured example of this problem.&lt;/p&gt;




&lt;h1&gt;
  
  
  Question 2: Design a RAG System
&lt;/h1&gt;

&lt;p&gt;Retrieval-augmented generation, or RAG, allows a model to answer using information retrieved from external sources.&lt;/p&gt;

&lt;p&gt;A common interview prompt is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Design an enterprise assistant that answers employee questions using internal documents and provides citations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A RAG system has two major paths:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The ingestion path&lt;/li&gt;
&lt;li&gt;The query path&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The ingestion path
&lt;/h2&gt;

&lt;p&gt;Documents may come from file uploads, internal wikis, cloud drives, databases, or support systems.&lt;/p&gt;

&lt;p&gt;The ingestion pipeline performs several stages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Document extraction
&lt;/h3&gt;

&lt;p&gt;Files must be converted into usable text.&lt;/p&gt;

&lt;p&gt;The system may need parsers for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PDFs&lt;/li&gt;
&lt;li&gt;Word documents&lt;/li&gt;
&lt;li&gt;Presentations&lt;/li&gt;
&lt;li&gt;HTML pages&lt;/li&gt;
&lt;li&gt;Spreadsheets&lt;/li&gt;
&lt;li&gt;Scanned images&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The extraction process should preserve useful metadata such as titles, headings, page numbers, owners, and access permissions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chunking
&lt;/h3&gt;

&lt;p&gt;Long documents are divided into smaller segments.&lt;/p&gt;

&lt;p&gt;Chunks that are too large may contain irrelevant text and consume excessive context. Chunks that are too small may lose meaning.&lt;/p&gt;

&lt;p&gt;Possible strategies include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fixed token windows&lt;/li&gt;
&lt;li&gt;Paragraph-based chunking&lt;/li&gt;
&lt;li&gt;Heading-aware chunking&lt;/li&gt;
&lt;li&gt;Overlapping windows&lt;/li&gt;
&lt;li&gt;Semantic chunking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is no universally correct chunk size. It should be tested against representative questions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Embedding generation
&lt;/h3&gt;

&lt;p&gt;Each chunk is converted into a numerical vector using an embedding model.&lt;/p&gt;

&lt;p&gt;The embedding service should be versioned because changing models can require re-embedding the entire corpus.&lt;/p&gt;

&lt;h3&gt;
  
  
  Indexing
&lt;/h3&gt;

&lt;p&gt;The system stores:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Embeddings&lt;/li&gt;
&lt;li&gt;Original text&lt;/li&gt;
&lt;li&gt;Document metadata&lt;/li&gt;
&lt;li&gt;Access-control information&lt;/li&gt;
&lt;li&gt;Source location&lt;/li&gt;
&lt;li&gt;Embedding version&lt;/li&gt;
&lt;li&gt;Update timestamp&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A vector index enables semantic retrieval. A traditional inverted index can support keyword retrieval. Many production systems combine both.&lt;/p&gt;

&lt;h2&gt;
  
  
  The query path
&lt;/h2&gt;

&lt;p&gt;When a user submits a question:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Authenticate the user.&lt;/li&gt;
&lt;li&gt;Generate an embedding for the query.&lt;/li&gt;
&lt;li&gt;Retrieve candidate chunks.&lt;/li&gt;
&lt;li&gt;Apply access-control filtering.&lt;/li&gt;
&lt;li&gt;Rerank the candidates.&lt;/li&gt;
&lt;li&gt;Select the best context.&lt;/li&gt;
&lt;li&gt;Construct the prompt.&lt;/li&gt;
&lt;li&gt;Generate the answer.&lt;/li&gt;
&lt;li&gt;Attach citations.&lt;/li&gt;
&lt;li&gt;Evaluate or log the result.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Hybrid retrieval
&lt;/h2&gt;

&lt;p&gt;Semantic retrieval is useful when the query and source use different words with similar meanings.&lt;/p&gt;

&lt;p&gt;Keyword retrieval is useful for exact terms such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Product codes&lt;/li&gt;
&lt;li&gt;Error messages&lt;/li&gt;
&lt;li&gt;Names&lt;/li&gt;
&lt;li&gt;Dates&lt;/li&gt;
&lt;li&gt;Identifiers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Combining both methods often produces better coverage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reranking
&lt;/h2&gt;

&lt;p&gt;Vector similarity may retrieve documents that are generally related but not directly useful.&lt;/p&gt;

&lt;p&gt;A reranker can score the top candidates more accurately before they are sent to the LLM. This improves answer quality while keeping the final prompt small.&lt;/p&gt;

&lt;h2&gt;
  
  
  Access control
&lt;/h2&gt;

&lt;p&gt;Security is one of the most important parts of enterprise RAG.&lt;/p&gt;

&lt;p&gt;A user should never retrieve a document they are not authorized to view. Filtering after the model has already received the document is too late.&lt;/p&gt;

&lt;p&gt;Permissions should be enforced during retrieval, with tenant and user identity included in the query path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Freshness and deletion
&lt;/h2&gt;

&lt;p&gt;The system must react when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A document changes.&lt;/li&gt;
&lt;li&gt;A document is deleted.&lt;/li&gt;
&lt;li&gt;Permissions change.&lt;/li&gt;
&lt;li&gt;A user loses access.&lt;/li&gt;
&lt;li&gt;A newer policy replaces an older one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The ingestion pipeline may use event-driven updates, periodic crawling, or both.&lt;/p&gt;

&lt;h2&gt;
  
  
  RAG evaluation
&lt;/h2&gt;

&lt;p&gt;A RAG system should separately evaluate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval quality:&lt;/strong&gt; Did the system find the relevant document?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generation quality:&lt;/strong&gt; Did the model use the retrieved context correctly?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Citation quality:&lt;/strong&gt; Do the cited sources actually support the answer?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This separation is important. A poor answer can result from failed retrieval even when the model behaves correctly.&lt;/p&gt;




&lt;h1&gt;
  
  
  Question 3: Design an LLM Inference Platform
&lt;/h1&gt;

&lt;p&gt;This question focuses less on the product interface and more on the infrastructure that serves models.&lt;/p&gt;

&lt;p&gt;A possible prompt is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Design a multi-tenant platform that serves several large language models to millions of requests.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The platform may need to support:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple model families&lt;/li&gt;
&lt;li&gt;Different model sizes&lt;/li&gt;
&lt;li&gt;Streaming generation&lt;/li&gt;
&lt;li&gt;Priority tiers&lt;/li&gt;
&lt;li&gt;Autoscaling&lt;/li&gt;
&lt;li&gt;Usage accounting&lt;/li&gt;
&lt;li&gt;Model versioning&lt;/li&gt;
&lt;li&gt;Regional deployment&lt;/li&gt;
&lt;li&gt;Fine-tuned adapters&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Inference gateway
&lt;/h2&gt;

&lt;p&gt;The gateway exposes a consistent API and performs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Quota enforcement&lt;/li&gt;
&lt;li&gt;Request validation&lt;/li&gt;
&lt;li&gt;Model selection&lt;/li&gt;
&lt;li&gt;Token-limit checks&lt;/li&gt;
&lt;li&gt;Admission control&lt;/li&gt;
&lt;li&gt;Cost estimation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Admission control is critical. Accepting unlimited work and allowing it to queue indefinitely creates poor latency and can destabilize the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model registry
&lt;/h2&gt;

&lt;p&gt;The registry tracks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model version&lt;/li&gt;
&lt;li&gt;Artifact location&lt;/li&gt;
&lt;li&gt;Supported hardware&lt;/li&gt;
&lt;li&gt;Memory requirements&lt;/li&gt;
&lt;li&gt;Context length&lt;/li&gt;
&lt;li&gt;Quantization format&lt;/li&gt;
&lt;li&gt;Deployment status&lt;/li&gt;
&lt;li&gt;Safety and evaluation results&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rollouts should use immutable versions so requests and incidents can be traced to the exact model that served them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model placement
&lt;/h2&gt;

&lt;p&gt;Loading a large model into GPU memory can take substantial time. The scheduler cannot treat models like lightweight stateless application containers.&lt;/p&gt;

&lt;p&gt;It must decide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which models remain loaded&lt;/li&gt;
&lt;li&gt;How many replicas each model receives&lt;/li&gt;
&lt;li&gt;Where fine-tuned adapters are placed&lt;/li&gt;
&lt;li&gt;When models should be unloaded&lt;/li&gt;
&lt;li&gt;How capacity is distributed across regions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Popular models may remain warm, while rarely used models may accept a cold-start delay.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prefill and decode
&lt;/h2&gt;

&lt;p&gt;LLM inference contains two different computational phases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prefill&lt;/strong&gt; processes the input prompt and can often benefit from parallel computation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decode&lt;/strong&gt; generates tokens sequentially and is usually memory-bandwidth intensive.&lt;/p&gt;

&lt;p&gt;Separating or independently scheduling these phases can improve utilization, but it also adds network and orchestration complexity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuous batching
&lt;/h2&gt;

&lt;p&gt;Instead of waiting for a fixed group of requests to finish together, continuous batching adds and removes requests dynamically as generation progresses.&lt;/p&gt;

&lt;p&gt;This improves GPU utilization, especially when responses have different lengths.&lt;/p&gt;

&lt;p&gt;The scheduler must still prevent long requests from starving shorter ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  KV cache
&lt;/h2&gt;

&lt;p&gt;The key-value cache stores intermediate attention state so the model does not recompute the entire prompt for every generated token.&lt;/p&gt;

&lt;p&gt;KV-cache management affects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maximum concurrency&lt;/li&gt;
&lt;li&gt;Memory pressure&lt;/li&gt;
&lt;li&gt;Long-context support&lt;/li&gt;
&lt;li&gt;Prefix reuse&lt;/li&gt;
&lt;li&gt;Request eviction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A shared prompt prefix—such as a large system prompt—may sometimes be cached and reused across compatible requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scaling
&lt;/h2&gt;

&lt;p&gt;GPU utilization alone may not be sufficient for autoscaling.&lt;/p&gt;

&lt;p&gt;Useful signals include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Queue length&lt;/li&gt;
&lt;li&gt;Time to first token&lt;/li&gt;
&lt;li&gt;Tokens generated per second&lt;/li&gt;
&lt;li&gt;KV-cache pressure&lt;/li&gt;
&lt;li&gt;Number of active sequences&lt;/li&gt;
&lt;li&gt;Predicted token demand&lt;/li&gt;
&lt;li&gt;Model-specific backlog&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because accelerator provisioning may be slow, the platform may need reserved capacity and predictive scaling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Graceful degradation
&lt;/h2&gt;

&lt;p&gt;When capacity is limited, the system may:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Route to a smaller model.&lt;/li&gt;
&lt;li&gt;Reduce the maximum output length.&lt;/li&gt;
&lt;li&gt;Reject low-priority requests.&lt;/li&gt;
&lt;li&gt;Disable expensive features.&lt;/li&gt;
&lt;li&gt;Queue batch workloads.&lt;/li&gt;
&lt;li&gt;Move traffic to another region.&lt;/li&gt;
&lt;li&gt;Use a third-party model provider.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A strong interview answer discusses the quality and cost consequences of each fallback.&lt;/p&gt;




&lt;h1&gt;
  
  
  Question 4: Design an AI Agent Platform
&lt;/h1&gt;

&lt;p&gt;An AI agent does more than produce text. It can plan a sequence of actions, call tools, observe results, update its state, and continue until a goal is completed.&lt;/p&gt;

&lt;p&gt;A typical prompt might be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Design an enterprise agent that can search internal documents, update tickets, send emails, and request human approval for sensitive actions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Core components
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Agent orchestrator
&lt;/h3&gt;

&lt;p&gt;The orchestrator controls the execution loop:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Receive a goal.&lt;/li&gt;
&lt;li&gt;Construct the current context.&lt;/li&gt;
&lt;li&gt;Ask the model for the next action.&lt;/li&gt;
&lt;li&gt;Validate the proposed action.&lt;/li&gt;
&lt;li&gt;Execute the selected tool.&lt;/li&gt;
&lt;li&gt;Store the result.&lt;/li&gt;
&lt;li&gt;Decide whether to continue.&lt;/li&gt;
&lt;li&gt;Produce the final response.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The orchestrator—not the model—should enforce hard limits such as maximum steps, timeouts, budgets, and approval requirements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tool registry
&lt;/h3&gt;

&lt;p&gt;The tool registry describes each available capability:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tool name&lt;/li&gt;
&lt;li&gt;Purpose&lt;/li&gt;
&lt;li&gt;Input schema&lt;/li&gt;
&lt;li&gt;Required permissions&lt;/li&gt;
&lt;li&gt;Timeout&lt;/li&gt;
&lt;li&gt;Retry policy&lt;/li&gt;
&lt;li&gt;Risk level&lt;/li&gt;
&lt;li&gt;Whether human approval is required&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tool definitions should be versioned because changing their schemas can break existing agent behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tool execution service
&lt;/h3&gt;

&lt;p&gt;Tool calls should run through controlled executors rather than allowing the model unrestricted access to internal systems.&lt;/p&gt;

&lt;p&gt;The executor handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Input validation&lt;/li&gt;
&lt;li&gt;Secrets&lt;/li&gt;
&lt;li&gt;Network policy&lt;/li&gt;
&lt;li&gt;Timeouts&lt;/li&gt;
&lt;li&gt;Retries&lt;/li&gt;
&lt;li&gt;Audit logging&lt;/li&gt;
&lt;li&gt;Output normalization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;High-risk operations should use narrow, purpose-built APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  State and memory
&lt;/h3&gt;

&lt;p&gt;Agents may need several kinds of memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Working memory&lt;/strong&gt; contains the current task, observations, and intermediate steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Session memory&lt;/strong&gt; preserves information during one user interaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Long-term memory&lt;/strong&gt; stores information across sessions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;External memory&lt;/strong&gt; may contain documents retrieved from databases or vector indexes.&lt;/p&gt;

&lt;p&gt;Not everything should be stored forever. Memory needs explicit retention, privacy, and deletion policies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Human approval
&lt;/h3&gt;

&lt;p&gt;Actions such as sending payments, deleting data, publishing content, or modifying production systems should not be executed solely because a model requested them.&lt;/p&gt;

&lt;p&gt;The agent can create a proposed action, pause its workflow, and wait for authorized approval.&lt;/p&gt;

&lt;p&gt;The approval record should contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The intended action&lt;/li&gt;
&lt;li&gt;The relevant parameters&lt;/li&gt;
&lt;li&gt;Why it was proposed&lt;/li&gt;
&lt;li&gt;The expected effect&lt;/li&gt;
&lt;li&gt;The identity of the approver&lt;/li&gt;
&lt;li&gt;An expiration time&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Idempotency
&lt;/h3&gt;

&lt;p&gt;Agents may retry actions after timeouts.&lt;/p&gt;

&lt;p&gt;Without idempotency, a retry could send the same email twice, create duplicate tickets, or repeat a transaction.&lt;/p&gt;

&lt;p&gt;Every state-changing tool call should include a stable execution identifier or idempotency key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agent-specific failure modes
&lt;/h2&gt;

&lt;p&gt;A strong candidate should discuss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Infinite planning loops&lt;/li&gt;
&lt;li&gt;Repeated tool calls&lt;/li&gt;
&lt;li&gt;Prompt injection inside retrieved content&lt;/li&gt;
&lt;li&gt;Tool hallucination&lt;/li&gt;
&lt;li&gt;Stale observations&lt;/li&gt;
&lt;li&gt;Excessive cost&lt;/li&gt;
&lt;li&gt;Partial workflow completion&lt;/li&gt;
&lt;li&gt;Conflicting actions&lt;/li&gt;
&lt;li&gt;Unauthorized data access&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The system should impose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maximum step counts&lt;/li&gt;
&lt;li&gt;Token budgets&lt;/li&gt;
&lt;li&gt;Time limits&lt;/li&gt;
&lt;li&gt;Per-tool permissions&lt;/li&gt;
&lt;li&gt;Human checkpoints&lt;/li&gt;
&lt;li&gt;Detailed audit logs&lt;/li&gt;
&lt;li&gt;Recovery or compensation workflows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://www.designgurus.io/course/grokking-modern-ai-fundamentals" rel="noopener noreferrer"&gt;Grokking Modern AI Fundamentals&lt;/a&gt; course can provide additional background on agentic AI, planning, memory, and tool-based behavior.&lt;/p&gt;




&lt;h1&gt;
  
  
  Additional AI System Design Questions to Practice
&lt;/h1&gt;

&lt;p&gt;The four core questions cover much of the modern AI stack, but interviewers can frame the same concepts in narrower ways.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design an enterprise AI copilot
&lt;/h2&gt;

&lt;p&gt;Focus on tenant isolation, document permissions, RAG, conversation history, model routing, auditability, and data retention.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design a coding assistant
&lt;/h2&gt;

&lt;p&gt;Discuss repository indexing, code-aware chunking, low-latency suggestions, context selection, IDE integration, private-code protection, and evaluation of generated code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design an AI evaluation platform
&lt;/h2&gt;

&lt;p&gt;Cover dataset versioning, offline evaluation, human review, model comparison, prompt experiments, regression detection, and production feedback.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design a multi-model gateway
&lt;/h2&gt;

&lt;p&gt;Explain routing between internal and third-party models based on cost, quality, latency, privacy, context length, and availability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design a semantic-search platform
&lt;/h2&gt;

&lt;p&gt;Focus on ingestion, embeddings, vector indexes, hybrid retrieval, filtering, reranking, index updates, and relevance metrics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design an AI safety and guardrails service
&lt;/h2&gt;

&lt;p&gt;Discuss policy versioning, input and output classification, prompt-injection detection, tool restrictions, personally identifiable information, appeals, and false-positive handling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design a prompt-management platform
&lt;/h2&gt;

&lt;p&gt;Cover prompt templates, version control, experiments, rollout, rollback, tenant overrides, caching, and compatibility with changing model versions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design a multimodal assistant
&lt;/h2&gt;

&lt;p&gt;Add image, audio, and document ingestion, media storage, preprocessing, modality-specific models, content safety, and larger payload management.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Interviewers Look for in AI System Design Answers
&lt;/h1&gt;

&lt;p&gt;A weak answer places an LLM box in the center of a diagram and connects it to an API.&lt;/p&gt;

&lt;p&gt;A strong answer explains the system around the model.&lt;/p&gt;

&lt;p&gt;Interviewers want to see whether you can reason about:&lt;/p&gt;

&lt;h2&gt;
  
  
  End-to-end architecture
&lt;/h2&gt;

&lt;p&gt;Can you connect the client, application services, retrieval layer, model platform, storage, and observability systems?&lt;/p&gt;

&lt;h2&gt;
  
  
  Trade-offs
&lt;/h2&gt;

&lt;p&gt;Can you compare:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Larger models versus smaller models&lt;/li&gt;
&lt;li&gt;Quality versus latency&lt;/li&gt;
&lt;li&gt;Quality versus cost&lt;/li&gt;
&lt;li&gt;Long context versus retrieval&lt;/li&gt;
&lt;li&gt;Hosted APIs versus self-hosting&lt;/li&gt;
&lt;li&gt;Semantic retrieval versus keyword search&lt;/li&gt;
&lt;li&gt;Autonomy versus human control&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reliability
&lt;/h2&gt;

&lt;p&gt;Can the system continue operating when a model, vector index, tool, region, or third-party provider is unavailable?&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluation
&lt;/h2&gt;

&lt;p&gt;Can you tell whether a new model or prompt actually improved the product?&lt;/p&gt;

&lt;h2&gt;
  
  
  Security
&lt;/h2&gt;

&lt;p&gt;Can you protect tenant data, prevent unauthorized retrieval, constrain tool use, and manage sensitive prompts?&lt;/p&gt;

&lt;h2&gt;
  
  
  Cost
&lt;/h2&gt;

&lt;p&gt;Can you estimate and control token usage, accelerator capacity, retrieval cost, storage, and third-party API spending?&lt;/p&gt;

&lt;p&gt;The model is only one component. Production readiness comes from the architecture surrounding it.&lt;/p&gt;




&lt;h1&gt;
  
  
  How to Prepare
&lt;/h1&gt;

&lt;p&gt;Candidates new to large-scale architecture should first learn the traditional foundations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.designgurus.io/course/grokking-system-design-fundamentals" rel="noopener noreferrer"&gt;Grokking System Design Fundamentals&lt;/a&gt; introduces the core building blocks behind scalable systems, including databases, caches, queues, replication, partitioning, and load balancing.&lt;/p&gt;

&lt;p&gt;The original &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt; applies those concepts to common interview problems and teaches a structured way to move from requirements to architecture and trade-offs.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://www.designgurus.io/course/system-design-interview-crash-course" rel="noopener noreferrer"&gt;System Design Interview Crash Course&lt;/a&gt; is useful for practicing a consistent interview framework across modern case studies, including a complete ChatGPT design problem.&lt;/p&gt;

&lt;p&gt;Engineers preparing for senior and staff-level discussions can continue with &lt;a href="https://www.designgurus.io/course/grokking-system-design-interview-ii" rel="noopener noreferrer"&gt;Advanced System Design Interview, Volume II&lt;/a&gt;, which emphasizes open-ended problems, failures, and defensible architectural decisions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.designgurus.io/course/grokking-scalable-systems-for-interviews" rel="noopener noreferrer"&gt;Grokking Scalable Systems for Interviews&lt;/a&gt; is a useful next step for strengthening scalability, observability, fault tolerance, and performance reasoning.&lt;/p&gt;

&lt;p&gt;For every AI design problem, practice three times:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Design the happy path.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Design for failure and overload.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Defend the quality, safety, and cost trade-offs.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That third pass is where most of the valuable interview discussion occurs.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Takeaway
&lt;/h1&gt;

&lt;p&gt;AI system design is not a replacement for traditional system design.&lt;/p&gt;

&lt;p&gt;It is a traditional system design combined with a new set of constraints.&lt;/p&gt;

&lt;p&gt;You still need to understand APIs, storage, caching, queues, partitioning, replication, security, observability, and fault tolerance.&lt;/p&gt;

&lt;p&gt;But you must now apply those concepts to systems with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Probabilistic outputs&lt;/li&gt;
&lt;li&gt;Expensive inference&lt;/li&gt;
&lt;li&gt;Streaming generation&lt;/li&gt;
&lt;li&gt;Vector retrieval&lt;/li&gt;
&lt;li&gt;Dynamic prompts&lt;/li&gt;
&lt;li&gt;Long-lived context&lt;/li&gt;
&lt;li&gt;External tools&lt;/li&gt;
&lt;li&gt;Model evaluation&lt;/li&gt;
&lt;li&gt;Safety requirements&lt;/li&gt;
&lt;li&gt;Human approval&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start with four foundational problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Design ChatGPT.&lt;/li&gt;
&lt;li&gt;Design a RAG platform.&lt;/li&gt;
&lt;li&gt;Design an LLM inference service.&lt;/li&gt;
&lt;li&gt;Design an AI agent platform.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Master the request flow, deep dives, failure modes, and trade-offs behind each one.&lt;/p&gt;

&lt;p&gt;Once you can explain those systems clearly, most other AI system design questions become variations of the same underlying building blocks.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>chatgpt</category>
      <category>claude</category>
    </item>
    <item>
      <title>System Design Interview Questions by Level: Junior, Mid-Level, Senior, and Staff</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Thu, 25 Jun 2026 11:25:18 +0000</pubDate>
      <link>https://dev.to/arslan_ah/system-design-interview-questions-by-level-junior-mid-level-senior-and-staff-2m6h</link>
      <guid>https://dev.to/arslan_ah/system-design-interview-questions-by-level-junior-mid-level-senior-and-staff-2m6h</guid>
      <description>&lt;h1&gt;
  
  
  System Design Interview Questions by Level: Junior, Mid-Level, Senior, and Staff
&lt;/h1&gt;

&lt;p&gt;Not every system design interview evaluates the same thing.&lt;/p&gt;

&lt;p&gt;A junior engineer may be asked to design a URL shortener and explain why a cache would help. A mid-level engineer could receive the same question but be expected to estimate traffic, choose a database, and handle key collisions.&lt;/p&gt;

&lt;p&gt;A senior engineer may need to discuss multi-region deployment, consistency, failure recovery, and operational trade-offs. A staff engineer could be pushed further into migration strategy, organizational boundaries, cost, and the long-term evolution of the platform.&lt;/p&gt;

&lt;p&gt;The question may look identical. The expected answer is not.&lt;/p&gt;

&lt;p&gt;This is why preparing from one enormous, unstructured list of system design questions can be misleading. Candidates often spend time on problems that are far above or below the depth required for their target role.&lt;/p&gt;

&lt;p&gt;A better approach is to organize your preparation around the level you are targeting.&lt;/p&gt;

&lt;p&gt;This guide breaks system design interview questions into four groups:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Junior engineers&lt;/li&gt;
&lt;li&gt;Mid-level engineers&lt;/li&gt;
&lt;li&gt;Senior engineers&lt;/li&gt;
&lt;li&gt;Staff engineers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a broader collection covering every difficulty tier, see the complete pillar guide: &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m"&gt;64 System Design Interview Questions, Ranked From Easiest to Hardest&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The goal here is different. Instead of simply listing questions, we will examine what interviewers expect from candidates at each engineering level.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Changes as You Move Up the Engineering Ladder?
&lt;/h2&gt;

&lt;p&gt;System design interviews become harder with seniority, but not simply because the systems become larger.&lt;/p&gt;

&lt;p&gt;The most important change is the &lt;strong&gt;depth of reasoning expected from you&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A junior candidate is usually evaluated on whether they understand fundamental building blocks.&lt;/p&gt;

&lt;p&gt;A mid-level candidate must connect those building blocks into a scalable architecture.&lt;/p&gt;

&lt;p&gt;A senior candidate must anticipate failures, challenge assumptions, and defend architectural trade-offs.&lt;/p&gt;

&lt;p&gt;A staff candidate must think beyond the immediate system and consider its interaction with teams, platforms, migrations, business constraints, and long-term technical strategy.&lt;/p&gt;

&lt;p&gt;A simplified progression looks like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Level&lt;/th&gt;
&lt;th&gt;Primary expectation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Junior&lt;/td&gt;
&lt;td&gt;Understand the basic components and produce a workable design&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mid-level&lt;/td&gt;
&lt;td&gt;Build a scalable end-to-end system and explain major trade-offs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Senior&lt;/td&gt;
&lt;td&gt;Handle ambiguity, failures, correctness, and operational complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Staff&lt;/td&gt;
&lt;td&gt;Shape the problem, evaluate long-term consequences, and lead the design discussion&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Your preparation should reflect this progression.&lt;/p&gt;




&lt;h1&gt;
  
  
  Junior-Level System Design Interview Questions
&lt;/h1&gt;

&lt;p&gt;Junior engineers are not normally expected to design a globally distributed platform from first principles.&lt;/p&gt;

&lt;p&gt;Interviewers are more interested in whether you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clarify basic requirements.&lt;/li&gt;
&lt;li&gt;Identify the main entities.&lt;/li&gt;
&lt;li&gt;Define simple APIs.&lt;/li&gt;
&lt;li&gt;Choose reasonable storage.&lt;/li&gt;
&lt;li&gt;Understand caching and load balancing.&lt;/li&gt;
&lt;li&gt;Estimate basic traffic and storage.&lt;/li&gt;
&lt;li&gt;Explain how the system could scale beyond one server.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The best junior-level questions usually focus on one dominant concept.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Design TinyURL
&lt;/h2&gt;

&lt;p&gt;A URL shortener is one of the best starting points for system design preparation.&lt;/p&gt;

&lt;p&gt;The core workflow is simple:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A user submits a long URL.&lt;/li&gt;
&lt;li&gt;The system generates a short identifier.&lt;/li&gt;
&lt;li&gt;The identifier is stored with the original URL.&lt;/li&gt;
&lt;li&gt;Requests to the short URL are redirected.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A junior candidate should be able to discuss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The API for creating and resolving links.&lt;/li&gt;
&lt;li&gt;Generating unique short keys.&lt;/li&gt;
&lt;li&gt;Handling collisions.&lt;/li&gt;
&lt;li&gt;Storing URL mappings.&lt;/li&gt;
&lt;li&gt;Caching frequently accessed links.&lt;/li&gt;
&lt;li&gt;Expiring links when necessary.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not overcomplicate the first version. Start with a single service and database, then explain how load balancers, replicas, and caches could be introduced as traffic increases.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/_TsJizByBvE" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Design Pastebin
&lt;/h2&gt;

&lt;p&gt;Pastebin extends the URL-shortening problem by adding larger content, expiration, and access control.&lt;/p&gt;

&lt;p&gt;Important questions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should paste content and metadata live together?&lt;/li&gt;
&lt;li&gt;How will pastes expire?&lt;/li&gt;
&lt;li&gt;How will private pastes be protected?&lt;/li&gt;
&lt;li&gt;Where should large text objects be stored?&lt;/li&gt;
&lt;li&gt;How can popular pastes be served quickly?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This problem teaches an important system design lesson: different types of data may require different storage strategies.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Design an API Rate Limiter
&lt;/h2&gt;

&lt;p&gt;A rate limiter controls how many requests a user or client can send during a given period.&lt;/p&gt;

&lt;p&gt;Junior candidates should understand the basic algorithms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fixed window&lt;/li&gt;
&lt;li&gt;Sliding window&lt;/li&gt;
&lt;li&gt;Token bucket&lt;/li&gt;
&lt;li&gt;Leaky bucket&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The interview is not only about naming an algorithm. You should explain where counters are stored, how limits are associated with users, and what response is returned when the limit is exceeded.&lt;/p&gt;

&lt;p&gt;A simple in-memory solution is acceptable initially. You can then introduce a shared store such as Redis when multiple application servers need access to the same counters.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Design a Unique ID Generator
&lt;/h2&gt;

&lt;p&gt;Distributed systems frequently need identifiers for users, orders, posts, messages, and transactions.&lt;/p&gt;

&lt;p&gt;The problem appears easy until several machines must generate IDs simultaneously.&lt;/p&gt;

&lt;p&gt;A junior-level discussion may compare:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Auto-incrementing database IDs&lt;/li&gt;
&lt;li&gt;Random UUIDs&lt;/li&gt;
&lt;li&gt;Timestamp-based identifiers&lt;/li&gt;
&lt;li&gt;Preallocated ID ranges&lt;/li&gt;
&lt;li&gt;Snowflake-style IDs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Focus on uniqueness first. Ordering, clock drift, and coordination can be introduced as deeper follow-up topics.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Design Typeahead Suggestions
&lt;/h2&gt;

&lt;p&gt;A typeahead service returns suggestions while a user is entering a search query.&lt;/p&gt;

&lt;p&gt;The design introduces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prefix lookup&lt;/li&gt;
&lt;li&gt;Tries and prefix indexes&lt;/li&gt;
&lt;li&gt;Popularity ranking&lt;/li&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;Latency requirements&lt;/li&gt;
&lt;li&gt;Updating trending queries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The most important lesson is that the system cannot scan every possible query after each keystroke. It needs a data structure or precomputed index that supports fast prefix retrieval.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Design an API Gateway
&lt;/h2&gt;

&lt;p&gt;An API gateway sits between clients and backend services.&lt;/p&gt;

&lt;p&gt;A foundational design should explain how it handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Request routing&lt;/li&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Rate limiting&lt;/li&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Response aggregation&lt;/li&gt;
&lt;li&gt;Protocol transformation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This question helps junior engineers understand how clients interact with a microservice architecture without calling dozens of internal services directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a Strong Junior Answer Looks Like
&lt;/h2&gt;

&lt;p&gt;A good junior-level answer does not need to include every distributed-systems technique.&lt;/p&gt;

&lt;p&gt;It should demonstrate a clear thought process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clarify what the system must do.&lt;/li&gt;
&lt;li&gt;Define the main API operations.&lt;/li&gt;
&lt;li&gt;Choose a simple data model.&lt;/li&gt;
&lt;li&gt;Draw the initial architecture.&lt;/li&gt;
&lt;li&gt;Identify the likely bottleneck.&lt;/li&gt;
&lt;li&gt;Explain one or two ways the design could scale.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Candidates preparing for their first system design interview can begin with &lt;a href="https://www.designgurus.io/course/grokking-system-design-fundamentals" rel="noopener noreferrer"&gt;Grokking System Design Fundamentals&lt;/a&gt; and then progress to the original &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Mid-Level System Design Interview Questions
&lt;/h1&gt;

&lt;p&gt;Mid-level engineers are expected to move beyond isolated components.&lt;/p&gt;

&lt;p&gt;Your design should include a complete flow from the client request to storage, processing, and delivery. You should recognize common bottlenecks without waiting for the interviewer to point them out.&lt;/p&gt;

&lt;p&gt;Interviewers may expect you to discuss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read-heavy versus write-heavy workloads.&lt;/li&gt;
&lt;li&gt;Database partitioning.&lt;/li&gt;
&lt;li&gt;Replication.&lt;/li&gt;
&lt;li&gt;Cache placement and invalidation.&lt;/li&gt;
&lt;li&gt;Asynchronous processing.&lt;/li&gt;
&lt;li&gt;Message queues.&lt;/li&gt;
&lt;li&gt;Eventual consistency.&lt;/li&gt;
&lt;li&gt;Basic failure recovery.&lt;/li&gt;
&lt;li&gt;Trade-offs between different designs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The questions at this level often involve familiar consumer products.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Design Twitter
&lt;/h2&gt;

&lt;p&gt;The central challenge in Twitter is generating a user’s home timeline.&lt;/p&gt;

&lt;p&gt;Two common strategies are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fan-out on write:&lt;/strong&gt; When a user posts, the system pushes the post into followers’ timelines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fan-out on read:&lt;/strong&gt; When a user opens the application, the system retrieves recent posts from everyone they follow.&lt;/p&gt;

&lt;p&gt;Fan-out on write improves read latency but creates enormous write amplification for accounts with millions of followers. Fan-out on read avoids those writes but makes timeline retrieval more expensive.&lt;/p&gt;

&lt;p&gt;A strong mid-level candidate should recognize that a hybrid strategy may work best.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Design Instagram
&lt;/h2&gt;

&lt;p&gt;Instagram introduces media upload, processing, storage, and delivery.&lt;/p&gt;

&lt;p&gt;Your design should separate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Media metadata&lt;/li&gt;
&lt;li&gt;Original image or video files&lt;/li&gt;
&lt;li&gt;Derived formats and thumbnails&lt;/li&gt;
&lt;li&gt;Feed-generation data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Application servers should not repeatedly serve large media files. Object storage and a content delivery network are better suited for that workload.&lt;/p&gt;

&lt;p&gt;Other useful discussion areas include privacy, upload retries, feed generation, and handling popular posts.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Design Facebook Messenger or WhatsApp
&lt;/h2&gt;

&lt;p&gt;A messaging service requires more than storing messages.&lt;/p&gt;

&lt;p&gt;You should consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Persistent connections&lt;/li&gt;
&lt;li&gt;Message routing&lt;/li&gt;
&lt;li&gt;Delivery acknowledgments&lt;/li&gt;
&lt;li&gt;Offline delivery&lt;/li&gt;
&lt;li&gt;Conversation history&lt;/li&gt;
&lt;li&gt;Message ordering&lt;/li&gt;
&lt;li&gt;Retries and deduplication&lt;/li&gt;
&lt;li&gt;Multi-device synchronization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The phrase “exactly-once delivery” should be used carefully. In practice, messaging systems often combine at-least-once delivery with idempotency and deduplication.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Design Dropbox
&lt;/h2&gt;

&lt;p&gt;Dropbox tests both server-side and client-side reasoning.&lt;/p&gt;

&lt;p&gt;Important concepts include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Breaking files into chunks.&lt;/li&gt;
&lt;li&gt;Uploading only changed chunks.&lt;/li&gt;
&lt;li&gt;Deduplicating identical data.&lt;/li&gt;
&lt;li&gt;Synchronizing files across devices.&lt;/li&gt;
&lt;li&gt;Handling concurrent updates.&lt;/li&gt;
&lt;li&gt;Maintaining version history.&lt;/li&gt;
&lt;li&gt;Storing metadata separately from file content.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The client plays a significant role because it monitors local changes and communicates them efficiently to the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Design Uber
&lt;/h2&gt;

&lt;p&gt;Uber combines geospatial search with frequently changing state.&lt;/p&gt;

&lt;p&gt;The system needs to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Receive driver-location updates.&lt;/li&gt;
&lt;li&gt;Find available drivers near a rider.&lt;/li&gt;
&lt;li&gt;Match drivers with trips.&lt;/li&gt;
&lt;li&gt;Track trip state.&lt;/li&gt;
&lt;li&gt;Calculate estimated arrival times.&lt;/li&gt;
&lt;li&gt;Handle sudden regional demand spikes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A mid-level candidate should be comfortable discussing geohashes or another spatial partitioning technique, but the conversation should not end there. You must also explain how the location index stays current and how matching requests avoid conflicts.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Design Yelp or Nearby Friends
&lt;/h2&gt;

&lt;p&gt;This question focuses on finding entities within a geographic area.&lt;/p&gt;

&lt;p&gt;Potential approaches include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Geohashing&lt;/li&gt;
&lt;li&gt;Quadtrees&lt;/li&gt;
&lt;li&gt;Grid-based indexes&lt;/li&gt;
&lt;li&gt;Spatial database indexes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The design should account for uneven density. A geographic cell in a rural area may contain almost nothing, while a similarly sized cell in Manhattan may contain thousands of businesses or users.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Design Ticketmaster
&lt;/h2&gt;

&lt;p&gt;Ticketmaster introduces temporary reservations and strong correctness requirements.&lt;/p&gt;

&lt;p&gt;The system must prevent two customers from purchasing the same seat.&lt;/p&gt;

&lt;p&gt;Important topics include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Seat-locking mechanisms&lt;/li&gt;
&lt;li&gt;Reservation expiration&lt;/li&gt;
&lt;li&gt;Waiting rooms&lt;/li&gt;
&lt;li&gt;Handling flash traffic&lt;/li&gt;
&lt;li&gt;Payment failures&lt;/li&gt;
&lt;li&gt;Idempotent booking operations&lt;/li&gt;
&lt;li&gt;Releasing abandoned reservations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This question helps distinguish systems where eventual consistency is acceptable from systems where it could create serious business problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Design a Notification System
&lt;/h2&gt;

&lt;p&gt;A notification platform may deliver:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Push notifications&lt;/li&gt;
&lt;li&gt;Emails&lt;/li&gt;
&lt;li&gt;SMS messages&lt;/li&gt;
&lt;li&gt;In-app notifications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A good architecture separates notification creation from delivery by placing events on queues. Independent workers can then process different channels.&lt;/p&gt;

&lt;p&gt;The system should also respect user preferences, retry temporary failures, prevent duplicates, and enforce provider-specific rate limits.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a Strong Mid-Level Answer Looks Like
&lt;/h2&gt;

&lt;p&gt;A strong mid-level candidate should be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Complete the end-to-end design.&lt;/li&gt;
&lt;li&gt;Estimate the dominant workload.&lt;/li&gt;
&lt;li&gt;Explain the main read and write paths.&lt;/li&gt;
&lt;li&gt;Select storage based on access patterns.&lt;/li&gt;
&lt;li&gt;Use queues for work that does not need to happen synchronously.&lt;/li&gt;
&lt;li&gt;Identify hotspots and single points of failure.&lt;/li&gt;
&lt;li&gt;Compare at least two possible approaches to the central problem.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The original &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt; is especially relevant at this stage because it combines system design fundamentals, recurring trade-offs, and classic interview problems.&lt;/p&gt;




&lt;h1&gt;
  
  
  Senior-Level System Design Interview Questions
&lt;/h1&gt;

&lt;p&gt;Senior candidates are expected to take ownership of the discussion.&lt;/p&gt;

&lt;p&gt;The interviewer may deliberately leave the prompt vague. Rather than asking for every requirement individually, you should identify the assumptions that materially affect the architecture.&lt;/p&gt;

&lt;p&gt;Senior interviews tend to emphasize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Failure modes.&lt;/li&gt;
&lt;li&gt;Multi-region operation.&lt;/li&gt;
&lt;li&gt;Data consistency.&lt;/li&gt;
&lt;li&gt;Idempotency.&lt;/li&gt;
&lt;li&gt;Observability.&lt;/li&gt;
&lt;li&gt;Backpressure.&lt;/li&gt;
&lt;li&gt;Capacity planning.&lt;/li&gt;
&lt;li&gt;Operational complexity.&lt;/li&gt;
&lt;li&gt;Security and privacy.&lt;/li&gt;
&lt;li&gt;Cost-aware architecture.&lt;/li&gt;
&lt;li&gt;Migration and rollout strategies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simply drawing more boxes does not make an answer senior-level. Depth comes from anticipating what could go wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Design Google Docs
&lt;/h2&gt;

&lt;p&gt;Real-time collaborative editing requires multiple users to update the same document concurrently.&lt;/p&gt;

&lt;p&gt;The key problem is convergence: all clients must eventually agree on the same document state, even when operations arrive in different orders.&lt;/p&gt;

&lt;p&gt;A strong discussion may include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Operational transformation&lt;/li&gt;
&lt;li&gt;Conflict-free replicated data types&lt;/li&gt;
&lt;li&gt;Operation logs&lt;/li&gt;
&lt;li&gt;Document snapshots&lt;/li&gt;
&lt;li&gt;Cursor and presence updates&lt;/li&gt;
&lt;li&gt;Reconnection after network failure&lt;/li&gt;
&lt;li&gt;Version history&lt;/li&gt;
&lt;li&gt;Permission changes during a session&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senior candidates should explain which updates require durability and which can be treated as temporary presence information.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Design ChatGPT
&lt;/h2&gt;

&lt;p&gt;Designing ChatGPT combines conventional application infrastructure with large-model inference.&lt;/p&gt;

&lt;p&gt;The product layer may require:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Conversation history&lt;/li&gt;
&lt;li&gt;Usage limits&lt;/li&gt;
&lt;li&gt;Billing&lt;/li&gt;
&lt;li&gt;Streaming responses&lt;/li&gt;
&lt;li&gt;Safety enforcement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model-serving layer introduces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GPU scheduling&lt;/li&gt;
&lt;li&gt;Request batching&lt;/li&gt;
&lt;li&gt;Model routing&lt;/li&gt;
&lt;li&gt;Token streaming&lt;/li&gt;
&lt;li&gt;Context management&lt;/li&gt;
&lt;li&gt;KV-cache management&lt;/li&gt;
&lt;li&gt;Capacity and cost control&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The interviewer may not expect a detailed explanation of model training. A strong candidate clearly defines the scope and focuses on the online serving system.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Design a Distributed Cache
&lt;/h2&gt;

&lt;p&gt;A distributed cache such as Redis introduces several difficult concerns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Partitioning&lt;/li&gt;
&lt;li&gt;Replication&lt;/li&gt;
&lt;li&gt;Eviction&lt;/li&gt;
&lt;li&gt;Expiration&lt;/li&gt;
&lt;li&gt;Cache invalidation&lt;/li&gt;
&lt;li&gt;Hot keys&lt;/li&gt;
&lt;li&gt;Cache stampedes&lt;/li&gt;
&lt;li&gt;Node failure&lt;/li&gt;
&lt;li&gt;Rebalancing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A senior candidate should discuss what happens during partial failure, not merely describe the happy path.&lt;/p&gt;

&lt;p&gt;For example, when an expired popular key receives thousands of simultaneous requests, those requests may all hit the database. Request coalescing, staggered expiration, and stale-while-revalidate are possible protections.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Design a Payment System
&lt;/h2&gt;

&lt;p&gt;Payments are dominated by correctness rather than raw scale.&lt;/p&gt;

&lt;p&gt;Important concepts include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Idempotency keys&lt;/li&gt;
&lt;li&gt;Immutable transaction records&lt;/li&gt;
&lt;li&gt;Double-entry ledgers&lt;/li&gt;
&lt;li&gt;Payment state machines&lt;/li&gt;
&lt;li&gt;Reconciliation&lt;/li&gt;
&lt;li&gt;Webhook retries&lt;/li&gt;
&lt;li&gt;Duplicate events&lt;/li&gt;
&lt;li&gt;Refunds and chargebacks&lt;/li&gt;
&lt;li&gt;Unknown transaction outcomes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A network timeout does not prove that a payment failed. The request may have succeeded while the response was lost. The architecture must preserve this uncertainty and resolve it safely.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Design Amazon S3
&lt;/h2&gt;

&lt;p&gt;An object-storage system must provide extraordinary durability while serving huge volumes of reads and writes.&lt;/p&gt;

&lt;p&gt;A senior-level design should address:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Object and bucket metadata&lt;/li&gt;
&lt;li&gt;Data partitioning&lt;/li&gt;
&lt;li&gt;Replication or erasure coding&lt;/li&gt;
&lt;li&gt;Checksums&lt;/li&gt;
&lt;li&gt;Multipart uploads&lt;/li&gt;
&lt;li&gt;Versioning&lt;/li&gt;
&lt;li&gt;Lifecycle management&lt;/li&gt;
&lt;li&gt;Corruption detection&lt;/li&gt;
&lt;li&gt;Background repair&lt;/li&gt;
&lt;li&gt;Hot partitions&lt;/li&gt;
&lt;li&gt;Regional failures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The metadata plane and object data plane should be considered separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Design a Metrics and Monitoring System
&lt;/h2&gt;

&lt;p&gt;Monitoring systems ingest large volumes of time-series data.&lt;/p&gt;

&lt;p&gt;Important concerns include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High-throughput ingestion&lt;/li&gt;
&lt;li&gt;Metric labels and cardinality&lt;/li&gt;
&lt;li&gt;Time-based partitioning&lt;/li&gt;
&lt;li&gt;Downsampling&lt;/li&gt;
&lt;li&gt;Retention&lt;/li&gt;
&lt;li&gt;Aggregation&lt;/li&gt;
&lt;li&gt;Query performance&lt;/li&gt;
&lt;li&gt;Alert evaluation&lt;/li&gt;
&lt;li&gt;Late-arriving data&lt;/li&gt;
&lt;li&gt;Regional collection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the most important discussions is cardinality. A seemingly harmless label such as a unique user ID can produce an unsustainable number of time series.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Design a Code Deployment System
&lt;/h2&gt;

&lt;p&gt;A deployment platform coordinates changes across large fleets of machines or containers.&lt;/p&gt;

&lt;p&gt;A strong design should include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build artifacts&lt;/li&gt;
&lt;li&gt;Deployment manifests&lt;/li&gt;
&lt;li&gt;Canary releases&lt;/li&gt;
&lt;li&gt;Blue-green deployments&lt;/li&gt;
&lt;li&gt;Health checks&lt;/li&gt;
&lt;li&gt;Progressive rollout&lt;/li&gt;
&lt;li&gt;Automated rollback&lt;/li&gt;
&lt;li&gt;Audit logs&lt;/li&gt;
&lt;li&gt;Configuration management&lt;/li&gt;
&lt;li&gt;Regional sequencing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The senior-level challenge is not merely deploying the new version. It is limiting the blast radius when that version is defective.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a Strong Senior Answer Looks Like
&lt;/h2&gt;

&lt;p&gt;Senior candidates should lead rather than follow.&lt;/p&gt;

&lt;p&gt;That means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Narrowing an ambiguous problem.&lt;/li&gt;
&lt;li&gt;Prioritizing the most important quality attributes.&lt;/li&gt;
&lt;li&gt;Making assumptions explicit.&lt;/li&gt;
&lt;li&gt;Identifying failure scenarios before being prompted.&lt;/li&gt;
&lt;li&gt;Explaining operational consequences.&lt;/li&gt;
&lt;li&gt;Choosing the deep dive that best demonstrates judgment.&lt;/li&gt;
&lt;li&gt;Acknowledging where the design creates future complexity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Engineers targeting senior and L5/L6 roles can use &lt;a href="https://www.designgurus.io/course/grokking-system-design-interview-ii" rel="noopener noreferrer"&gt;Grokking the System Design Interview, Volume II&lt;/a&gt; for more advanced distributed-systems problems and deeper trade-off analysis.&lt;/p&gt;




&lt;h1&gt;
  
  
  Staff-Level System Design Interview Questions
&lt;/h1&gt;

&lt;p&gt;Staff-level interviews are not simply senior interviews with larger numbers.&lt;/p&gt;

&lt;p&gt;The candidate is expected to reason across systems, teams, and time horizons.&lt;/p&gt;

&lt;p&gt;A staff engineer should be able to discuss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Platform boundaries.&lt;/li&gt;
&lt;li&gt;Ownership between teams.&lt;/li&gt;
&lt;li&gt;Incremental migrations.&lt;/li&gt;
&lt;li&gt;Build-versus-buy decisions.&lt;/li&gt;
&lt;li&gt;Long-term data models.&lt;/li&gt;
&lt;li&gt;Cross-region architecture.&lt;/li&gt;
&lt;li&gt;Compliance and security.&lt;/li&gt;
&lt;li&gt;Cost and organizational constraints.&lt;/li&gt;
&lt;li&gt;Standardization versus team autonomy.&lt;/li&gt;
&lt;li&gt;How the system evolves over several years.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The interviewer may care more about how you frame the problem than about the final diagram.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Design a Stock Exchange
&lt;/h2&gt;

&lt;p&gt;A stock exchange requires deterministic ordering, low latency, and strict correctness.&lt;/p&gt;

&lt;p&gt;The design should cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Order submission&lt;/li&gt;
&lt;li&gt;Sequencing&lt;/li&gt;
&lt;li&gt;Order books&lt;/li&gt;
&lt;li&gt;Matching engines&lt;/li&gt;
&lt;li&gt;Market-data distribution&lt;/li&gt;
&lt;li&gt;Persistence and replay&lt;/li&gt;
&lt;li&gt;Risk controls&lt;/li&gt;
&lt;li&gt;Failure recovery&lt;/li&gt;
&lt;li&gt;Auditability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Partitioning by financial instrument can improve scalability, but each order book needs a clear source of authority.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Design a Distributed Lock Manager
&lt;/h2&gt;

&lt;p&gt;Distributed locking introduces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consensus&lt;/li&gt;
&lt;li&gt;Leases&lt;/li&gt;
&lt;li&gt;Session expiration&lt;/li&gt;
&lt;li&gt;Leader election&lt;/li&gt;
&lt;li&gt;Fencing tokens&lt;/li&gt;
&lt;li&gt;Split-brain prevention&lt;/li&gt;
&lt;li&gt;Clock and network uncertainty&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A staff candidate should understand why acquiring a lock is not enough. A paused or partitioned client might continue operating after its lease has expired. Fencing tokens can help downstream resources reject stale owners.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Design a Distributed Job Scheduler
&lt;/h2&gt;

&lt;p&gt;A global scheduler must trigger jobs at the correct time, distribute work, and recover from failures.&lt;/p&gt;

&lt;p&gt;Challenges include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sharding schedules.&lt;/li&gt;
&lt;li&gt;Leader election.&lt;/li&gt;
&lt;li&gt;Worker coordination.&lt;/li&gt;
&lt;li&gt;Duplicate execution.&lt;/li&gt;
&lt;li&gt;Missed schedules.&lt;/li&gt;
&lt;li&gt;Long-running jobs.&lt;/li&gt;
&lt;li&gt;Retries.&lt;/li&gt;
&lt;li&gt;Backpressure.&lt;/li&gt;
&lt;li&gt;Time-zone handling.&lt;/li&gt;
&lt;li&gt;Disaster recovery.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The candidate should distinguish between guaranteeing that a job is dispatched and guaranteeing that its business effect occurs only once.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Design Apache Kafka
&lt;/h2&gt;

&lt;p&gt;Kafka is best understood as a distributed append-only log rather than a conventional queue.&lt;/p&gt;

&lt;p&gt;A staff-level discussion may cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Partitioning&lt;/li&gt;
&lt;li&gt;Consumer groups&lt;/li&gt;
&lt;li&gt;Offset management&lt;/li&gt;
&lt;li&gt;Replication&lt;/li&gt;
&lt;li&gt;Leader election&lt;/li&gt;
&lt;li&gt;Retention&lt;/li&gt;
&lt;li&gt;Log compaction&lt;/li&gt;
&lt;li&gt;Rebalancing&lt;/li&gt;
&lt;li&gt;Delivery semantics&lt;/li&gt;
&lt;li&gt;Cross-region replication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The design should also consider how Kafka would be operated as a shared organizational platform without allowing one workload to destabilize everyone else.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Explain Amazon Dynamo
&lt;/h2&gt;

&lt;p&gt;Dynamo provides a rich case study in availability-oriented storage.&lt;/p&gt;

&lt;p&gt;Core topics include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consistent hashing&lt;/li&gt;
&lt;li&gt;Replication&lt;/li&gt;
&lt;li&gt;Quorum reads and writes&lt;/li&gt;
&lt;li&gt;Vector clocks&lt;/li&gt;
&lt;li&gt;Sloppy quorums&lt;/li&gt;
&lt;li&gt;Hinted handoff&lt;/li&gt;
&lt;li&gt;Read repair&lt;/li&gt;
&lt;li&gt;Merkle trees&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At staff level, do not just define these mechanisms. Explain why Dynamo chose them and which workloads are compatible with those trade-offs.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Explain Cassandra
&lt;/h2&gt;

&lt;p&gt;Cassandra combines Dynamo-inspired distribution with an LSM-tree-based storage engine.&lt;/p&gt;

&lt;p&gt;A strong discussion may include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Partition keys&lt;/li&gt;
&lt;li&gt;Tunable consistency&lt;/li&gt;
&lt;li&gt;Commit logs&lt;/li&gt;
&lt;li&gt;Memtables&lt;/li&gt;
&lt;li&gt;SSTables&lt;/li&gt;
&lt;li&gt;Bloom filters&lt;/li&gt;
&lt;li&gt;Compaction&lt;/li&gt;
&lt;li&gt;Tombstones&lt;/li&gt;
&lt;li&gt;Repair&lt;/li&gt;
&lt;li&gt;Hot partitions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The schema must be designed around queries. Poor partition-key selection can undermine an otherwise scalable architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Explain Google File System and Bigtable
&lt;/h2&gt;

&lt;p&gt;These systems show how infrastructure components can be composed.&lt;/p&gt;

&lt;p&gt;Google File System is optimized around large files, sequential access, append-heavy workloads, and frequent machine failure.&lt;/p&gt;

&lt;p&gt;Bigtable builds a distributed, sorted storage abstraction while relying on other infrastructure for persistent storage and coordination.&lt;/p&gt;

&lt;p&gt;The broader staff-level lesson is that architecture is shaped by workload assumptions. A design that is excellent for one environment may be inappropriate for another.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a Strong Staff Answer Looks Like
&lt;/h2&gt;

&lt;p&gt;A staff-level candidate should be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reframe the prompt around business and technical priorities.&lt;/li&gt;
&lt;li&gt;Establish architectural principles.&lt;/li&gt;
&lt;li&gt;Identify the interfaces between major subsystems.&lt;/li&gt;
&lt;li&gt;Explain how multiple teams could own and evolve the system.&lt;/li&gt;
&lt;li&gt;Propose an incremental path rather than a risky rewrite.&lt;/li&gt;
&lt;li&gt;Compare technical complexity with operational and organizational costs.&lt;/li&gt;
&lt;li&gt;Recognize when the system should use an existing platform instead of building a new one.&lt;/li&gt;
&lt;li&gt;Discuss how the architecture behaves during rare but severe failures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Staff interviews are less about producing the largest possible diagram and more about demonstrating durable technical judgment.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Same Question Can Be Asked at Every Level
&lt;/h1&gt;

&lt;p&gt;Consider the instruction:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Design a URL-shortening service.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A junior candidate may focus on the API, short-code generation, database schema, and cache.&lt;/p&gt;

&lt;p&gt;A mid-level candidate may add traffic estimates, partitioning, replication, expiration, analytics, and abuse prevention.&lt;/p&gt;

&lt;p&gt;A senior candidate may discuss global routing, multi-region consistency, disaster recovery, hot-key protection, observability, and safe migrations.&lt;/p&gt;

&lt;p&gt;A staff candidate may ask whether the organization should build a shared link-management platform, how several product teams would integrate with it, how privacy policies would be enforced, and how the service could migrate from an existing system without breaking billions of links.&lt;/p&gt;

&lt;p&gt;The prompt stayed the same.&lt;/p&gt;

&lt;p&gt;The evaluation level changed.&lt;/p&gt;

&lt;p&gt;This is why memorizing one “correct” architecture is not enough. Your answer must reflect the depth expected from the role.&lt;/p&gt;




&lt;h1&gt;
  
  
  How Many Questions Should You Practice?
&lt;/h1&gt;

&lt;p&gt;You do not need to complete every system design question ever published.&lt;/p&gt;

&lt;p&gt;A more effective preparation plan is:&lt;/p&gt;

&lt;h3&gt;
  
  
  Junior candidates
&lt;/h3&gt;

&lt;p&gt;Practice five to eight foundational problems deeply.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mid-level candidates
&lt;/h3&gt;

&lt;p&gt;Practice approximately ten to fifteen problems covering social feeds, messaging, file storage, geospatial search, booking, and notifications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Senior candidates
&lt;/h3&gt;

&lt;p&gt;Practice fifteen to twenty problems, with additional attention to payments, infrastructure, observability, collaboration, storage, and failure handling.&lt;/p&gt;

&lt;h3&gt;
  
  
  Staff candidates
&lt;/h3&gt;

&lt;p&gt;Practice fewer problems at greater depth. Add production case studies and distributed-systems papers to your preparation.&lt;/p&gt;

&lt;p&gt;The complete &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m"&gt;64-question system design roadmap&lt;/a&gt; can help you select problems that match your target level.&lt;/p&gt;

&lt;p&gt;For every problem, use three passes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Learn:&lt;/strong&gt; Study the architecture and central trade-offs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reconstruct:&lt;/strong&gt; Design the system again without looking at the solution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Defend:&lt;/strong&gt; Explain failures, alternatives, costs, and why your decisions fit the requirements.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The third pass is where interview readiness develops. The fastest way to test it is a timed mock interview, where someone else pushes on your weakest decision. This &lt;a href="https://www.designgurus.io/blog/system-design-mock-interview" rel="noopener noreferrer"&gt;system design mock interview guide&lt;/a&gt; shows how many mocks to do at each stage and which platforms to use.&lt;/p&gt;




&lt;h1&gt;
  
  
  Choosing the Right System Design Preparation Path
&lt;/h1&gt;

&lt;p&gt;Your preparation resources should match your current level.&lt;/p&gt;

&lt;p&gt;Newer engineers may begin with &lt;a href="https://www.designgurus.io/course/grokking-system-design-fundamentals" rel="noopener noreferrer"&gt;Grokking System Design Fundamentals&lt;/a&gt; to build familiarity with scalability, databases, caching, replication, partitioning, messaging, and other architectural building blocks.&lt;/p&gt;

&lt;p&gt;Junior and mid-level candidates can continue with the original &lt;a href="https://www.designgurus.io/course/grokking-the-system-design-interview" rel="noopener noreferrer"&gt;Grokking the System Design Interview&lt;/a&gt;, which applies those concepts to classic interview questions.&lt;/p&gt;

&lt;p&gt;Senior and staff candidates should add &lt;a href="https://www.designgurus.io/course/grokking-system-design-interview-ii" rel="noopener noreferrer"&gt;Grokking the System Design Interview, Volume II&lt;/a&gt;, where the emphasis moves toward more complex distributed systems, deeper failure analysis, and defensible architectural decisions.&lt;/p&gt;

&lt;p&gt;Candidates working with a limited preparation window can also use the &lt;a href="https://www.designgurus.io/course/system-design-interview-crash-course" rel="noopener noreferrer"&gt;System Design Interview Crash Course&lt;/a&gt; as a structured review of system design frameworks and modern design problems.&lt;/p&gt;

&lt;p&gt;The broader &lt;a href="https://www.designgurus.io/system-design-interview" rel="noopener noreferrer"&gt;DesignGurus System Design Interview Guide&lt;/a&gt; can serve as a central reference for frameworks, concepts, questions, and study resources.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Takeaway
&lt;/h1&gt;

&lt;p&gt;The best system design preparation is not based on solving the greatest possible number of questions.&lt;/p&gt;

&lt;p&gt;It is based on practicing the right questions at the right depth.&lt;/p&gt;

&lt;p&gt;Junior engineers should build confidence with focused, single-concept systems.&lt;/p&gt;

&lt;p&gt;Mid-level engineers should learn to connect components into scalable end-to-end architectures.&lt;/p&gt;

&lt;p&gt;Senior engineers should anticipate failures, defend trade-offs, and account for operational complexity.&lt;/p&gt;

&lt;p&gt;Staff engineers should shape the problem, guide long-term architecture, and reason across systems, teams, and organizational constraints.&lt;/p&gt;

&lt;p&gt;As you move up the engineering ladder, the interviewer becomes less interested in whether you know a particular component and more interested in whether you can make sound decisions under uncertainty.&lt;/p&gt;

&lt;p&gt;That is the real progression from junior to staff-level system design.&lt;/p&gt;

</description>
      <category>distributedsystems</category>
      <category>systemdesign</category>
      <category>ai</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Must do system design interview questions required for each software engineering level.</title>
      <dc:creator>Arslan Ahmad</dc:creator>
      <pubDate>Sat, 09 May 2026 16:07:42 +0000</pubDate>
      <link>https://dev.to/arslan_ah/must-do-system-design-interview-questions-required-for-each-software-engineering-level-3b9</link>
      <guid>https://dev.to/arslan_ah/must-do-system-design-interview-questions-required-for-each-software-engineering-level-3b9</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m" class="crayons-story__hidden-navigation-link"&gt;64 System Design Interview Questions, Ranked From Easiest to Hardest&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/arslan_ah" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F34147%2F2974e0a5-f688-45b5-a4c9-5fa49c257854.jpg" alt="arslan_ah profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/arslan_ah" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Arslan Ahmad
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Arslan Ahmad
                
              
              &lt;div id="story-author-preview-content-3488973" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/arslan_ah" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F34147%2F2974e0a5-f688-45b5-a4c9-5fa49c257854.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Arslan Ahmad&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Apr 12&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m" id="article-link-3488973"&gt;
          64 System Design Interview Questions, Ranked From Easiest to Hardest
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/systemdesign"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;systemdesign&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/softwaredevelopment"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;softwaredevelopment&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/interview"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;interview&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;16&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/arslan_ah/64-system-design-interview-questions-ranked-from-easiest-to-hardest-260m#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            19 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>career</category>
      <category>interview</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
