Transactions

Owner(s):

__Transaction__ - A set of actions that shows and acts as one complete action. It should be atomic, in other words, not interruptible in the middle.

Transactions first and foremost must must abide by **ACID**.
 * **A**tomicity - Once a process starts, it locks the resources and no other processes can interrupt it half way.
 * **C**onsistency - All instances of resources must be the same across the board.
 * **I**solation - Although several threads can be going at once, each transaction must occur in order one at at time.
 * **D**urability - Once a transaction is completed, it is locked in. No future transaction or database failures should corrupt any transactions that have been processed and completed before it.

There are two possibilities for transactions: either it completes, or it fails. If it completes, it must be final and not changeable from the actions of another transaction (etched in stone if you will). If it fails, it must roll the system back to its state before the transaction began. This can be helped with such programs as CICS.

//Online Transaction Processing// Highlights of uses include:
 * OLTP** (Online Transaction Processing) - Online transactions are the opposite of batch transactions. Online transactions are done right there and then when requested. Batch transactions are usually run during a time of low activity and all objects are run in bulk. Changes made to the objects are not officially changed in the system until the batch process runs.
 * Manages the user interface
 * Retrieves and modifies data
 * Tracks data locations
 * Handles communications
 * Interfaces with security


 * CICS** (Cutomer Information Control System) is a type of OLTP. It behaves as a buffer between the OS and the user. It helps the system roll back incompleted transactions by keeping track of the actions that occur through it. Thus, it automatically does this job for the user. Everything in the transaction must be entered through CICS. If it is not, CICS will not have the information it needs to roll the transaction back.
 * CICS is considered a shell where OS calls are made to it, and it makes them to the OS.
 * CICS transactions are called tasks.
 * CICS allows for transactions to run concurrently, but they still abide by the isolation principle of ACID.

CICS is already written out and can be included with mainframes. For a distributed system to follow these rules of transactions, a program would have to be written from scratch specifically for such functionality. Thus, mainframes are geared toward transaction processing.



//Characteristics//
 * Short Scope** - A small amount of code so resources are not locked up for long periods of time.
 * Small Scope** - Only lock resources the process needs so other threads can run transactions on other resources.

//Examples// 1) If someone is buying plane tickets, the transaction must be done carefully. If, for instance, this person gets cut off in the middle of the transaction, any seat marked as taken or any fees paid must be rolled back to their former state. Although everyone can shop for seats concurrently, no one should be able to buy the same seats while that one is the middle of the buying seats. And, once the purchase and confirmation is made, no other transactions after that should put the person out of their seats.

2) Even think of something as simple as a trade. It it were considered a transaction, you would never have to worry about giving an item, have the transaction break down, and have the other keep both items. A roll back of the transaction would have you get your item back unless the trade can be fully completed.