0% found this document useful (0 votes)
26 views3 pages

Distributed ACID Transactions Overview

The document discusses various techniques for ensuring reliability and integrity in distributed transactions, including two-phase commit, three-phase commit, and saga patterns with orchestration and choreography approaches. It also covers topics like optimistic and pessimistic locking as well as BLOB storage.

Uploaded by

keshrishiwam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Distributed ACID Transactions Overview

The document discusses various techniques for ensuring reliability and integrity in distributed transactions, including two-phase commit, three-phase commit, and saga patterns with orchestration and choreography approaches. It also covers topics like optimistic and pessimistic locking as well as BLOB storage.

Uploaded by

keshrishiwam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ACID Transactions:

● Atomicity: Atomicity ensures that a transaction is treated as a single, indivisible unit. It means that all
the operations within a transaction are either fully completed or fully rolled back in case of any failure.
There's no in-between state.

● Consistency: Consistency ensures that a transaction brings the database from one consistent state to
another. It means that a transaction cannot violate the integrity constraints defined on the database. If a
transaction starts with a valid database state, it should end with a valid state.

● Isolation: Isolation guarantees that concurrent transactions do not interfere with each other. Even
when multiple transactions are executed simultaneously, the final result should be as if they were
executed one after the other. This property prevents issues like data corruption or inconsistent results
due to concurrent access.

● Durability: Durability ensures that once a transaction is committed, its effects are permanent, even in
the face of system failures (e.g., power outage or hardware crashes). The changes made by committed
transactions are stored securely and persistently in the database.

Distributed Transactions in Distributed Systems:

In distributed systems, transactions involve multiple components distributed across various nodes or servers.
Ensuring their reliability and integrity is essential.

Two-Phase Commit (2PC): Ensures atomicity and consistency in distributed transactions. It guarantees that
either all participants commit or none do, ensuring consistency.

Process:
1. Prepare Phase:
● Coordinator asks participants if they are ready to commit.
● Participants respond with "Yes" or "No."
● If all respond "Yes," the coordinator proceeds to the commit phase.
● If any participant responds "No," the coordinator aborts the transaction.
2. Commit Phase:
● Coordinator sends a commit message to all participants.
● Participants, upon receiving the commit message, execute the transaction.

Three-Phase Commit (3PC): Addresses some limitations of 2PC, especially in cases of network partitions. It
adds a phase to mitigate situations where participants cannot confirm or abort.

Process:
1. Can Commit Phase:
● Coordinator asks participants if they can commit.
● Participants respond with "Yes," "No," or "Prepared."
2. Pre-Commit Phase:
● If all participants respond "Yes" in the can commit phase, the coordinator proceeds.
● Coordinator sends a pre-commit message to all participants.
● Participants, upon receiving the pre-commit message, get ready to commit.
3. Commit Phase:
● Coordinator sends a commit message to all participants.
● Participants, upon receiving the commit message, execute the transaction.
Saga Pattern : The Saga pattern offers two coordination models: Orchestrator, which uses a central
coordinator, and Choreography, which relies on decentralized communication between services. The choice
depends on the specific needs and architecture of a distributed system.

Orchestrator:
- Role: Centralized coordinator that manages the sequence of steps in a distributed transaction.
- Functionality:
1. Initiates the saga by sending a request to the first service.
2. Monitors the progress of each step in the saga.
3. Makes compensating calls to undo completed steps if a failure occurs.
4. Ultimately, signals the outcome of the saga (commit or rollback) to maintain data consistency.

Choreography:
- Role: A decentralized approach where individual services communicate and coordinate with each other.
- Functionality:
1. Each service knows its part in the saga and communicates directly with others.
2. Services send events to each other to trigger their respective actions.
3. No centralized coordinator; the coordination logic is distributed across services.
4. Services must be designed to listen for events and handle them accordingly.
5. Typically relies on message queues or event-driven architecture for communication.

Advantages of Orchestrator:
- Centralized control and monitoring.
- Easier to implement complex compensation logic.
- Explicit and clear definition of the saga flow.

Advantages of Choreography:
- Decentralized, less single-point-of-failure.
- More flexibility and autonomy for individual services.
- Scalable and suitable for loosely coupled systems.

Considerations:
- Orchestrator can become a bottleneck or single point of failure.
- Choreography may be harder to visualize and track, making it complex to implement.
- Choice between the two depends on system requirements and complexity.

Optimistic & Pessimistic Locks:

Pessimistic Locks: Ensures exclusive access to data and prevents concurrent modifications. When a
transaction wants to access data, it acquires a lock, preventing other transactions from accessing that data
until it releases the lock. It ensures data integrity but can reduce concurrency.

Optimistic Locks: Maximizes concurrency and assumes data conflicts are rare. When a transaction reads
data, it records a version or timestamp. When the transaction updates the data, it checks if the version or
timestamp has changed since the read. If unchanged, the update proceeds; otherwise, the transaction may
retry or abort. It enhances concurrency but may require conflict resolution.
BLOB Storage (Binary Large Object Storage)

It is designed to store binary data, often of variable and large size, such as images, videos, audio files,
documents, and more.

Why it's Needed:


● Efficient Storage: BLOB Storage is optimised for handling large binary data efficiently, allowing systems
to store and retrieve data without performance bottlenecks.
● Data Preservation: It ensures the preservation and integrity of binary data, which is crucial for
applications that rely on accurate and complete storage of files.
● Scalability: BLOB Storage solutions are scalable, accommodating the growing volume of binary data
generated by modern applications.
● Accessibility: BLOB Storage provides secure and reliable access to binary data, making it accessible to
applications and users.

Examples:
1. Azure Blob Storage: Microsoft Azure offers BLOB Storage as part of its cloud services, enabling users to
store and manage unstructured data.
2. Amazon S3 (Simple Storage Service): Amazon Web Services provides a highly scalable and durable
object storage service suitable for a wide range of binary data.
3. Google Cloud Storage: Google's cloud platform offers BLOB Storage with features like versioning and data
lifecycle management.
4. Database BLOB Columns: Many relational databases, such as MySQL and PostgreSQL, include BLOB
columns to store binary data within database tables.
5. Content Delivery Networks (CDNs): CDNs like Cloudflare and Akamai leverage BLOB Storage to
distribute and serve media content efficiently.

Common questions

Powered by AI

BLOB Storage is suitable for handling large binary data, such as multimedia files, due to its ability to efficiently store and retrieve data without performance bottlenecks. This storage method is optimized for variable and large binary data, ensuring data integrity and preservation, which is crucial for applications that require accurate storage of files. Additionally, BLOB Storage solutions are scalable to accommodate growing data volumes and provide secure, reliable access, often using cloud services like Azure Blob Storage, Amazon S3, and Google Cloud Storage .

The primary difference between the Orchestrator and Choreography models in the Saga pattern is the method of coordination. The Orchestrator model employs a centralized coordinator to manage and monitor the sequence of steps in a distributed transaction, making it easier to implement complex compensation logic and providing clear visibility of the saga flow. However, it poses a risk of becoming a single point of failure . In contrast, the Choreography model is decentralized, with each service autonomously communicating and coordinating directly with others. This model offers greater flexibility and autonomy, suitable for scalable systems, but can be complex to visualize and track due to the distributed coordination logic .

The Saga pattern is more suitable for modern microservices architectures because it provides flexibility and scalability in managing distributed transactions across multiple services. Unlike traditional ACID transactions, which enforce strict atomicity, consistency, isolation, and durability across all services, the Saga pattern allows for the coordination of long-running transactions through asynchronous processes. This pattern better suits the loosely coupled nature of microservices by supporting both the Orchestrator and Choreography models, which can either centralize or decentralize transaction control, enhancing fault tolerance and reducing dependency bottlenecks .

The Three-Phase Commit (3PC) protocol introduces an additional Pre-Commit Phase to address the limitations of 2PC during network partitions. In 2PC, a coordinator and participants may become uncertain about the next steps if a network partition occurs after the Prepare Phase. 3PC mitigates this by adding the Pre-Commit Phase: after the Can Commit Phase confirms readiness, a pre-commit message is sent, alerting participants to prepare without yet committing. This approach provides more flexibility, potentially allowing participants to resolve issues or clarify the protocol's state if a partition occurs, thereby reducing the risk of deadlock and uncertainty .

Isolation in ACID transactions ensures that concurrent transactions do not interfere with each other, maintaining database integrity. It guarantees that the results of concurrent execution are the same as they would be under serial execution, where one transaction completes before the next begins. This prevents data corruption and inconsistent results, ensuring that each transaction operates independently despite being executed simultaneously .

Pessimistic locks ensure data integrity by preventing concurrent modifications to a resource by multiple transactions, locking the data for exclusive access until the transaction completes. This prevents any other operations from accessing or changing the locked data, thus avoiding conflicts and ensuring consistency. However, the drawback of using pessimistic locks is reduced concurrency, as transactions must wait for locks to be released before proceeding, which can lead to decreased performance in high-throughput environments .

The Two-Phase Commit (2PC) protocol ensures atomicity and consistency in distributed transactions by dividing the commit process into two distinct phases. In the Prepare Phase, the coordinator asks all participants if they are ready to commit, and participants respond with 'Yes' or 'No.' If all participants agree to commit, the protocol moves to the Commit Phase, where the coordinator sends a commit message to all participants, who then proceed to execute the transaction. This structured approach ensures that either all participants commit, maintaining consistency, or none do, maintaining atomicity .

The key advantages of using the Orchestrator model in distributed transaction management include centralized control and monitoring, making it easier to implement complex compensation logic and providing an explicit definition of the transaction flow. However, its disadvantages include the potential for becoming a bottleneck or single-point-of-failure due to its centralized nature. The choice of model depends on the specific requirements and complexity of the distributed system .

Durability in ACID transactions is ensured through mechanisms that guarantee changes made by committed transactions are stored persistently in the database system, preserving them even in the event of a system failure. This is typically achieved by writing transaction logs and changes to stable storage before acknowledging commitment to the client. These logs can be used to recover the database to its last consistent state following failures such as power outages or hardware crashes, which is crucial for maintaining the integrity of the database over time .

Optimistic locks improve concurrency by allowing multiple transactions to access and potentially modify the same data without immediate locking. Instead of locking data during read operations, a version or timestamp is recorded. Upon attempting an update, the system checks whether the data's version or timestamp has changed, indicating other transactions have altered it. If it hasn't changed, the update proceeds; otherwise, the transaction may retry or abort. This approach assumes conflicts are rare, enabling higher concurrency levels while delaying conflict resolution until necessary .

You might also like