Design a scalable database schema for an e-commerce platform that supports millions of transactions per day.

Instruction: Outline your approach to designing a database schema, considering factors such as scalability, performance, and data integrity.

Context: This question evaluates the candidate's ability to design complex database systems that can handle high volumes of transactions efficiently while maintaining data integrity.

Updated

Official answer

Define peak traffic, order lifecycle, inventory rules and recovery goals. A million transactions spread evenly over a day is about 11.6 per second; peaks and transaction complexity determine capacity requirements.

Start with explicit entities: customers; products/SKUs; inventory by SKU/location; orders; order_lines; payment_attempts; shipments and shipment_lines. Give each row a stable key and enforce relationships. Order lines record quantity, currency and transaction-time unit price; shipping addresses are purchase-time facts, distinct from a customer's current address. Use controlled payment-provider references rather than storing unnecessary payment secrets.

Reserve inventory with an atomic, concurrency-safe operation and create the corresponding order/reservation state within the intended transaction. Use a scoped idempotency key for checkout retries. External payments can have unknown outcomes: reconcile provider state and prevent duplicate charges rather than assuming a database rollback undoes a payment. A transactional outbox can publish committed changes for downstream processing.

Index measured access paths, archive by retention rules, and consider replicas, partitioning or sharding only when justified. Load analytics into separately defined facts so reporting does not multiply order and payment rows. Test hot products, concurrent checkout, retries, refunds, partial shipment and restore. Distribution and eventual consistency do not automatically preserve every inventory or financial invariant.

Related Questions