Stripe | Web Application

Payment Flow

  1. A User clicks Checkout Button
  2. The Server creates checkout session for this Order and redirects the User to Stripe Payment Page
  3. The User types in his/her payment information and clicks Pay Button.
  4. Stripe processes this payment.
  5. If it succeeds, Stripe redirects the User to Success Page and sends the Event to the Server.
  6. The Server’s Webhook catches Stripe’s Event.
  7. The Server fullfills this Order.

png

Data Consistency in Subscription Systems

Ensuring data consistency within our payment system is of paramount importance. The main areas of focus are:

  1. Inter-Database Consistency: Ensuring synchronization between the Backend Database, Stripe’s Database, and the Client-side Session.
  2. Temporal Consistency: Maintaining accurate and current data in real-time.

Inter-Database Consistency

A seamless logical data flow is imperative for managing inter-database consistency. The pivotal moments for data alteration occur when:

  • A user initiates a payment.
  • Stripe communicates an Event back to the Server.

For events relayed from Stripe, the primary task is to synchronize the Backend Database. This is achieved by invoking the update subscription function. Subsequently, the update points info function is employed to align the session data. It’s essential to understand the hierarchy here:

  • Primary: Keeping Stripe’s Database and Backend Database synchronized.
  • Secondary: Adjusting the Client-side Session based on the Backend Database.

Temporal Consistency

Managing data consistency over time is slightly more intricate due to its real-time nature. When a user aims to expend points, the system must:

Verify if the current time is within the subscription’s active window (as recorded in the session).

  • Yes: Directly retrieve and update point information from the Backend Database.
  • No:
    1. First, pull the latest subscription data from Stripe (as it houses the most recent information). Update the Backend Database with this information.
    2. Attempt point expenditure and adjust point values in the Backend Database. It’s crucial to note that two distinct updates to the Backend Database might be necessary here. The first guarantees updated subscription data, and the second confirms point expenditure (which could potentially fail if points are insufficient).

For both scenarios, the concluding step is to refresh the Client-side Session to mirror the Backend Database.

Chengzhan Gao
Chengzhan Gao
高程展|Graduate Student at UCSD

My interests include web development, game development and machine learning.