0% completed
Diving deeper into the transactional labyrinth of distributed systems, we first need to look back and understand the roots of the problem. This journey takes us back to the traditional transaction models that were the norm in the era of monolithic applications.
In the world of monolithic systems, transactions were simple. Recall the e-commerce checkout example we discussed earlier. In a monolithic application, this transaction would usually be handled using ACID transactions. ACID, standing for Atomicity, Consistency, Isolation, and Durability, is a set of properties that guarantee that database transactions are processed reliably.
Atomicity ensures that a transaction is treated as a single unit, which either succeeds completely, or fails completely. If any part of the transaction fails, the entire transaction fails, and the database is left unchanged.
Consistency, on the other hand, ensures that a transaction brings the database from one valid state to another. It guarantees that the database changes state upon a successfully committed transaction.
Isolation ensures that concurrent execution of transactions leaves the database in the same state that would have been obtained if the transactions were executed sequentially.
Lastly, Durability guarantees that once a transaction has been committed, it will remain committed even in the case of a system failure.
In simpler terms, ACID properties ensure that once a transaction is complete, you can be confident that it has either fully occurred, or that it hasn't occurred at all.
This all sounds well and good, doesn't it? So, you might be wondering, what's the problem?
While ACID transactions work perfectly within the confines of a single monolithic system, they start to show their limitations as we step into the realm of distributed systems. The world of microservices is vastly different from that of monolithic applications. Here, each microservice is independent and can be distributed across different servers, even different geographical locations.
Imagine trying to implement a typical ACID transaction in such an environment. Let's return to our e-commerce example. The inventory service, the order service, and the payment service could all be residing on different servers. Ensuring atomicity across these services would mean that if any of these steps fail, we have to undo all previous steps. But, coordinating this rollback across multiple services is a challenging task.
And here comes another roadblock - network latency. Given that the services could be distributed across different geographical locations, the time taken for a transaction to complete can be significantly long. Holding resources locked for such a long duration is not practical and can lead to performance issues.
This brings us to a significant limitation of the traditional transaction model - it is not designed to handle the complexity and demands of distributed systems. The principles of ACID, although well-intentioned, do not translate well in a world where services need to operate independently and communicate over networks.
So, we find ourselves at a crossroads. On one side, we have the ever-growing world of distributed systems, with its promise of scalability, resilience, and flexibility. On the other side, we have the need for reliable and consistent transactions - a non-negotiable requirement for any application.
There is a clear gap that needs to be bridged here. The traditional transaction model is not capable of handling this new world order. This is where the need for a distributed transactions solution arises, one that can handle the unique challenges of distributed systems while ensuring data consistency.
And this is where our hero, the Saga Pattern, comes to the rescue. But, before we jump to the solution, it's crucial to fully understand the depth of the problem. Let's dig deeper.
.....
.....
.....