Could you explain the difference between Optimistic vs Pessimistic locking?

Technology CommunityCategory: Entity FrameworkCould you explain the difference between Optimistic vs Pessimistic locking?
VietMX Staff asked 3 years ago
  • Optimistic locking is used when you don’t expect many collisions. It costs less to do a normal operation but if the collision DOES occur you would pay a higher price to resolve it as the transaction is aborted.
  • Pessimistic locking is used when a collision is anticipated. The transactions which would violate synchronization are simply blocked.

To select proper locking mechanism you have to estimate the amount of reads and writes and plan accordingly.