Introduction to Atomic Transactions – How A Simple Database Operation Can Highly Impact Your Business

In the Big Data era, efficient database management is a given, regardless of your business type. 

But how do you choose the right database management tool or determine the best database processes and operations when building an app or platform?

These are the questions for which you need to set clear answers from the start; otherwise, the technical glitches on your app or platform could seriously damage your entire business. 

Here’s what atomic transactions are all about, why they’re important, and their crucial role both from the tech and the business perspective.

What Are Atomic Transactions

Within databases and data storage management systems, atomic transactions are part of a database operation in which all or nothing happens. 

An easily relatable example is when you transfer money from your bank account to another; either the entire sum has left your bank account, or it hasn’t — there can never be an in-between situation when you could have transferred half or only part of the money.

Atomicity is one of the four essential characteristics of the ACID (atomicity, consistency, isolation, durability) principles of transactions. The basis of each of these principles is:

  • Atomicity – all operations and commands of a transaction are treated as a single element, and either they all succeed or fail;  the transaction is rolled back in case of any error.
  • Consistency – any change in the transaction should follow database rules, limitations, and triggers; if changes don’t comply with database rules, the transaction fails.
  • Isolation – transactions operate in an isolated environment and a distinct order, ensuring they don’t impact other reads and writes of separate transactions from the same database.
  • Durability – once a transaction reaches a “completion” state, all the saved data is persistent and stays in the system even in case of crashes or power outages.

How Atomic Transactions Work

Transactions are usually formulated and coded to include multiple ‘if’ statements. When you cover atomic transactions within software systems, developers don’t need to think about all possible ‘if’ statements or adjust all lines of code based on different use cases. 

This way, atomicity guarantees the highest level of database integrity and prevents risks of losing partial data. You avoid incomplete database changes or updates, which can lead to bigger issues than rejecting the entire series altogether.

For example, in the absence of an atomic system, if a system fails or crashes while someone fills in information in a database, some data would be lost while some would be saved. The outcome is your team will have to spend a lot of time recovering the lost information, which can be like looking for a needle in a haystack. 

With atomicity implemented, the database remains intact since the information didn’t succeed in arriving from point A to point B. 

Having atomicity embedded from the very beginning is ideal.

Take this explanation from Marius Zoican, Finance Professor at the University of Toronto:

Atomic transactions are exceptionally well-suited to streamline complex processes and lead to a shorter intermediation chain. This is particularly valuable in finance, where intermediation is costly and takes significant amounts of time. For example, atomic cross-border payments can happen instantaneously as a transfer between two parties, without the need for multiple correspondent banks. In securities trading, atomic transactions such as “flash loans” allow traders to bundle trade financing and execution – brokers only lend capital to successful trades.

 This greatly reduces the risk associated with margin trading and boosts returns to traders.  Further, a shorter intermediation chain reduces the risk of introducing (manual) errors if multiple parties interact with the same transaction.”

What Type of Apps Require Atomic Transactions

The simple answer is that any app should implement the ACID approach. Where it’s mandatory, though, are apps and platforms that manage and store sensitive user data, like:

  • Systems that handle money: banking applications, payment processing systems, and trading platforms. 
  • Supply chain and booking systems where it’s required to keep track of ownership of goods and services. 
  • Billing systems that keep information in database records and summary records. 
  • Healthcare systems that store  confidential information, including medical records, treatment, and diagnostics.

Here’s a clear example of how atomic transactions work in a payment processing app and how they keep data safe from Ștefan Opariuc, Founding Engineer at Apollo:

ACIDity of transactions is a concept that engineers stumble upon quite early in their careers. 

Besides its technical complexity and applicability, there’s also the business impact. Depending on whether it’s needed or not, it can make your product operate erroneously.

Most services interact with databases and many even manipulate the same dataset.

For example, card payments have a representation in a database, and various services ensure that details are correct, checks have been performed (e.g., balance, 3ds, etc.), and status is updated after each step. 

Since such a payment is time sensitive, it needs minimal execution time, so asynchronicity is frequently implied. Putting all of this together with hundreds of operations per second, and you get the best recipe for potential disasters.

Hence, ACID transactions show a powerful and important role as they ensure the integrity of the payment state at each step.

Examples of How Databases Work in the Absence of Atomic Transactions

Example 1) Transactions within a finance app

Let’s say Jeff wants to transfer to his friend Danny $50.  Before the transfer is made, Jeff has a total of $450 in his account, while Danny has $250.  Once the transfer takes place, the total amount in Danny’s account should become $300. 

The next step is for two procedures are now scheduled to take place:

  • the $50 that Jeff wants to send will be deducted from his account  
  • the amount would be credited to Danny’s account

What happens now is that the financial app crashes due to a power failure.  

If atomic transactions are already implemented, Jeff won’t succeed in making the transfer, so Danny wouldn’t receive $50 from Jeff. Yes, the app would be unavailable for a while, but overall, it wouldn’t create a bad or unsafe user experience. Once the app is up and running again, Jeff will re-initiate the transfer, and Danny will receive the transferred amount in his account. 

However, taking the same scenario of a power failure without having atomic transactions embedded in the app, the outcome would be that the initial debit operation succeeds, but the crediting process fails. So, $50 is withdrawn from Jeff’s account, but they fail to reach Danny’s account. 

Example 2) Atomicity in an online booking system  

Let’s take the case of a user who wants to make a hotel reservation through an online booking platform. The successful booking requires completing a transaction, first for the payment of the accommodation service and second for the actual booking of a room. 

The two separate and different parts of the transaction should occur concurrently based on the business logic. Without atomicity, issues like withdrawing the amount of money provided for the reservation without succeeding in booking the room. 

The key takeaways from these examples are that atomic transactions ensure that all data from a database stays safe and in an integral state, including in the event of power failures, errors, or crashes. The key to effectively managing databases is implementing the most suitable technology for your app’s or platform’s needs.

For large and complex apps where several database interactions take place to complete an action, the concept of atomic transactions should be considered from the very beginning. 

Atomicity – The Standard of the Web3 Space

The mechanics behind smart contracts and the way they handle transactions relies on the ACID model. A transaction changes the system from one consistent state to another and includes the previous block’s hash and a timestamp. Any retroactive change made within a transaction will change the containing block, its hash, and all the blocks in the chain, turning that specific transaction invalid.

As Karla Pantelimon, Backend Architect at Softbinator Technologies, mentions, this logic provides a safety net that supports data accuracy:

There is no coincidence that the calls made to the smart contracts, that define a programmatic equivalent of a contract between two parties, are built on the idea of transaction atomicity. Their logic is to use revert of the state and balance changes when handling errors to assure that the data on the chain is not affected by any bad logic or untreated cases, this being the safest action. So, it’s natural that the same logic needs to be applied to Web2 applications with sensitive data.

However, in the Web3 world, atomicity hasn’t yet become the norm, leaving the door open for security risks that can be difficult to measure and manage. 

Here’s this interesting view from Donovan Dall,  Technical Lead at t3rn:

The notion of atomicity comes out of the box with most Virtual Machines nowadays. However, as multi-chain and interoperability become the norm, it is ever more apparent each day that builders should support atomicity. Most protocols on top of the virtual machines are some form of reasoning around an asynchronous message or how to add additional security on top of these messages. At this stage, you should consider applying some form of reversibility to guarantee users that the message will indeed be delivered or handled depending on a certain level of risk tolerance.

From the business perspective, it is essentially a unification of the same goal as the technical side of things, onboarding users and providing safety guarantees that the protocol works as expected or that whispers of a partially correct message may not ruin some intrinsic state.

From my perspective, atomicity should be the norm, and as we see the characteristics evolve in this space, we should see this particular paradigm become second nature.

Benefits of Atomic Transactions

As part of the ACID approach (atomic, consistent, isolated, durable), atomicity brings these benefits:

Data reliability

By implementing atomicity, a system database becomes more reliable, easier to use and to access. With the increased reliability of the database, anyone using the entire platform or app knows they can trust the information the database delivers is correct. 

Protection of transactions

A database system that’s ACID compliant is a guarantee for regular checkups on information and changes and that transactions are accurate before they enter the database. This is an advantage for financial businesses, but also for any company that manages sensitive information.

Multiple access

 With an ACID system in place, long database locks can be more easily avoided, increasing the platform of app’s scalability. Atomicity allows simultaneous checks and changes, enabling bulk of updates to be performed in sequence and around the same time. This will make sure that all the information for an update is applied at once, so the lock time may be required only for the set time period.

Conclusion

Atomic transactions play an essential role on the technical side, reducing the number of business operations and making them run effectively, and overall providing a good customer experience.

But it also positively impacts the business by reducing financial risks and avoiding the pitfalls of reputational damage.

They’re particularly useful for financial or blockchain apps, but other systems too. 

Here’s an opinion from Elena Otilia Manta, Associate Professor Ph.D. at the Romanian-American University:

The mix of finance and technology represents the combination of the future of regional and global financial markets.

In the context of the digitalization of finance as a whole, I appreciate that these ACID guiding principles contribute directly to the reliability of transactions in the databases of financial institutions, as well as to the limitation of possible blocks or interruptions of a transaction without atomicity. By using this principle of atomicity, the financial institution ensures that either the entire transaction is completed successfully or that no transaction has been completed, which generates predictability and control.

The ACID (atomic, consistent, isolated and durable) guiding principles provide the same advantages in several systems, respectively: big data and data mining, cybersecurity in the financial industry, and artificial intelligence and information analysis.