Let's say a buyer logs in to the bookshop application and purchases a book. The following actions should take place in the event of purchase:
Charge the buyer the cost of the book
Reduce the stock of the book
If the charge on the credit card fails, the stock shouldn't be reduced. Also, when the book is out of stock, the buyer shouldn't be charged. That means either both actions should be successfully completed, or they should have no effect. These actions collectively are called a transaction or unit of work. In essence, transactions provide an all-or-nothing proposition.
The concept of transactions is inherited from database management systems. By definition, a transaction must be atomic, consistent, isolated, ...