A schema isn't designed in a vacuum. It's a response to three constraints: how much data you have, how it will be queried, and how consistent it must be. In an interview, tie every schema decision back to one of these three, so it's clear you're designing for the problem rather than reciting a textbook.
The three driving factors#
Each factor answers one question and drives a different part of the schema. The sections below take them one at a time.
| Factor | Question | What it decides |
|---|---|---|
| Data volume | How much are we storing? | One database, or sharding and partitioning |
| Access patterns | How will the data be read and written? | Indexes and denormalization |
| Consistency | Can data be briefly out of sync? | ACID transactions (SQL) vs eventually consistent (BASE) stores |
Data volume → where the data physically lives#
Hundreds of millions of enrollments won't fit on one disk, so the data gets split across servers. If students and enrollments end up on different machines, the database can't JOIN them, so the schema has to support application-level joins: the service fetches from each store and combines the results.
Access patterns → table structure#
Say the course catalog must show each course with its number of enrolled students, instantly. In a fully normalized schema, that means counting rows in a huge enrollments table on every read. Instead, denormalize: keep an enrollment_count column on courses and update it on each enrollment. Writes get slightly more work and reads get much cheaper.
That counter works because you keep two things apart: a source of truth and a read optimization.
- Source of truth: the
enrollmentstable, one row per student per course. - Read optimization:
courses.enrollment_count, a derived value you can always rebuild fromenrollments.
Check your schema against your API. If the API has GET /students/{id}/courses, there must be a way to answer it without scanning ten tables.
Consistency → database choice#
The third factor is how wrong the data is allowed to be, even briefly. A bank transfer must be exactly right; the enrollment count on a catalog page can lag by a couple of seconds.
- Strong consistency: use a relational database like PostgreSQL, and keep related data in the same instance so you can use transactions.
- Eventual consistency: a distributed NoSQL store is fine. A new review that takes a moment to show up everywhere is acceptable.
Default to PostgreSQL for core entities like students, courses and payments, then add other stores for specific needs.
Explaining decisions: "Because X, we'll do Y"#
Knowing the three factors only helps if the interviewer hears them. Don't just draw tables. State the constraint, then the choice and its cost:
- Denormalization: "The catalog is read-heavy and must be fast, so we'll store
review_countoncourses. Keeping it in sync adds write logic, but it avoids aCOUNT()on every read." - Distribution: "Data will reach petabytes, so we'll shard by
student_id. That rules out JOINs across students in the database, so the service layer will combine those results." - Consistency: "Payments are lower volume but must never double-charge, so that service keeps a normalized schema in PostgreSQL with ACID transactions."
Key takeaways#
- Every schema decision traces back to data volume, access patterns or consistency.
- Large volume forces data apart, which means application-level joins.
- Access patterns justify indexes and denormalized counters. Keep a normalized source of truth.
- Consistency needs pick the store: ACID for money, eventual consistency for counts and reviews.
- In an interview, phrase decisions as "because X, we'll do Y, at the cost of Z".