shreyansh

High Level Design

A complete system-design track: storage fundamentals first, then distribution (replication, sharding, consensus), then the applied building blocks (caching, queues, rate limiting), ending in twelve full case studies. Read top to bottom — prev/next follows this order. Cases marked with a playground link have a steppable, animated simulator.

Each case follows the same skeleton: requirements → capacity estimation → API design → data model → high-level design → deep dives → bottlenecks. Three have interactive simulators.

Theory path

  1. Database Indexes
    1. Hash Indexes

      A hash index is the simplest durable index you can build. The storage engine keeps an in-memory hash map from each key t

    2. B-Tree Indexes

      A B-Tree keeps keys sorted in fixed-size pages (nodes), typically 4–16 KB to match disk blocks and SSD pages. Internal p

    3. LSM Trees and SSTables

      A Log-Structured Merge-tree splits the index into a small mutable in-memory part and many immutable on-disk parts. Write

    4. Indexes Conclusion

      btitle["B-TREE (in-place)<br/>InnoDB / Postgres"]

  2. Transactions
    1. ACID Transactions

      Atomicity — all-or-nothing across multiple writes, even across retries and crashes. Transfer 100 from A to B = debit(A)

    2. Read Committed Isolation

      Read committed provides exactly two promises:

    3. Snapshot Isolation

      Every row version carries creator/deleter transaction IDs (xmin/xmax in Postgres). At BEGIN, the transaction records the

    4. Write Skew and Phantom Writes

      Rota rule: at least one doctor on call at all times. Alice and Bob are both on call. Two concurrent transactions, one pe

    5. Serial Execution and Achieving ACID

      Serializability is the strongest isolation level and the only one with a one-sentence definition: the effect of concurre

  3. Database Internals
    1. Two-Phase Locking

      Two phases, strictly ordered per transaction:

    2. Serializable Snapshot Isolation

      Snapshot Isolation fails exactly on predicate anomalies (Write Skew and Phantom Writes): disjoint writes, invisible phan

    3. Column-Oriented Storage

      An orders table with 50 columns where the query needs 3 (SUM(amount) GROUP BY region): a row store reads all 50 columns'

    4. Data Serialization Frameworks

      svc(["Service emits event<br/>10 fields"])

  4. Replication
    1. Intro to Replication - Need to knows

      Q: Why replicate a database at all?

    2. Single Leader Replication

      Last write: 80, was written to the replication log.

    3. MultiLeader Replication - chaos

      As an alpha sigma Male myself, not a big fan of having multiple leaders. Clearly, such a setup is destined to fail and h

    4. Leaderless Replication

      In leaderless replication, there is no single leader node that coordinates write operations. Instead, write operations c

    5. Quorums

      If there are n replicas, every write must be confirmed by w nodes to be considered successful, and we must query at leas

    6. Dealing with Stale Reads

      Monotonic reads are particularly relevant in distributed systems with data replication, where data is copied and maintai

    7. Write Conflicts

      Concurrent writes: Conflicting writes that are unaware of each other at the time of writing.

    8. Conflict-Free Replicated Data Types - CRDTs

      Conflict-Free Replicated Data Types (CRDTs) are designed to enable concurrent updates and ensure eventual consistency ac

    9. Conclude Replication

      Replication is a key strategy in distributed systems to enhance availability, fault tolerance, and scalability. There ar

  5. Sharding and Partitioning
    1. Into to Partitioning or Sharding

      For very large datasets, or very high query throughput, replication is not sufficient: we need to break the data into pa

    2. Rebalancing Partitions

      Rebalancing is the process of redistributing data and requests across nodes in a cluster to handle changes such as incre

    3. Atomic Commit and Two-Phase Commit (2PC)

      Atomicity prevents failed transactions from littering the database with half-finished results and half-updated state. Th

  6. Consistency and Consensus
    1. Linearizability

      In a database with multiple nodes, inconsistencies occur because write requests arrive at different times on different n

    2. Distributed Consensus

      Distributed consensus is how a group of unreliable machines agrees on a single value — one leader, one log order, one co

    3. The Raft Consensus Algorithm - Leader Election

      https://web.stanford.edu/ouster/cgi-bin/cs190-winter20/lecture.php?topic=raft

    4. Raft Writes

      Once a leader is elected, it is responsible for handling all client write requests. Here’s how a typical write operation

    5. Coordination Services

      Coordination services are just thin layer that're built on distributed consensus algorithm like Raft (The Raft Consensus

    6. Lamport Clocks

      Lamport clocks are a mechanism used in distributed systems to assign a logical timestamp to events in order to capture t

    7. Version Vector

      Version vectors are a mechanism used in distributed systems to track the version history of replicated data across multi

  7. Databases Duel Arena
    1. Relational Vs Non-Relational DBs

      SQL vs NoSQL (not preferred terms)

    2. MySQL vs PostgreSQL

      SQL databases are particularly well-suited for handling normalized, relational data. They excel at managing data in a st

    3. MongoDB vs Cassandra

      MongoDB is a NoSQL database that is document-oriented, meaning it stores data in flexible, JSON-like documents. Unlike t

  8. Streams
    1. Stream Processing

      Stream processing is basically real-time processing of a continuous data streams as they're generated. Unlike, batch pro

    2. Kafka vs RabbitMQ

      Here is a comparison table highlighting the key differences between Kafka (a log-based message broker) and RabbitMQ (an

  9. Scaling and Load Balancing
    1. Scaling Out and Load Balancing

      Vertical scaling (scale-up) means a bigger machine: more cores, more RAM, faster NVMe. A single well-tuned box today can

  10. Caching
    1. Cache Patterns and Eviction

      Two rules interviewers listen for. First, on write in cache-aside, delete the key — don't update it: updating risks orde

  11. CDN and Edge
    1. Content Delivery and Edge

      A Point of Presence is a cluster of cache + compute + TLS-termination servers placed in carrier-neutral facilities and I

  12. API Design and Gateways
    1. API Design and Gateways

      The FAANG-default topology: gRPC inside, REST (or GraphQL) outside, translated at the gateway/edge. Quote the numbers: p

  13. Rate Limiting
  14. Messaging and Queues
    1. Messaging and Event Queues

      Synchronous RPC chains multiply failure: if service A calls B calls C, each with 99.9% availability, the chain is 99.7%

  15. Microservices Patterns
    1. Microservices Patterns

      Single edge entrypoint (Kong, NGINX/Envoy, AWS API Gateway, Spring Cloud Gateway) owning all cross-cutting concerns: TLS

  16. CAP and Consistency Models
    1. CAP PACELC and Consistency Models

      Gilbert–Lynch CAP: when a network partition occurs, a distributed read/write store chooses between consistency (every re

  17. Observability
    1. Observability and Operations

      Counters (requests, errors), gauges (queue depth, connections), histograms/summaries (latency distributions — never aver

  18. Security and Auth
    1. Security and Auth for System Design

      Every hop encrypted: client→edge, edge→service, service→service (mTLS in a service mesh like Istio/Linkerd, or at minimu

Case studies

  1. URL Shortener hld questions

    KGS key generation, hash sharding, 301 vs 302.

  2. Rate Limiter hld questions

    token bucket on Redis Lua, sliding windows, multi-DC quotas.

  3. News Feed hld questions

    hybrid fan-out, ranking, seen-filtering, cursor pagination.

  4. Twitter Timeline hld questions

    dynamic celebrity thresholds, early-rank ingest, home vs user timelines.

  5. Instagram hld questions

    media pipeline, stories TTL, feed on top of blobs.

  6. WhatsApp Chat hld questions

    connection management, message sync, E2E delivery receipts.

  7. YouTube Video Platform hld questions

    upload pipeline, transcoding DAG, CDN distribution.

  8. Uber and Lyft hld questions

    geospatial matching, dispatch, surge pricing reads.

  9. Web Crawler hld questions

    frontier sharding, politeness, dedup at crawl scale.

  10. Search Autocomplete hld questions

    trie sharding, hot-prefix cache, per-IP throttles.

  11. Notification System hld questions

    fan-out across push/SMS/email, retries, user preferences.

  12. Distributed Key-Value Store hld questions

    consistent hashing, quorum reads/writes, hinted handoff.