Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do key/value stores manage concurrency?

I have read a number of articles stating key value stores only require two operations:

  • set(key, value)
  • get(key)

This is fine for a single process, but when you have multiple processes, how does the key value store manage concurrency? I would have thought a version number (E.g., an unsigned integer) used for compare-and-swap style concurrency would be required. E.g., the two operations would be:

  • set(key, value, version), where version is the condition - a mismatch causes a concurrency error and a successful match causes an increment.
  • get(key) (returning both the value and the version).
like image 209
magnus Avatar asked Jan 30 '26 21:01

magnus


1 Answers

There is two kind of design. Some are using locks and other are using MultiVersion Concurrency Control.

MVCC achieve concurrency without locks. It can be summed up as:

  • In a single read, the database return the latest version of the data
  • In a single write, the databae add a new version for the data
  • In the case of read/write concurrent request, the read get the most recent version of the data, that is before the current write.
  • In the case of write/write concurrent request, I think that one of the write is abandonned and replayed later.
like image 153
amirouche Avatar answered Feb 03 '26 10:02

amirouche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!