Vendia Transactions
Vendia Share uses transactions as its data processing unit. Each transaction contains one or more updates to a data value in a Vendia Share Uni. Vendia Transactions enable users to group multiple changes on multiple data values in a single transaction and guarantees that all updates are processed serially, in order, as an atomic unit. This feature is analogous to relational database transactions. Vendia Transactions can also be used when querying data to ensure that all nodes see a consistent value even if an in-flight transaction is actively being processed across nodes.
When Vendia Transactions are used when updating data in a Uni, you can easily manage complex workflows that require coordinated updates on multiple data items. Vendia Transactions also provide a transactional query mechanism to prevent returning inconsistent data among nodes.
If Vendia Transactions are not used when updating data in a Uni, there is no guarantee of transaction order. There is no way to group transactions together as an atomic unit where all data updates complete successfully or none do. The same query may return different results among nodes as data is updated.
Vendia Share supports transactions through a custom GraphQL directive to decorate the mutations and queries: @vendia_transaction
Mutations without Vendia Transactions
A single mutation can include multiple operations. For example, if we wanted to define multiple update_Inventory
operations in a single mutation m
, we could use the following syntax:
The Vendia ledger shows that these two mutations happened across two separate transactions.
Sample listVendia_BlockItems query and result
Query:
Result:
There is no guarantee of order for these two operations. The update_Inventory
operation in warehouse2
may complete before the operation in warehouse1
. Each operation will occur independently; meaning some may succeed while others fail.
For some business cases this may be acceptable. For others - managing financial transactions or warehouse inventory - it may not. Vendia Transactions should be used in those cases where multiple operations must be processed in order and as a unit where all operations succeed or fail together.
Mutations with Vendia Transactions
In next mutation, we will run the same mutation but include the @vendia_transaction
GraphQL decorator.
The Vendia ledger shows that these two operations happened in a single transaction.
Sample listVendia_BlockItems query and result when using a Vendia Transaction
Query:
Result demonstrating our two update mutations
were part of the same transaction:
If we attempt to run an invalid operation (e.g. violating the constraint of a field) in a Vendia Transaction then all operations will fail. For example, if there was a constraint on quantityWarehouse2
that stated the value could not be negative, the following mutation m
would fail.
Sample Vendia Transaction error
Neither of the operations in the mutation m
are applied.
Queries with Vendia Transactions
A query using the @vendia-transaction
GraphQL directive ensures that all nodes will see the same, consistent value until all nodes have the update applied. Due to the asynchronous nature of Vendia Share, it may take a brief amount of time for updated values to be reflected on all nodes in a Uni.