Schema design · mid
Data modelling and normalisation
Model each real-world thing as a table with a key, link them with foreign keys (one-to-many with a column, many-to-many with a junction table), and normalise so each fact is stored once, which avoids update anomalies.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- One-to-many: the 'many' side holds the foreign key (orders.user_id). Many-to-many: a junction table with two foreign keys and a composite primary key (shift_applications(shift_id, worker_id)), often with its own columns (status, applied_at).
- 1NF: atomic values, no repeating groups (no 'tags' comma lists). 2NF: every non-key column depends on the whole key. 3NF: no column depends on another non-key column (store city_id, not city plus state in every row).
- Keys: surrogate (bigint identity or UUID) vs natural (email, PAN). UUIDv7 (Postgres 18 has uuidv7()) is time-ordered, so it indexes better than random UUIDv4.
- Money: integer paise or NUMERIC, never floating point. Time: timestamptz in UTC.
- Snapshots are not duplication: order_items stores the price at purchase time, because product prices change later.
- Soft deletes (deleted_at) vs hard deletes: soft deletes keep history but every query must filter, and UNIQUE constraints need a partial index.
- Design from the queries: list the screens and their queries, then check each is answerable with joins and indexes.
The red pen
Common traps: mistake → fix
Mistake: Store order items as a JSON array in orders to avoid a join
Fix: you lose constraints, easy querying and indexing per item.
Mistake: Copying the product price into order_items breaks normalisation
Fix: it is a historical fact about the order, not duplication.
Mistake: Use FLOAT for prices
Fix: floating-point rounding errors; use integer paise or NUMERIC.
Easy to hard
Questions interviewers ask, easy to hard
- Design the schema for a food-ordering app: users, restaurants, menu items, orders.
- How do you model many-to-many?
- Explain 1NF, 2NF and 3NF in simple words.
- UUID or auto-increment id? Why?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.