Reliable Publishing To The Blockchain
How to update your local DBMS and publish to the blockchain in one transaction

So you want to publish to the blockchain what you save in your own database? Read on…


Your accounting system stores invoices in its database. Suppose you want to do triple-entry accounting by publishing your invoices also to the blockchain so you have a copy in the distributed ledger. What can you do to make this reliable?

The Problem

It turns out it's not trivial to update both systems in one go. The intuitive approaches many developers would use do not work. To see why, let's try:

Attempt 1: Commit in DBMS, then push to the blockchain

In this approach, one would:

  1. Update and commit the local DBMS
  2. If this worked, then push to the blockchain

If there is a crash between 1 and 2 then you will have a DBMS update, but no blockchain publication.

Attempt 2: Push to blockchain, then update / commit in DBMS

Here we go:

  1. Push to the blockchain
  2. If this worked, then update / commit the DBMS

If there is a crash in between 1 and 2 then you will have published in the blockchain, but without DBMS update.

The Solution

Screenshot 2019-03-12 16.10.32.png

Use JTA/XA transactions and a message queue to create an atomic transaction:

  1. Create a JTA transaction
  2. Update your XA-capable DBMS
  3. Post a message to an XA-capable queue requesting a blockchain publication
  4. Commit the JTA transaction

The key point is that the success of 2 and 3 coincide with the commit of 4. If there is no commit, then none of 2 or 3 will happen.

Then have a background component that:

  1. Reads a message from the queue
  2. Publishes in the blockchain accordingly
  3. If this worked, remove the message from the queue

If there is a failure / crash between 1 and 2 then the publication can be retried later. If there is a crash between 2 and 3 then the publication may be attempted twice. Either the code detects this (and does nothing the second time), or the logic that reads data from the blockchain ignores duplicate entries. We are assuming either one of these is possible and feasible.

Added Benefits

The process that updates the DBMS and the code that pushes to the blockchain interact via a queue. Most queues have accessibility in multiple programming languages, so the application that updates the DBMS can be written in a different language than the blockchain component.

Contact Us

Atomikos Corporate Headquarters
Hoveniersstraat, 39/1, 2800
Mechelen, Belgium

T +3215613055

Subscribe to our newsletter

Never miss an update

Copyright 2021 Atomikos BVBA | Our Privacy Policy
By using this site you agree to our cookies. More info. That's Fine