Optimistic Locking in YugaByte DB

Hi forum members,
I was wondering whether YugabyteDB supports optimistic locking?
If it does, I have the following questions:

  1. What are the implementation details of it? Does the database read versions from cache or disk?
  2. How does it impact write performance?

Hi @Ali_Zadehdehbalaei

See docs for locking: Explicit locking | YugabyteDB Docs

Depends if the data is already cached in-memory.

One of the transactions gets aborted and has to be retried by the client.

1 Like

Thanks for your reply @dorian_yugabyte. :pray: :heart:
Now I have quite a few new questions:

  1. How can I use optimistic locking in Yugabyte DB?
  2. Does it have a specific syntax or it will be handled manually and the database will only provides some constructs to speed up the process?
  3. Is the “For Update” syntax used primarily for pessimistic locking or it can be used solely for optimistic locking as well?

It’s used by default.

See details Explicit locking | YugabyteDB Docs

1 Like

Hi. I hope you are well.
I’m a new user of Yugabyte DB.
Does using optimistic locking cause read before write?
(If it causes read before write, therefore it reduces performance a lot. Am I right?)

It depends on the query and the full table schema + indexes.

1 Like