Schema design · Design
Tables for an e-commerce order system
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Design the database tables for an e-commerce order system: customers, addresses, products from many sellers, carts, orders, payments and returns. Walk me through the main tables, keys and constraints.
Then
Follow-ups the interviewer asks next
- A customer edits their address after ordering. What does the old order show?
- One order has items from three sellers. How do shipments and seller payouts fit your schema?
- How do you store money and GST?
- Which indexes do you add for 'my orders' and for the seller's dashboard?
- The orders table reaches 2 billion rows. What changes?
The answer
What a strong answer covers
- Tables: users, addresses, sellers, products, product_variants (SKU), inventory per warehouse, carts and cart_items, orders, order_items, payments (several attempts per order), shipments (one per seller or warehouse), returns and refunds, an order status history.
- Snapshots: order items store the price, tax and title at purchase; the order stores a copy of the delivery address, so later edits don't change past orders.
- Money as
numeric(12,2)or integer paise inbigint, never float; tax per line (CGST and SGST, or IGST). Invoice numbers must be a unique, consecutive series per financial year. - Keys and constraints: bigint identity or UUIDv7 keys, foreign keys,
CHECK (qty > 0), a partial unique index for one successful payment per order, statuses as a CHECK or enum. - Indexes from the screens:
orders (user_id, created_at DESC),order_items (order_id),order_items (seller_id, created_at)for sellers,payments (order_id),shipments (order_id). - Scale: partition orders by month, archive old ones, move analytics to a warehouse.
The red pen
Common traps
Avoid:reading the current product price for old orders; one orders table with item columns; float money.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.