Database Design Interview: A 7-Step Framework

A seven-step way to answer a database design interview: access patterns, entities, keys, indexes, consistency, scaling and failure.

In this chapter

A database design interview in seven steps

More on Database design case studies

Keep learning

Overview

a short text row, a profile without photo the RAM of a large server is a few hundred GB a video platform’s yearly uploads Q&A site, 100 million users × 2 KB per profile Short-video app, 1 billion users × 2 uploads × 50 MB, plus metadata total 106 TB/day about 100 PB/day (100,006 TB) Rentals, 1 million listing changes × 15 MB of photos 15,000 TB/day 15 TB/day Ephemeral photos, 500 million users × 10 snaps, 20% of them 5 MB videos 10 PB/day 9 PB/day Relational (PostgreSQL, MySQL) Structured rows, joins, transactions, constraints such as unique email or no double booking. Key-value (DynamoDB, Redis with persistence) Get and put by a known key at very high rates: sessions, feature flags, carts. No queries other than by key. Wide-column (Cassandra, ScyllaDB, Bigtable) Huge append-heavy data read by partition key: messages, timelines, sensor rows. Document (MongoDB, Firestore) Self-contained nested records whose shape varies. Search index (Elasticsearch, OpenSearch) Full-text search, ranking, filters and facets. A derived copy, seconds behind. Not the source of truth. Object storage + CDN (S3, GCS + a CDN) Photos, video, backups, exports: large immutable bytes. In-memory cache (Redis, Memcached) Hot reads, counters, rate limits, short-lived data. Time-series / columnar (ClickHouse, TimescaleDB, BigQuery) Events and metrics aggregated by time and dimension. Weak at point updates and lookups by id. Graph (Neo4j, Neptune) Multi-hop questions: friends of friends, fraud rings, recommendations. For one hop, an indexed edge table is simpler. Question it answers Output on the board 1 Requirements What must work, how fast, and how fresh? 2 Estimation How big and how busy? 3 Entities What are the nouns and how do they connect? 4 Access patterns Which queries run most? 5 Stores Which engine holds which data? One store per data type, source of truth marked 6 Partitioning How does it split when one machine is not enough? 7 Consistency and failure What may be stale, and what happens when a box dies? Votes, scores and feeds Derived counters and a hybrid push/pull feed Bytes, metadata, events Three orders of magnitude, three stores Never sell a night twice A constraint per night inside one shard Data that must disappear TTL, tombstones and bounded storage Flash sale The last unit Atomic decrement, hold, guarded capture Food delivery Which database? One store per job, split on measurement Cache stampede One hot key expires Stale-while-revalidate, lock, jitter Live final Tens of millions at once CDN arithmetic and pre-scaling Chat model The answer is written live GPU queue, batching, token streaming Product Q&A Retrieve, then answer Hybrid search, tools, injection defence One seat, many stretches Short lock, hold row, bitmask update Group chat Many sockets, one register Directory, cursors, client message ids chapters · database design case studies A database design interview in seven steps

1. Clarify the requirements, one feature at a time

Three numbers to ask about for each feature: Consistency: must every reader see the latest write (strong), must the writer see their own (read-your-writes), or is a few seconds behind fine (eventual)? Notice how one feature can decide the core store. A rentals site is 99% reads that tolerate staleness, yet the booking path needs a transaction and a no-overlap rule, which is the reason it keeps a relational database at its centre. The interview format itself is covered in how these interviews run.

2. Estimate, and get the units right

Powers of ten you will use Bytes unit Feel for it The recipe, with a worked example for a Q&A site (assumptions are mine, chosen to be round): Turn the record size up past 100 KB and the lab switches its advice: that is media, and the database should only hold a pointer. Splitting media from metadata is the single most useful line in any estimate, because the two go to different stores with different costs.

The units trap

The commonest estimation error is a factor of 1,000 hidden in the unit names. Try it before reading the table below. Estimates that circulate in study material, recomputed What went wrong

3. Name the entities and how they relate

Watch for two things the lab hints at. A relationship you read in both directions (followers and following) needs both orderings indexed, and after sharding the two orderings may live on different machines. And a parent id that leads the child's key, such as (chat_id, sent_at), keeps a parent's children together on disk, which is what step 4 wants.

4. Access patterns first, keys second

The pattern repeats: equality columns first, then the sort column, then a tie-breaker id, with a keyset cursor for paging (cursor pagination). When a query cannot be served by the main key, the answer is a second copy shaped for it: a denormalised column (denormalise) or a separate read model (read model). Text search goes to a search index (full-text search).

5. Pick a store per kind of data

Stores and when to use them Use it for Watch out for Every extra store is another system to run, back up and keep in sync. Start from a relational core plus object storage, and add a store only when a named requirement needs it. Columnar storage for analytics is explained in column stores.

6. Choose the partition key

Even spread of both rows and writes. A time-based range spreads stored rows nicely and still sends every new write to one shard. Keeps the top query on one shard. A query that does not filter by the shard key asks every shard and merges the answers. A plan for hot keys: one viral question or one celebrity can outgrow a shard. Cache it, replicate its reads, or split that key.

7. Consistency, replication and failure

Then cover the machinery: Replication. Asynchronous replicas are fast but can lose the last moments of writes on failover, and they lag (replica lag). Synchronous or quorum writes trade latency for safety (quorums). Use the safe mode for money and bookings, the fast one for the rest. Transactions. Keep each strong invariant inside one shard so it needs only a local transaction, with the right isolation level (isolation levels, locks). Cache invalidation. Write to the database first, then delete the cache entry (do not update it), and give every entry a TTL as a safety net. Deleting avoids two racing writers leaving the older value in the cache. Failure. For each box, say what happens when it dies: a replica is promoted, a cache node is rebuilt from the database, the search index is replayed from the event log. Derived stores must be rebuildable from the source of truth.

Which case study teaches what

Each case study applies the seven steps, but each one is famous for a single hard part. Pick the one whose hard part matches the question in front of you.

Running it in the room

A 45-minute round leaves about six minutes per step. Step through what to say, what to leave on the board, and the usual miss at each step. Mark the ones you would cover confidently today.

Reference: the seven steps

Each step, the question it answers and what it produces

Recap

State requirements per feature: read/write ratio, latency percentile, and the consistency level that feature needs. Name entities with keys and 1:N / N:M relationships, then list the top queries before designing any key or index. Pick a store per data type for a stated reason, with one source of truth and rebuildable derived copies. Shard only when the numbers demand it, on a high-cardinality key that keeps the top query on one shard, with a plan for hot keys. Next, the framework applied: Quora, TikTok, Airbnb, Snapchat, and the interview designs for a flash sale, food delivery, cache stampede, live final, chat model, product Q&A, Tatkal, and group chat. Key order inside a table is covered in primary key order.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.