Theory of Intelligence
BACKEND ENGINEERING•Databases Concurrency And Caching•Concurrency•4.2 Locking & Deadlocks

4.2.1 Optimistic Locking

Subtopics: Optimistic Locking, Pessimistic Locking and Deadlocks.

4.2.1 Optimistic Locking

Row has version. UPDATE ... WHERE version = 3 returns 0 rows if someone else won. You reload and try again.

Why it matters

No long locks. Works well when conflicts are rare.

How it is used

Expose the version to the client (ETag). On conflict return 409. Bad for hot counters — use atomic increments or a queue instead.

Discuss theoretical concepts, mathematical formulas, and architectural foundations.

Supports inline code with `backticks`
No comments yet. Be the first to start the discussion!