Rubén Pérez
Software Engineer at Schibsted Spain
@bakwrau
Set of properties of database transactions intended to guarantee validity even in the event of errors
A
C
I
D
tomicity
onsistency
solation
urability
TODO images
High Coupling
Too large for a single developer to understand
Slow day to day development
Spaghetti code / big ball of mud
Delayed deployments
Reliability
Long term commitment to a technology stack
...
Smaller code base
Less code complexity, faster to develop and easier to understand
Minimize cost of change
Different responsibilities are placed in different services
Deployed independently
Better scaling
...
It is a distributed algorithm that coordinates all the processes that participate in a distributed atomic transaction on whether to commit or abort (rollback) the transaction
Coordinator
Query to commit
Query to commit
Query to commit
Query to commit
Coordinator
Query to commit
Query to commit
Query to commit
Query to commit
Yes
Yes
Yes
Yes
Commit
Commit
Commit
Commit
Ack
Ack
Ack
Ack
Coordinator
Query to commit
Query to commit
Query to commit
Query to commit
Yes
Yes
No
Yes
Rollback
Rollback
Rollback
Rollback
Ack
Ack
Ack
Ack
Provides atomicity because every commit is applied at the same time, or no commit is executed at all
Distributed transactions are very appealing from a developer’s point of view
It’s a blocking protocol
2PC coordinator is a Single Point of Failure
O(n^2) messages worst case
Reduced throughput due to locks, and depending on the slowest machine
2PC impacts availability (Availability is the product of the availability of all the participants in the transactions )
1987
Sagas are long lived transactions that can be broken up in a sequence of relatively independent sub-transactions than can be interleaved
All transactions in the sequence complete successfully or compensating transactions ran to amend a partial execution
To amend partial executions, each saga transaction
\( T_i \)
should be provided with a compensating transaction
\(C_i\)
The compensating transaction semantically undoes any of the actions performed by \( T_i \)
Guarantee:
A saga does not have ACID guarantees
The trade-off -> availability
Two tipical ways of implementing this:
SEC
Compensating requests:
Requests:
Book
Cancel
Book
START SAGA
START CAR
END CAR
START HOTEL
END HOTEL
START FLIGHT
END FLIGHT
START PAYMENT
END PAYMENT
END SAGA
SEC
START SAGA
START CAR
END CAR
START HOTEL
END HOTEL
START FLIGHT
ABORT FLIGHT
COMP HOTEL
COMP CAR
END SAGA
SEC
START SAGA
START CAR
END CAR
START HOTEL
END HOTEL
START FLIGHT
END FLIGHT
START PAYMENT
END PAYMENT
END SAGA
SEC
START SAGA
START CAR
END CAR
START HOTEL
START FLIGHT
ABORT FLIGHT
END HOTEL
COMP HOTEL
COMP CAR
END SAGA
SEC
It is not a Single Point of Failure
The state is in the log, not in the SEC
Just spin up new machines.
To resume previous work:
SEC
Gw
SEC
Gw
Gw
SEC
Gw
Gw
Trips
Avoid transactions across service boundaries if you can