Book Seller · Interview calculation example
From 10K QPS to a Storage Decision
Translate traffic into events, transactions, mutations, bytes, backlog, and key skew before selecting a database. Every value on this page is an illustrative assumption for interview reasoning.
Interview sequence
- Classify API traffic: separate purchase intents, status reads, seller updates, and background work.
- State average and peak: peak drives burst capacity; average drives daily storage and sustained processing.
- Trace one event: count transaction boundaries, statements, row mutations, external calls, and payload bytes.
- Model data growth: include indexes, metadata, replicas, retention, and archival.
- Find the serialization point: estimate demand for one ISBN and one listing.
- Model the queue: calculate backlog growth, drain rate, and waiting time.
- Apply semantics: consistency, query shape, and ownership choose the storage model.
- Benchmark the candidate: validate the exact schema, indexes, durability, hardware, and skew.
Reference envelope
| Quantity | Illustrative result |
|---|---|
| Peak purchase requests | 10,000/s |
| Average at 1–10% of peak | 100–1,000/s |
| Orders per day | 8.64M–86.4M |
| Order size with indexes | 0.5–1 KB |
| Order growth per day | 4.3–86 GB |
| 90-day hot order storage | 0.4–7.8 TB |
| Matching lookups at peak | Up to 10,000/s |
| Lifecycle row mutations | About 4–6/order |
| Peak logical mutation rate | About 40K–60K/s |
| Immediate matcher transaction | Potentially 1/order |
The lower storage bound combines 100 orders/s with 0.5 KB. The upper bound combines 1,000 orders/s with 1 KB. WAL, MVCC versions, replicas, page slack, and backups increase physical storage and write bandwidth.
One short relational transaction
BEGININSERT order(status = 'PENDING')SELECT cheapest eligible listing FOR UPDATE SKIP LOCKEDUPDATE listing → HELD by orderUPDATE order → FOUNDCOMMITThis is one transaction containing several statements. The lock spans local database work measured in milliseconds. Seller confirmation and payment continue as later idempotent workflow steps.
Queue rate and backlog
backlog growth/s = producer rate − consumer ratedrain rate/s = consumer rate − new arrival ratedrain time = backlog / drain rate| Phase | Incoming | Workers | Backlog change |
|---|---|---|---|
| 30-second spike | 10,000/s | 2,000/s | +8,000/s → 240K |
| After spike | 500/s | 2,000/s | −1,500/s → 160 s drain |
The queue shapes instantaneous database pressure. Batching, deduplication, and coalescing can reduce database work. Sustained consumer capacity covers average production plus the required backlog-clearing margin.
Queue keys follow ordering
| Stream | Key | Property |
|---|---|---|
| Purchase requests | order_id | Even worker distribution |
| Inventory events | isbn | Ordered changes per book |
| Payment events | order_id | Ordered payment lifecycle |
| Order status | order_id | Ordered state transitions |
The relational listing claim arbitrates competing buyers. A popular ISBN can saturate one ISBN-keyed lane, while order-keyed purchase work spreads across partitions.
State-change-driven rematching
no eligible listing → WAITING_FOR_INVENTORYNewListing(isbn) → wake bounded waiting ordersThis flow turns repeated empty searches into useful work triggered by new inventory. It preserves queue capacity for fresh requests and real state changes.
Illustrative planning ranges
| Technology | Interview planning instinct | Role here |
|---|---|---|
| PostgreSQL | About 3K–10K write-heavy OLTP tx/s per strong primary; 10K–30K calls for careful engineering | Primary orders, listings, holds, and claims |
| MongoDB | Tens of thousands of ordinary operations/s per substantial shard, followed by horizontal scale | Document-centric domains |
| Cassandra | About 10K–50K simple mixed operations/s per production node class; 100K+ cluster workloads | Append and history workloads |
| Elasticsearch | About 10K–50K indexed documents/s for a serious tuned cluster; search throughput varies by query | Catalogue and search projection |
| Neo4j | Hundreds to low-thousands of complex graph transactions/s as a planning starting point | Recommendation or fraud graph |
These ranges are rough discussion anchors. Real capacity comes from workload-specific benchmarks with the chosen consistency, schema, indexes, payloads, hardware, replication, and failure reserve.
Threshold map
| Workload shape | First candidate |
|---|---|
| Under 1K transactional writes/s | PostgreSQL |
| 1K–10K transactional tx/s | PostgreSQL on suitable hardware |
| 10K–30K complex ACID tx/s | PostgreSQL with benchmarking, tuning, and contention analysis |
| 30K–100K independent document writes/s | MongoDB or Cassandra, selected by data model |
| 100K–1M+ simple distributed writes/s | Cassandra-class architecture |
| Full-text, ranked, or faceted queries | Elasticsearch derived index |
| Multi-hop relationship queries | Neo4j graph projection |
Book Seller conclusion
- One relational authority keeps orders, listings, and reservations inside one transactional boundary.
- The matching index follows
(isbn, status, price)and serves the cheapest eligible listing lookup. - A queue accepts the 10K/s burst and controls matcher throughput according to the latency target.
- Read replicas and archival isolate order history, seller reporting, and analytics from the claim path.
- Measured hot-key distribution guides partitioning, admission control, and fairness policy.
Recall test
- Which assumption drives daily storage most strongly?
- How many database transactions occur in the local matching step?
- How long does the example queue take to drain?
- Which key partitions purchase requests?
- Which measurement reveals a hot ISBN?