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.

Peak input10K orders/s
Example average100–1,000/s
Order footprint0.5–1 KB
Primary pressureHot listing claims

Interview sequence

  1. Classify API traffic: separate purchase intents, status reads, seller updates, and background work.
  2. State average and peak: peak drives burst capacity; average drives daily storage and sustained processing.
  3. Trace one event: count transaction boundaries, statements, row mutations, external calls, and payload bytes.
  4. Model data growth: include indexes, metadata, replicas, retention, and archival.
  5. Find the serialization point: estimate demand for one ISBN and one listing.
  6. Model the queue: calculate backlog growth, drain rate, and waiting time.
  7. Apply semantics: consistency, query shape, and ownership choose the storage model.
  8. Benchmark the candidate: validate the exact schema, indexes, durability, hardware, and skew.

Reference envelope

QuantityIllustrative result
Peak purchase requests10,000/s
Average at 1–10% of peak100–1,000/s
Orders per day8.64M–86.4M
Order size with indexes0.5–1 KB
Order growth per day4.3–86 GB
90-day hot order storage0.4–7.8 TB
Matching lookups at peakUp to 10,000/s
Lifecycle row mutationsAbout 4–6/order
Peak logical mutation rateAbout 40K–60K/s
Immediate matcher transactionPotentially 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 → FOUNDCOMMIT

This 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
PhaseIncomingWorkersBacklog change
30-second spike10,000/s2,000/s+8,000/s → 240K
After spike500/s2,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

StreamKeyProperty
Purchase requestsorder_idEven worker distribution
Inventory eventsisbnOrdered changes per book
Payment eventsorder_idOrdered payment lifecycle
Order statusorder_idOrdered 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 orders

This 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

TechnologyInterview planning instinctRole here
PostgreSQLAbout 3K–10K write-heavy OLTP tx/s per strong primary; 10K–30K calls for careful engineeringPrimary orders, listings, holds, and claims
MongoDBTens of thousands of ordinary operations/s per substantial shard, followed by horizontal scaleDocument-centric domains
CassandraAbout 10K–50K simple mixed operations/s per production node class; 100K+ cluster workloadsAppend and history workloads
ElasticsearchAbout 10K–50K indexed documents/s for a serious tuned cluster; search throughput varies by queryCatalogue and search projection
Neo4jHundreds to low-thousands of complex graph transactions/s as a planning starting pointRecommendation 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 shapeFirst candidate
Under 1K transactional writes/sPostgreSQL
1K–10K transactional tx/sPostgreSQL on suitable hardware
10K–30K complex ACID tx/sPostgreSQL with benchmarking, tuning, and contention analysis
30K–100K independent document writes/sMongoDB or Cassandra, selected by data model
100K–1M+ simple distributed writes/sCassandra-class architecture
Full-text, ranked, or faceted queriesElasticsearch derived index
Multi-hop relationship queriesNeo4j 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

  1. Which assumption drives daily storage most strongly?
  2. How many database transactions occur in the local matching step?
  3. How long does the example queue take to drain?
  4. Which key partitions purchase requests?
  5. Which measurement reveals a hot ISBN?