How to run two-phase commit transaction
ScalarDB GraphQL supports two-phase commit style transactions
called Two-phase Commit Transactions.
With Two-phase Commit Transactions, you can execute a transaction that spans multiple
processes/applications (e.g., Microservices).
We name the application that starts a transaction "coordinator" while the applications that
join the transaction are named "participants".
Every two-phase commit operation requires annotating the mutation or query operation with
a @twoPhaseCommit
directive. Below is a description of such operations.
Start a transaction
To start a transaction, add the @twoPhaseCommit
directive without setting parameters.
query some_query @twoPhaseCommit {
# some query
}
The transaction ID of the started transaction will be returned in the extensions object that is part of the result.
{
"data": {
...
},
"extensions": {
"transaction": {
"id": "the_transaction_id"
}
}
}
Join a transaction (for participants)
In a participant application, to join the transaction started by a coordinator application, set the
transaction ID with the id
parameter and set the join
parameter to true.
query some_query_from_participant @twoPhaseCommit(id:"the_transaction_id", join:true) {
# some query
}