Design a Book Seller Platform
by CombinedOliveTyrannosaurus163• Staff• 1 year ago

Security of sensitive data:

  • All payment details from users and sellers will be token encrypted in the API requests and stored in the DB with encryption as well
  • Similar strategy for the OAuth API token for thes sellers' endpoints

Pyaments should be made directly to seller from user

  • When a seller is identified, a purchase hold request is sent to the seller for the book with a 10 minute TTL
  • Then, a payment request is made to Stripe with the user's payment details as source and sellers payment details as destination
  • If the payment is successful, a purchase confirmation request is sent to the seller marking the order as complete

Sellers APIs should be called securely and politely

  • API requests to the sellers will go via an API gateway which will be responsible to use the OAuth tokens for requests and respect the ratelimits requested by sellers using a distributed rate limiter

Scale to 10K QPS and handle burst loads

  • Order service is stateless and can be horizontally scaled; requests will be load balanced
  • Have read replicas for the MySQL database; cache popular book details in memory on Order Workers
  • Details of top sellers are cached in Redis
  • SQS is partitioned on author ID. For popular authors, have multiple partitions {authorId:1, authorId:2 and so on}
  • When there are flash sales, we can have a Virtual Queue that users can join. This allows a steady stream of load to come in without overwhelming any service

Durable, strong consistency for order and payment details

  • Entry is made to the DB as soon as order request is recieved from the user. Only then is the request enqueued in SQS. In case of failures, we can have a separate service that periodically scans through pending requests in the db and enqueues them
  • Distributed lock on order ID in Redis to prevent multiple workers from working on it
  • Configure SQS with job-seen timeout to handle lost workers
  • Add idempotency keys to all purchase hold, purchase confirmation requests to sellers and payment requests to Stripe to prevent double payments
  • Similarly, add idempotency key to order requests from users to prevent duplicate orders

26

53

Your account is free and you can post anonymously if you choose.