bigonotes
System DesignData Modeling

What Shapes a Schema

How data volume, access patterns and consistency needs shape your tables, keys and database choice.

3 min readLast updated

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 enrollments table, one row per student per course.
  • Read optimization: courses.enrollment_count, a derived value you can always rebuild from enrollments.

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_count on courses. Keeping it in sync adds write logic, but it avoids a COUNT() 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".
Revision notes · 1 min

Core idea#

A schema responds to three constraints: data volume, access patterns and consistency. Tie every schema decision back to one of them.

The three factors#

Factor Question What it decides
Data volume How much are we storing? One database, or sharding and partitioning
Access patterns How is data read and written? Indexes and denormalization
Consistency Can data be briefly out of sync? ACID (SQL) vs eventually consistent (BASE)

Key points#

  • Large volume splits data across servers. Tables on different machines need application-level joins.
  • Access patterns justify derived values. courses.enrollment_count avoids counting the enrollments table on every read.
  • Keep a source of truth (enrollments) and a read optimization (enrollment_count) you can always rebuild from it.
  • Check the schema against the API. GET /students/{id}/courses must not scan ten tables.
  • Strong consistency: PostgreSQL, with related data in one instance for transactions.
  • Eventual consistency: a distributed NoSQL store is fine, for example for review counts.
  • Default to PostgreSQL for core entities, then add stores for specific needs.

Pitfalls#

  • Drawing tables without stating the constraint behind each choice.
  • Sharding by student_id rules out JOINs across students in the database. Plan the service-layer join.

Say it in an interview#

  • "Because X, we'll do Y, at the cost of Z."
  • "The catalog is read-heavy, so we store review_count on courses. It adds write logic but avoids a COUNT() per read."
  • "Payments must never double-charge, so they stay normalized in PostgreSQL with ACID."

Found a mistake? Email ask@bigonotes.com