Sitemap
The Airbnb Tech Blog

Creative engineers and data scientists building a world where you can belong anywhere. http://airbnb.io

Avoiding Double Payments in a Distributed Payments System

14 min readApr 16, 2019

--

One of the conference rooms in our San Francisco office

Background

What is idempotency?

An idempotent request is a request that is made with identical parameters and the outcome will always be the same, consistently (the guest is charged at most once).

The Problem Statement

Solution Explained

Keep database commits to a minimum

Network communication is strictly kept separate from database transactions

Java Lambdas to the Rescue

We did not implement nested database transactions, but instead combined database instructions from Orpheus and the application into a single database commit, strictly passing Java functional interfaces (lambdas).

Handling Exceptions — To Retry or Not to Retry?

Categorizing “retryable” and “non-retryable” exceptions

Clients Play a Vital Role

How to Choose an Idempotency Key?

Each API Request Has an Expiring Lease

Recording the Response

Avoid Replica Databases — Stick to Master

A duplicate payment created as a result from replica lag

Response 1 is not found on the replica in the retry attempt (Request 2)

Duplicate payment avoided by storing idempotency information only on master

Response 1 found immediately on master and returned in the retry attempt (Request 2)

Final thoughts

--

--

The Airbnb Tech Blog
The Airbnb Tech Blog

Published in The Airbnb Tech Blog

Creative engineers and data scientists building a world where you can belong anywhere. http://airbnb.io

Responses (41)