Payment System

  • Build a Payment System for E-commerce site
  • Data should be consistent
  • Do not allow users to double submit payments
  • Actual handling of payments can be done by an external service
    • Example: Stripe, RazorPay
    • Batch Payments to vendors: Tipalti??
  • NFR:
    • Latency is not important, it can take up to few seconds
    • Generate Analytics for:
      • Orders per user
      • Revenue per seller

Database

  • payments table
    • (idempotency key, amount, status)
    • (1234, ₹104, pending)
  • The Database should be strongly consistent
    • Google Spanner
    • CockroachDB

Payment Gateway

Failures

  • Payment Server dies after the table is populated with pending status
  • Payment Gateway dies and webhook is never called, hence payment stuck on pending
  • Ideas:
    • Do polling after some time, if we don’t hear back from gateway
    • If gateway does not recognize idempotency key, then delete from payments table
    • if completed/failed, update the table accordingly
    • If in-progress, do nothing!

Analytics

  • Payments DB CDC Time-Series DB
    • Orders DB sharding based on seller ID
    • Revenue DB sharding based on buyer ID