Ramrao Adik Institute of Technology
Department of Computer Engineering
TE ADB Presentation
Topic -Transaction
By
Roll No.22CE1095 Kumar Aadarsh
Roll No.22CE1131 Siddharth Adep
Roll No.22CE1107 Stuti Agrawal
Roll No.22CE1146 Anukiran Bathula
Introduction to Database Transactions
1. What is a Transaction?
- A transaction is a set of operations that are treated as a single unit.
- All parts of the transaction must be completed for the change to be applied. If any part fails,
everything is rolled back to the original state.
2. Why Are Transactions Important?
- Transactions protect data integrity and prevent errors.
- They ensure that the database is not left in an incomplete or inconsistent state, especially when
multiple users access it at the same time.
3. ACID Properties:
- Atomicity: All-or-nothing execution.
- Consistency: Keeps the database in a valid state.
- Isolation: Transactions do not interfere with each other.
- Durability: Changes are permanent once the transaction is complete.
2 TE Presentation
Introduction to Database Transactions
Atomicity
1. Definition:
• Atomicity ensures that a transaction is either fully completed or fully aborted.
• In case of failure, the database reverts to its previous state.
2. Key Features of Atomicity:
• All-or-Nothing Principle: All operations within a transaction succeed, or none are applied.
• Rollback on Failure: If any step fails, the entire transaction is undone.
3. Example: Bank Transfer
• Deduct $100 from Account A.
• Add $100 to Account B.
• If the second step fails, the first step is rolled back.
3 TE Presentation
Introduction to Database Transactions
Importance of Atomicity in Transactions
1. Why Atomicity Matters:
• Data Integrity: Ensures that the database remains accurate and reliable
• Error Recovery: In case of a failure (like a power outage), atomicity
guarantees that no partial transactions exist, allowing easy recovery.
2. Use Cases:
• Banking Systems: Essential for ensuring money transfers are completed
without leaving any account in an inconsistent state.
3. Implementation:
• Most modern database management systems (DBMS) implement atomicity
through transaction logs and rollback segments, making it easier to revert to
a stable state after failures.
4 TE Presentation
Consistency
What is Consistency?
• Definition: In the context of ACID, consistency ensures that any transaction brings
the database from one valid state to another, adhering to all predefined rules and
constraints.
• Key Features of Consistency
1. Integrity Constraints:
- Enforces rules such as primary keys, foreign keys, and unique constraints.
- Prevents invalid data states (e.g., orphaned records).
2. State Transition:
- A transaction must transition the database from one valid state to another,
ensuring all business logic is followed.
- Example: Transferring funds between accounts must ensure that total balances
remain consistent.
3. Immediate Validity:
- All transactions must leave the database in a valid state at all times, even in the
event of transaction failure.
5 TE Presentation
Challenges and Importance of
Consistency
Challenges:
Performance Overhead: Maintaining consistency can slow down transactions
due to locking.
Complex Transactions: Nested or complex transactions can complicate
consistency.
Distributed Systems: Achieving consistency across nodes is more challenging.
Importance:
Critical for Reliability: Essential for applications like banking and e-commerce.
Trade-offs with Availability: Strong consistency may reduce availability (CAP
theorem).
Real-World Implications: Inconsistent data can lead to significant financial and
operational risks.
6 TE Presentation
Atomicity vs Consistency
7 TE Presentation
Understanding Consistency
8 TE Presentation
ISOLATION
• Definition
Isolation, in the context of ACID, refers to the property that ensures transactions are executed
independently of one another. This means that the operations of one transaction should not
interfere with those of another, even when they are occurring concurrently.
• Key Features of Isolation
1. Transaction Independence
• Each transaction is executed as if it were the only transaction in the system, ensuring that
the results of one transaction do not affect others.
2. Concurrency Control
• Mechanisms like locking, timestamp ordering, and optimistic concurrency control
manage how transactions interact to prevent conflicts.
3. ACID Compliance
• Isolation is part of the ACID properties (Atomicity, Consistency, Isolation, Durability) that
ensure reliable transaction processing.
9 TE Presentation
LEVELS OF ISOLATION
1. Read Uncommitted
• Description: Allows transactions to read data that has been modified but not yet
committed by other transactions.
2. Read Committed
• Description: Ensures that a transaction can only read data that has been committed.
3. Repeatable Read
• Description: Ensures that if a transaction reads a value, it will see the same value for the
duration of the transaction, even if other transactions commit changes.
4. Serializable
• Description: The highest level of isolation, ensuring that transactions are executed in
such a way that they appear to be serial (i.e., one after the other).
Choosing the appropriate isolation level depends on the specific requirements of the
application, balancing the need for data consistency against the need for performance and
concurrency.
10 TE Presentation
IMPORTANCE
Here are some key reasons why isolation is important:
1. Data Integrity
• Isolation helps maintain the accuracy and consistency of data by preventing concurrent
transactions from interfering with each other. This is crucial for ensuring that the
database reflects a reliable state.
2. Consistency
• By isolating transactions, databases can enforce consistency rules. This means that after
a transaction completes, all subsequent transactions see the data in a consistent state,
adhering to defined business rules.
3. Transaction Reliability
• Isolation contributes to the overall reliability of transactions, ensuring that operations are
completed successfully and in a manner that is transparent to other transactions.
4. User Experience
• For applications that depend on real-time data, isolation ensures that users see accurate
and consistent information, enhancing the user experience.
11 TE Presentation
UNDERSTANDING ISOLATION
12 TE Presentation
Durability
1. Definition:
Durability ensures that once a transaction is committed, its changes are permanent, even in
the case of a system crash or failure
2. Key Features of Atomicity
• Transaction Logs: Records every committed transaction so it can be recovered after
crashes.
• Backup Systems: Periodic backups protect against data loss.
• Replication: Duplicates data across multiple locations to prevent data loss due to
hardware failure.
3. Example: Online Purchase
• A customer completes a payment.
• The transaction is committed.
• Even if the system crashes afterward, the purchase remains confirmed, and the order
data is not lost.
13 TE Presentation
14 TE Presentation
Transaction States
A transaction in a database can move through several states during its execution.
Transaction states:
• Active: the initial state; the transaction stays in this state while it is executing
• Partially committed: after the final statement has been executed
• Failed: after the discovery that normal execution can no longer proceed
• Aborted: after the transaction has been rolled back and the database has been restored to its
state prior to the start of the transaction
• Committed: after successful completion
15 TE Presentation
State Diagram of a Transaction
16 TE Presentation
Thank You