Data Models and Storage for Product Features

Topics Covered

Entities and Relationships for Product Features

Start from the nouns in the user flows

Relationships and their cardinality

Read the screen, count the reads

IDs that work for the product

Commerce entities are different

What the interviewer is checking

A worked pass in three minutes

In a product architecture interview the data model is where the product turns into something you can build. The requirements step gave you user flows and screens. The API step gave you the requests those screens make. The data model has to answer a simpler and harder question: what are the things the product remembers, how do they relate, and can every screen be served from them quickly? Interviewers spend real time here because a weak data model leaks into everything after it. A feed that cannot be paginated, a like count that locks a row, a privacy setting that cannot be checked without a join across three services: all of these start as a modelling choice made in two minutes on a whiteboard.

This lesson works through that step for the two families of products you will meet most often, social products and commerce products. It does not re teach database internals; the System Design Fundamentals course covers indexes, replication and storage engines. The focus here is on product shaped modelling: which entities exist, which store each one belongs in, how you shape data for the screens that read it, and how you change it safely once real users depend on it.

Start from the nouns in the user flows

The fastest reliable way to find entities is to reread the user flows you agreed and underline the nouns that the product must remember after the request ends. For a photo sharing app the flows might be: a creator uploads a photo with a caption, a viewer follows the creator, the viewer scrolls a home feed, the viewer likes and comments. The nouns are user, photo or post, media object, follow, like, comment and feed. Not every noun is an entity. The feed is usually a derived view built from posts and follows, not something users create directly, so you mark it as a read model and come back to it later (the feeds lesson owns that design).

For each entity, write three or four fields that matter to the product, not every column. Interviewers do not want a full DDL listing. They want to see that you know what identifies the entity, who owns it, when it was created and which field drives the product behaviour you are about to discuss.

sql
1users(id, handle, display_name, avatar_url, created_at, home_region)
2posts(id, author_id, caption, visibility, created_at, deleted_at)
3media(id, post_id, kind, storage_key, width, height, status)
4follows(follower_id, followee_id, created_at)
5likes(post_id, user_id, created_at)
6comments(id, post_id, author_id, body, created_at, deleted_at)

Notice the fields that are already doing product work. visibility will drive privacy. deleted_at will drive deletion. status on media tracks whether processing has finished, so the client can show a placeholder. home_region on users matters once the product goes multi region. Each of those fields is a hook for a deep dive later, and naming them early shows the interviewer you are modelling behaviour, not just storage.

Relationships and their cardinality

Once the entities are listed, draw the relationships and say their cardinality out loud. A user has many posts. A post has many comments and many likes. Follows are many to many between users, and they are directional: Ana following Ben does not mean Ben follows Ana. A friendship model, by contrast, is symmetric and usually needs a request and accept state. Saying which one the product has changes the queries you need. Directional follows need two lookups, who do I follow and who follows me, and those two lists can have very different sizes for a celebrity account.

Cardinality also tells you where a relationship should live. A one to many relationship with a bounded child list, such as an order and its line items, can be stored together with the parent. A one to many relationship with an unbounded child list, such as a post and its comments on a viral post, must be stored separately and paginated. Many to many relationships almost always get their own table or edge list keyed by both sides.

One screen touches several entities; the data model decides how many reads that takes.

Read the screen, count the reads

A useful check before you move on is to take the busiest screen and count how many entity reads it needs. The post detail page needs the post, its author's name and avatar, the media variants, the like count, whether the viewer has liked it, and the first page of comments with each commenter's name. Written naively, that is six or seven separate reads, some of them per comment. That number is fine for a low traffic page. It is not fine for a feed card rendered fifty times per scroll. Counting the reads is how you discover where you will need denormalised copies or precomputed aggregates, which section three covers.

IDs that work for the product

Choose identifiers deliberately. Auto increment integers are simple in one database but leak business volume (an order number of 1,000,207 tells competitors how many orders you have had) and are awkward to generate across shards. Random UUIDs avoid both problems but scatter inserts across an index and sort meaninglessly. Many products use time ordered IDs, such as a 64 bit value with a timestamp in the high bits, or UUID version 7. These sort by creation time, which makes them natural cursors for pagination, and they can be generated on any server without coordination. Public facing IDs such as the short code in a share link are often a separate field, so you can keep internal IDs private.

Commerce entities are different

Social products are dominated by many small writes and huge read fan out. Commerce products care more about correctness. The core entities are product (the catalog idea of a thing), listing or SKU (a sellable variant with a price), inventory (how many exist and where), cart, order, order line, payment and shipment. Two modelling rules matter more here than anywhere else.

First, an order must snapshot what the buyer agreed to. An order line copies the item name, the unit price, the currency and the tax at the moment of checkout, rather than holding only a foreign key to the live listing. If the seller raises the price tomorrow, the receipt, the refund and the accounting must still show what was actually charged. Second, money is stored as integers in minor units with an explicit currency, never as floating point, and every state change on an order, such as paid, shipped or refunded, is recorded as an event or history row so support can explain what happened.

An order line freezes the price and name the buyer saw, instead of pointing at the live catalog.

What the interviewer is checking

At this step the interviewer is looking for three things. Can you find the entities from the flows without being led? Do you say the cardinality and direction of relationships, and do those choices match the product? And do you connect the model back to the screens, so that it is obvious every screen can be served? A candidate who lists tables without ever mentioning a screen or a query tends to get a follow up question like how would you render the profile grid with this, which is a sign the model was drawn in isolation. Keep the model small, keep it tied to the flows, and flag the two or three fields that will matter in the deep dives.

A worked pass in three minutes

Here is how the entity step can sound in the room for a marketplace prompt. The flows are: a seller lists an item with photos, a buyer searches and filters, the buyer messages the seller, makes an offer and checks out. The nouns that persist are user, listing, photo, conversation, message, offer, order and review. You say: listings belong to one seller, so seller ID is a foreign key; a listing has a state field with values such as active, reserved and sold, because the product shows different buttons in each state; conversations are between one buyer and one seller about one listing, so the conversation key is the triple; offers belong to a conversation and have their own state; and the order snapshots the listing's title and agreed price.

That takes about three minutes, and it has already set up the most interesting deep dives: the listing state machine, which must stop two buyers checking out the same item, and the conversation model, which must stay readable when a listing is deleted. You have not written a single column type, and you do not need to. The interviewer can see the product in the model, which is the purpose of this step.

Model behaviour, not just storage

Fields like visibility, deleted_at, media status and home_region each carry a product behaviour. Naming them in the first pass of the data model sets up your deep dives and shows the interviewer you are designing the product, not a generic schema.