BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Couchbase Details Its Distributed ACID Transaction Architecture

Couchbase Details Its Distributed ACID Transaction Architecture

This item in japanese

Bookmarks

Couchbase recently published a detailed explanation of its distributed multi-document ACID transaction implementation. In its blog post, Couchbase lays out how its DB engine supports the Monotonic Atomic View consistency model, which is a strengthened version of the Read Committed consistency model.

In Couchbase's architecture, there is no central transaction coordinator. Each client is responsible for the coordination of its transactions. The SDK performs this coordination under the hood. Denis Rosa, the blog post author, gives an example of a classic money transfer scenario between two users. In this example, the user needs to deduct a certain amount from one user's balance and increase another user's balance by the same amount. The following image depicts the transaction coordination process.

Distributed Transaction Example in Couchbase
Source: https://blog.couchbase.com/distributed-multi-document-acid-transactions/

vBucket is a Couchbase-internal unit of sharding. Each vBucket has a single document responsible for the transaction log called an Active Transaction Record (ATR). Before the first document mutation, the client adds a new entry in the mutated record's vBucket ATR with the transaction id and the "Pending" status.

Next, the client adds the mutated content in each record's "Meta" section. The meta section (also known as xAttrs) is an area when a client can store metadata. The mutated documents can reside in separate vBuckets and physical nodes.

Once the client completes all mutations, it marks the transaction as "Committed" in the ATR and updates it with the list of involved document ids. Then, the client updates all involved documents with the changes it previously staged in the metadata section, replacing their document body and removing the transaction metadata information. Finally, the transaction is marked as "Completed" and removed from the ATR.

To support Monotonic Atomic View, Couchbase clients check each document's metadata section as they read it. If they detect an existing transaction in the document's metadata, they read the relevant transaction's details from the ATR that holds it. If another client marked the transaction as "Committed," the client uses the staged mutation in the record's metadata instead of the main document body. This client cooperation guarantees atomicity and isolation in the face of errors and failures. The image below details this sequence.

Transaction isolation guarantee with client cooperation
Source: https://blog.couchbase.com/distributed-multi-document-acid-transactions/

Couchbase achieves durability by having many replicas for each vBucket. The user can configure the number of replicas required. Also, users can specify their durability requirements when operating, which controls the tradeoff between how fast clients get an acknowledgment for their writes and "how persistent" their data is. Both these settings affect the transaction operation as well.

Additionally, if something fails (e.g., a transaction times-out), the transaction library periodically runs cleanup jobs to keep all the documents as small as possible.

Couchbase is a popular open-source, distributed multi-model NoSQL document-oriented database. It exposes a key-value store with managed cache, indexers for fast queries, and a query engine for executing SQL-like queries.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT