thelovemsg / ticketing_site

ticketing_site
0 stars 0 forks source link

Query 7) BASE, CQRS, SAGA #9

Open thelovemsg opened 6 days ago

thelovemsg commented 6 days ago

SAGA Pattern

Overview

The SAGA pattern is an architectural pattern used in distributed systems to manage transactions across multiple services. It is particularly useful in environments where maintaining data consistency across different databases or services is crucial, without relying on traditional two-phase commit protocols.

Key Concepts

Long-Running Transactions

A saga is composed of multiple local transactions where each step updates the database and triggers the next. If a transaction fails, sagas ensure the system remains consistent by either compensating for previous operations or executing alternative transactions to correct the error.

Compensation Transactions

Each transaction step has an associated compensating transaction designed to undo the changes if subsequent steps fail. This is essential for maintaining consistency without locking system resources.

Types of Sagas

Benefits

Challenges

When to Use the SAGA Pattern

The SAGA pattern is ideal for business processes that span multiple microservices where each operation step can fail and requires compensation to maintain system integrity. It is best suited for operations that need reliability and consistency but can accept eventual consistency.

Real-World Example

Consider an e-commerce system where processing an order involves multiple steps such as order placement, payment processing, and shipping, each handled by different microservices. A saga can manage this process by ensuring that if payment fails, the order is canceled, and if shipping cannot proceed, both the payment and order are rolled back.

thelovemsg commented 19 hours ago

BASE

Overview

BASE is an acronym that stands for Basically Available, Soft state, Eventual consistency. It is often used to describe the data consistency model of distributed databases that prioritize availability over strict consistency in order to achieve higher scalability and fault tolerance.

Components of BASE

Basically Available

Soft State

Eventual Consistency

Benefits of BASE

Trade-offs

Applicability

BASE properties are suitable for applications where availability and partition tolerance are more critical than strong consistency. Examples include large-scale web applications, real-time big data processing systems, and distributed applications where data needs to be replicated across geographical regions.

Conclusion

While BASE offers significant advantages in terms of scalability and availability, it requires careful consideration of the specific application needs and user expectations regarding data accuracy and consistency. Systems designed around BASE principles are well-suited for environments where eventual consistency is an acceptable compromise for gaining high availability and robustness against network and system failures.