Saga (design pattern)

from Wikipedia, the free encyclopedia

Saga ( English saga pattern ) is a design pattern in the field of software development to manage data in distributed systems , often used in the implementation of Micro services . Saga can replace the transaction in a distributed system .

use

In a service-oriented architecture , the services are responsible for the persistence of their data. This leads to several independent data stores in the distributed system. Nevertheless, certain use cases require a sequence of operations based on several services with persistence that may only be carried out in full or not at all. This was traditionally solved in the database management system via transaction.

In the Saga approach, there is a compensation operation for every operation. The operations are viewed as a workflow that is carried out in parallel or sequentially, depending on the application logic . If an operation is terminated incorrectly during execution, all operations that have already been carried out successfully are reversed by the associated compensation operations in order to bring the system back to its consistent initial state.

example

Saga example travel booking as UML - activity diagram

In the travel booking example , hotel, car and flight bookings can be made using various independent services. So it is not a transaction, but a business transaction. There are the operations book hotel , book rental car , book flight and the compensation operations cancel flight , cancel rental car , cancel hotel.

If the flight booking cannot be carried out successfully, the hotel and car must be canceled. The sequence diagram assumes that the unsuccessful flight booking must also be canceled, but this depends on the service used. Depending on where in the workflow an error occurs, different compensation operations may be necessary

Web links