Data layer
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Databases for system design interviews: the 60-second story

    Databases in interviews

    “Which database would you use?” Then the follow-ups start.

    It probes reasoning, not product knowledge. A short design with clear reasons beats six databases and no keys.

    A kirana shop keeps four places. Each answers one question.

    Ledger: the truth. Shelf: a cache. Godown: object storage. Price list: a search index rebuilt from the ledger.

    Which store first?

    Bad: “NoSQL, because it scales”

    Scale is a number. You trade away transactions for writes you don’t have.

    Good: Default, then earn it

    PostgreSQL first. Add a store only for a pattern it serves badly.

    Five questions, in order. The brand name comes out last.

    Entities, access patterns, numbers, guarantees, then keys and stores. No key fits a pattern? Back to step 2.

    40k/s

    rider pings, each overwriting the last

    200,000 riders ping every 5 s. Orders peak near 350/s, easy for one primary. Pings are a different job, for Redis GEO.

    Menu search needs typo tolerance. Write each dish edit to PostgreSQL and the index?

    The trick

    Never dual-write: one failure and they drift forever. Stream row changes by CDC; the index trails about a second.

    “Latest 50 messages, newest first.” Now show me the key.

    Start with what you filter on, continue with what you sort by. Same idea in SQL and NoSQL.

    Label each operation, not the whole system

    1. Debit wallet + create order: one transaction
    2. Claim a username: unique constraint
    3. “My orders” right after ordering: read your writes
    4. Like counts: eventual, batched from Redis

    Say it like this

    PostgreSQL is the system of record. Each other store earns its place with a pattern and a number; name its key, its consistency and how it stays in sync.