Implementing transactions in Couchbase

“My basic question is whether the ctx.get() is designed to be a stateful or stateless API and if its stateful, then is it idempotent ?”

I read the question as “will it cause a problem” which is not the same as “is it idempotent”. Without knowing what “a problem” is, I can only defer to the documentation.

ctx.get within a transaction is not idempotent. Within a transaction, the changes that have been made, but not yet committed are what is “seen”. A ctx.replace in the transaction would result in a second ctx.get returning the updated document. If there was no modification, then it would return the same value. i suppose if you wanted to make further modifications, you woud need a new GetResult to modify and pass into replace. [ Also - if the document was modified by a non-tranactional replace - I don’t know what the value would be (Couchbase Transactions only provides isolation from other transactions)]

“the documentation didn’t advice against what we are doing”

Doing what? Overwriting the result of a ctx.get with the (modified) result of a prior non-transactional get? Which results in the loss of a deposit as described above the bank account example? The documentation does not advise against that as that might be the desired outcome - if it was a change of address, for instance. Neither does the transaction documentation give anything like that as an example as it is inherently dangerous and not very “transactional” - if the application is just going to overwrite regardless of previous values or other updates, it can just use upsert.