Skip to main content

Command Palette

Search for a command to run...

Database: Transaction?

Updated
2 min read
S

I love learning about technology and sharing that with others

Motivation

learning what is transaction

Transaction is a unit of work, that we want to be treated as a whole. We want either it completes or it should fail.

Lets say we have bought some momo's from a shop and we are now paying it with the upi. So this transfer of money should either happen or it should fail, it should not go in a waiting state.

Example

accountA -= 100; accountB += 100; or

accountB += 100; accountA -= 100;

If something goes wrong between the first and the second operation in the pair you have a problem - either 100 bucks have disappeared, or they have appeared out of nowhere.

Solution

beginTransaction;
accountB += 100;
accountA -= 100;
commitTransaction;

A transaction is mechanism which will make sure either all the operation is completed or it should go back to original state.

Simple Transaction Example in Database

  • Commit
  • Rollback

: Commit --> to make the operation permanent : Rollback --> to rollback the system to the previous state.

What are ACID Properties?

  • Atomicity : single operations , it should occur completely or should not occur
  • Consistency : System should be consistent before and after transaction
  • Isolation : Transaction should occur in isolation and should be isolated
  • Durability : Changes should persist after the transaction.

Types of Transactions

Based on Application areas

  1. Non-distributed vs. distributed
  2. Compensating transactions
  3. Transactions Timing
  4. On-line vs. batch

Based on Actions

  1. Two-step
  2. Restricted
  3. Action model

Based on Structure

  1. Flat or simple transactions: It consists of a sequence of primitive operations executed between a begin and end operations.
  2. Nested transactions: A transaction that contains other transactions. Workflow
11 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)