1

By the definition CRDTs (Conflict-free replicated data types) are conflict-free. So it means that any update made on one node will finally be applied (merged) on all other nodes.

So it leads me to the assumption that CRDT can't logically restrict or decline or refuse to make some update if the environment is in it's regular state (no hardware faults, etc.).

On the other hand the transaction by definition should be either accepted or declined, rolled back if some requirement not met - if some conflict detected. So it means that transactions (based on conflicts) can't be implemented with CRDTs (that are conflict-free). Is that right?

Let's consider an example - simple banking account. Balance is a non-negative number. I tried to implement it with PN-Counter (Positive-Negative Counter). I wanted to make it Non-negative - restrict spending if balance goes below zero. But seems it is impossible. Been implemented with PN-Counter it will allow to go below zero. Or if I want to restrict that - I need to synchronize (lock) all nodes to get a confirmation.

If it is possible to implement a simple transaction with CRDTs could you please describe how it is possible with the given example - non-negative number.

Aleksei Gutikov
  • 343
  • 4
  • 10

1 Answers1

1

You seem to describe a two separate issues here:

  1. Initial question: is it possible to implement transactions in CRDTs? Yes. In fact there are two transaction protocols that explicitly state that they can target CRDTs: RAMP and CURE. The latter one offers abort mechanics.
  2. Your example case: is it possible to implement a non-negative counter? Yes. In fact Bounded Counter does exactly that. However it has its limitations and works only over a single value at the time.

You most likely would need a combination of both in order to achieve your goal.

Keep in mind that transactions don't necessarily have to offer abort mechanics nor conditional updates (in fact RAMP transaction protocol doesn't guarantee any of them) - transactions are mostly about consistent view of application state in face of multi-value updates.

PS: Based on your use case there are other questions (like the validity of using CRDT or requirement of counter being non-negative) but these don't qualify on StackOverflow.

Bartosz Sypytkowski
  • 7,463
  • 19
  • 36
  • Yes, maybe you are right that simple "transaction" may be not the best name for that. But what then? Conditional transaction, or conditional atomic update, or something else? – Aleksei Gutikov Nov 05 '21 at 14:46
  • CURE transaction protocol should be capable of doing such transactions. However, the only real life implementation of it, that I'm aware of, is AntidoteDB (which also supports bounded counters). – Bartosz Sypytkowski Nov 05 '21 at 15:30