paint-brush
Comparing Optimistic and Pessimistic Locking With GO and PostgreSQLby@yudaph
5,227 reads
5,227 reads

Comparing Optimistic and Pessimistic Locking With GO and PostgreSQL

by Yuda Prasetiya Haqqy7mSeptember 24th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The locking mechanism is used to manage access to resources shared by user databases, tables, pages, and rows to guarantee the consistency of the transmitted data. There are two types of locking in databases, Optimistic Locking, and Pessimistic locking. Optimistic Locking. Optimistic locking is a technique for SQL database applications that do not hold row locks between selecting and updating or deleting a row. If the row does change, the update or delete will fail, and the application logic handles such failures by, for example, retrying the whole process.⁽¹⁾ Pessimistic Locking. The pessimistic locking model prevents simultaneous updates to records. As soon as one user starts to update a record, a lock is placed on it. Other users who attempt to update this record are informed that another user has an update in progress. The other users must wait until the first user has finished committing their changes, releasing the record lock. Only then can another user make changes based on the previous user's changes.⁽²⁾

Company Mentioned

Mention Thumbnail
featured image - Comparing Optimistic and Pessimistic Locking With GO and PostgreSQL
Yuda Prasetiya Haqqy HackerNoon profile picture
Yuda Prasetiya Haqqy

Yuda Prasetiya Haqqy

@yudaph

Enjoy coding

About @yudaph
LEARN MORE ABOUT @YUDAPH'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Yuda Prasetiya Haqqy HackerNoon profile picture
Yuda Prasetiya Haqqy@yudaph
Enjoy coding

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite