Optimistic checkouts.

By Filippo Conforti on October 10, 2023

Optimistic locking is a SQL database technique that does not hold row locks between selecting and updating or deleting a row. The application assumes optimistically that unlocked rows are unlikely to change before the update or delete operation.

Based on the same criteria, I would define an optimistic checkout as a process that skips payment authorization, stock availability checks, and other validations when the order is placed, assuming that the payment method is valid and that the items that were in stock when added to the shopping cart are still available. It is these assumptions that make this approach "optimistic".

Later in the order pipeline, the payment authorization and stock checks are performed, and the order is either approved or rejected based on the results. As simple as that. But why would one want to do it? What's the advantage of an optimistic approach over a pessimistic one, that implies payment authorization and stock check right when you place the order?

Performance and, therefore, conversion rate optimization are the main reasons. The payment authorization and stock availability check require additional logic that takes up server resources and slows down your checkout. The optimistic approach offloads your server, boosting checkout speed and improving conversions. Depending on your payment gateway and the compexity of your stock model, placing an order can take up to 3-4 seconds. At scale, this can actually cause database table locks and other issues, reducing your orders' throughput.

In contrast, placing an order with an optimistic approach is just writing or updating a row in a database, which takes a few milliseconds. Thus, you can easily increase your order throughput to thousands of orders per second. Technically, this can be achieved by making the checkout asynchronous. Once the order is placed, it is put into a queue, where one or more workers perform the actual validation, approving or rejecting it asynchronously.

Placing and validating orders asyncrhronously.
Placing and validating orders asyncrhronously.

Customer experience-wise, a thank you page doesn't necessarily mean that your order will be fulfilled. In the event the validation fails, the order cannot be approved and the customer needs to be notified. Even if it's not ideal, customer service—or some automated process—could suggest an alternative product or send a new checkout link if the payment failed.

I ran into this issue a while back when I purchased from apple.com. While checking out, I put the wrong expiration date on my credit card, but I regularly received my order confirmation email. The next day, Apple notified me there was a problem with my credit card and sent me a link to fix it. Which I did, getting my brand new MacBook Pro. I think other high volume ecommerce websites like Amazon or Ebay also do optimistic checkouts, so this approach can be more popular than you think.

Imagine a different scenario now. From the product page, a customer adds an out-of-stock item to their shopping cart. Upon receiving an out of stock message, the customer will probably look for an alternative product and purchase it. Rather, if the customer receives an out of stock message during checkout, the customer will likely abandon the order and the merchant will lose a sale.

The example illustrates how you might want to keep a pessimistic approach on the product page and switch to an optimistic approach as the customer gets closer to the bottom of the funnel. Additionally, you may want to consider a hybrid approach, which maintains an optimistic stock check, for example, and a pessimistic payment authorization, or vice versa.

As always, it's not a one-size-fits-all solution, and the right checkout strategy depends on a variety of factors. However, I am an advocate of the 80/20 rule. If you look at your order history and 80% or more of your orders would have been approved anyway with an optimistic checkout, I would suggest considering a switch to this approach. Your servers, customers, and conversions will appreciate the effort. If not, a checkout flow with synchronous validations might be instead your better option.

Enjoy the reading?

Subscribe to the newsletter and get a new article delivered to your inbox every week.