←Back to Documentation

Multi-Model Transactions

One transaction can write SQL rows, keys, documents, graph elements, vectors and time-series points together.

Using a transaction

Begin a transaction, pass its ID with each operation (any of the six data models), then commit or roll back. Nothing is visible to other clients until the commit.

TX=$(curl -s "${H[@]}" -X POST localhost:8080/api/v1/transaction/begin -d '{}' | jq -r .transactionId)

curl -s "${H[@]}" -X POST localhost:8080/api/v1/query/sql \
  -d '{"database":"demo","sql":"UPDATE acct SET balance = balance - 100 WHERE id = 1","transactionId":"'$TX'"}'
curl -s "${H[@]}" -X POST localhost:8080/api/v1/query/sql \
  -d '{"database":"demo","sql":"UPDATE acct SET balance = balance + 100 WHERE id = 2","transactionId":"'$TX'"}'
curl -s "${H[@]}" -X PUT localhost:8080/api/v1/kv/last-transfer \
  -d '{"database":"demo","value":"1->2","transactionId":"'$TX'"}'

curl -s "${H[@]}" -X POST localhost:8080/api/v1/transaction/$TX/commit     # or .../rollback

The SDKs wrap this: with db.transaction(): ... in Python and await db.transaction(async (tx) => ...) in Node.js. A statement sent without a transaction ID runs in its own single-statement transaction.

What is guaranteed

  • Atomicity. Writes are buffered and applied as one batch at commit, across all six data models. A rollback, or a client that never commits, leaves nothing behind.
  • Constraints. Primary keys, CHECK constraints and foreign keys are enforced; a violating statement fails with HTTP 409.
  • Isolation. Concurrency control is optimistic. At commit, the transaction is rejected (HTTP 409, TRANSACTION_CONFLICT) if anything it read or wrote, including the ranges it scanned, was changed by another commit after it began. This prevents lost updates, write skew and phantoms. Run a rejected transaction again.
  • Durability. The write-ahead log is fsynced before a commit is acknowledged (ENTROPYDB_SYNC_WRITES=true, the default). With replication, a commit is also written to a majority of nodes first.

Limits

  • Under heavy contention on the same rows, commits are retried and some may fail with 409.
  • On a single node, commits are serialized through one lock, so each waits for the previous fsync.
  • There is no sharding. In a cluster every node holds all data; see Replication and transactions.