4 ms·
Are there are any relational databases, or add-ons or frontends for relational databases, that allow for transaction sharing? What I mean by "transaction shari
by tzs 3y ago
Are there are any relational databases, or add-ons or frontends for relational databases, that allow for transaction sharing?
What I mean by "transaction sharing" is for separate connections to be simultaneously using the same transaction.
Consider something whose logic is like this:
begin_transaction()
select_something()
update_something()
compute_something()
update_some_more()
commit_transaction()
where compute_something() includes calling a service running in another process or on another server to return some data, and that service uses the same database, and we want it to see the data that update_something() updated.
With transaction sharing it might instead work something like this:
tid = begin_shared_transaction()
select_something()
update_something()
compute_something(tid)
update_some_more()
commit_transaction()
and in the service that compute_something(tid) calls it could take tid as a parameter and it would do something like
open_shared_transaction(tid)
...
close_transaction()
- rockostrich 3y agoI mean, it's possible to build something like that but why would you ever want to do that? It's so much simpler to just use a transaction per request and let the database's transaction logic handle which requests succeed and which ones fail. Clients should have retry logic to handle the failure scenarios. It's a lot simpler to reason about than trying to turn a distributed system into a single threaded one.
- josephg 3y agoI presume the idea is to make microservices able to work with database transactions. Microservices: Proof that not all ideas can be winners.
- rockostrich 3y agoNot really sure what the point is here. Microservices work great with database transactions.
- dontlaugh 3y agoNo, they don’t. You can have a function in a library, to which you pass a transaction. You can’t pass an open transaction to another service, in the general case. The service boundary forces multiple separate transactions.
- josephg 3y agoI'm not sure if many databases offer this, but you can do it in foundationdb like this: version = txn.get_read_version().wait() compute_something(version) Then on the remote computer, you can create a new transaction and call: def compute_something(version): txn2 = db.create_transaction() txn2.set_read_version(version) # ... Then use the transaction as normal. This will ensure both transactions are looking at the same snapshot of the data in the database. Docs: https://apple.github.io/foundationdb/api-python.html#versions https://apple.github.io/foundationdb/api-python.html#version...
- flir 3y agoHmm. I'd solve this by marshalling all the data in the parent process, and passing that, rather than the tid, to the compute process. Maybe you could do it with a database proxy. The whole approach feels unclean, though.
- klysm 3y agoThis is in general not a very tractable problem considering it as a distributed systems problem. Once you add in an asynchronous network layer inside that transaction you lose a ton of guarantees. This is why I’m baffled when people choose to split up their data across multiple databases.