Book Seller · Three-tier synthesis
Book Seller Marketplace
Persist first, select one seller, hold inventory, authorize payment, confirm fulfillment, then capture. Every external call carries a stable idempotency key and every ambiguous result is reconciled.
InputISBN + max price
Scale10K QPS
External systemsSellers + payment
InvariantOne order, one charge
Tier 1 · Core
- Seller registration records endpoints, auth references, limits, and health.
- One relational transaction persists the order and claims the cheapest eligible listing.
- A queue absorbs burst traffic and workers set the database processing rate.
- Candidate selection uses live quotes or a maintained offer catalog.
- Seller hold establishes current price and inventory for a short TTL.
- One atomic claim chooses the winner.
- Payment authorization precedes seller confirmation; capture completes the charge.
- Order state and provider webhooks reconcile retries and crashes.
Canonical state
PENDING → SEARCHING → COMMITTINGHOLD_PLACED → AUTHORIZEDSELLER_CONFIRMED → CAPTURED → COMPLETEDTier 2 · Choices
PricesLive fan-out gives freshness; an offer catalog bounds external QPS.
Queue keyOrder ID distributes purchase work; ISBN orders inventory events; the listing claim resolves contention.
StorageOrders, listings, and reservations share a relational authority. Search and history can use derived stores.
WaitingUnmatched orders pause until new inventory produces a bounded wake-up event.
PaymentPlatform-managed authorization and capture supports coordinated settlement; seller-managed settlement reduces platform payment ownership.
DispatchOutbox gives atomic intent; a pending-order scanner repairs DB-to-queue gaps.
Correctness authorities
- The listing row owns platform inventory availability.
- The seller hold owns inventory sold through external channels.
- The order database owns purchase workflow state.
- The payment provider owns authorization and capture state.
- Stable idempotency keys connect every retry to its original operation.
Tier 3 · Sharp edges
- Stripe Elements or equivalent tokenizes card data in the client.
- SCA and 3-D Secure complete before capture-ready fulfillment.
- Seller OAuth secrets live in a vault; access tokens stay short lived.
- Webhook signatures, timestamp checks, event IDs, and sequence numbers prevent replay and stale updates.
- Per-seller token buckets, concurrency caps, backoff, and circuits enforce politeness.
- Hot ISBN partitions force a fairness versus throughput decision.
- Late listings turn one-shot orders into standing requests when rematching is supported.
Recall test
- What is the inventory source of truth?
- How does peak API QPS become database TPS?
- What happens when seller confirmation fails after authorization?
- Which payment step moves money?
- Why does order-ID partitioning spread purchase work?