Original practice scenario: Design a hypothetical marketplace checkout for a product with ten units and heavy concurrent demand. Customers can abandon checkout, retry payment and cancel orders.
Read model answer +
Separate stock reservation, payment and order confirmation into explicit states. The inventory invariant must hold under concurrent attempts and repeated callbacks, not just a successful checkout sequence.
Work through it
Use an authoritative per-item quantity with atomic conditional reservation; assign each checkout attempt a stable reservation identity and expiration.
Record payment outcomes idempotently and define compensation when payment succeeds after the reservation expires or fulfillment becomes impossible.
Release expired or cancelled reservations through a recoverable process and reconcile inventory, orders and payments using durable state transitions.
Tradeoffs to discuss
Long reservations reduce customer frustration but hide stock from other shoppers; short reservations increase availability while complicating slow payments.
Common pitfalls
A client-side countdown is not an authoritative expiration decision.
Do not refund or release twice when cancellation, timeout and payment notifications race with each other.
Original practice scenario: A hypothetical fulfillment dataset has orders, order lines, packages and package events. Explain how to calculate distinct shipped orders per day when orders span multiple packages.
Read model answer +
Define what shipped means at order grain before joining event tables. One order may have several lines, packages and scans, each of which can multiply the apparent count.
Work through it
Choose the qualifying event and time rule, including whether the order counts after its first package or only after all required packages ship.
Deduplicate package events by event identity, derive the relevant shipment timestamp per package, then aggregate to one row per order.
Join that order-level result to the reporting calendar and group by the declared time zone, preserving unshipped orders for separate completeness controls.
Tradeoffs to discuss
First-package and fully-shipped metrics answer different questions; either can be valid if its population and timestamp are explicit.
Common pitfalls
COUNT DISTINCT can hide multiplication while leaving sums and timestamps wrong.
Handle split shipments, reversed scans and missing package mappings instead of treating every event as a completed order.