{"id":1752,"date":"2014-12-16T18:50:43","date_gmt":"2014-12-16T18:50:42","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=1752"},"modified":"2022-11-12T18:08:51","modified_gmt":"2022-11-13T02:08:51","slug":"optimistic-or-pessimistic-locking-which-one-should-you-pick","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/","title":{"rendered":"Optimistic vs Pessimistic Locking \u2013 Which One Should You Pick?"},"content":{"rendered":"<p><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Assume that Alice and Joe both read the same data item from Couchbase Server, then they\u00a0<\/span><span style=\"font-style: normal;font-size: 15px;font-family: Arial\">both changed the data, and then both tried to write the new versions back to the database.\u00a0<\/span><span style=\"font-style: normal;font-size: 15px;font-family: Arial\">Whose changes should be saved? Alice\u2019s? Joe\u2019s? Neither? A combination? It\u2019s questions like these that determine the winner in the debate over pessimistic vs optimistic locking.<\/span><\/p>\n<p><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Specifically, developers use locking to serialize access to shared data items. But which locking scheme <\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">should you pick for your application?<\/span><\/p>\n<p><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">In this blog, I am going to explain optimistic locking vs. pessimistic locking and the differences between the two. We will also<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">\u00a0discuss the optimistic and pessimistic locking APIs that you can use in Couchbase <\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">Server to control concurrent access to your data.<\/span><\/p>\n<h6><strong>What is Optimistic Locking in Couchbase Server?<\/strong><\/h6>\n<p><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Let\u2019s assume we are building an online wikipedia &#8211; like application using Couchbase Server:\u00a0<\/span><span style=\"font-style: normal;font-size: 15px;font-family: Arial\">users can update an article and add newer articles. Let\u2019s assume Alice is using this application\u00a0<\/span><span style=\"font-style: normal;font-size: 15px;font-family: Arial\">to edit an article on\u00a0<\/span><b style=\"font-size: 15px;font-family: Arial\">\u2018bicycles\u2019\u00a0<\/b><span style=\"font-style: normal;font-size: 15px;font-family: Arial\">to correct some information. Alice opens up the article and makes\u00a0<\/span><span style=\"font-style: normal;font-size: 15px;font-family: Arial\">those changes but before she hits save, she gets distracted and walks away from her desk.\u00a0<\/span><span style=\"font-style: normal;font-family: Arial;font-size: 15px\">In the meantime, let\u2019s assume Joe notices the same error in the bicycle article and wants to\u00a0<\/span><span style=\"font-style: normal;font-size: 15px;font-family: Arial\">correct the mistake.<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">If optimistic locking is used in the application, Joe can edit the article and save his changes.\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">When Alice returns and wants to save her changes, either Alice or the application will want to\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">handle the latest updates before allowing Alice\u2019s action to change the document. Optimistic\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">locking takes the \u201coptimistic\u201d view that data conflicts due to concurrent edits occur rarely, so it\u2019s\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">more important to allow concurrent edits.<\/span><\/p>\n<p><span style=\"font-family: 'proxima nova', proxima-nova-1, proxima-nova-2, Avenir, Futura, 'Gill Sans', Helvetica, Arial, sans-serif;font-size: 16px;font-style: normal;font-weight: bold\">What is Pessimistic Locking in Couchbase Server?<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Now let\u2019s assume that your business process requires exclusive access to one or more <\/span><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">documents or a graph of documents. Referring to our previous example, when Alice is editing\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">the document she does not want any other user to edit the same document. If Joe tries to open\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">the page, he will have to wait until Alice has released the lock.<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">With pessimistic locking, the application will need to explicitly get a lock on the document to\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">guarantee exclusive user access. When the user is done accessing the document, the locks can\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">be removed either manually or using a timeout.<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span style=\"font-family: 'proxima nova', proxima-nova-1, proxima-nova-2, Avenir, Futura, 'Gill Sans', Helvetica, Arial, sans-serif;font-size: 16px;font-style: normal;font-weight: bold\"><br \/>\nSo which one should you pick?<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><b style=\"font-size: 15px;font-family: Arial\">The answer is that, there is no correct answer &#8211;\u00a0<\/b><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">it depends<\/span><b style=\"font-size: 15px;font-family: Arial\">. You should pick your locking\u00a0<\/b><b><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">scheme based on your application requirements.<\/span><\/b><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Unless you expect a document to be heavily contended, optimistic locking is going to be much\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">lower overhead than pessimistic locking &#8211; grab the item you need, update it quickly and attempt t<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">o apply it. If some other actor in the system beat you to it, you can just retry till you succeed.<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">With pessimistic locking, you can get exclusive access to a given item &#8211; no other thread can\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">access the item while it is locked. You need to be sure you release the lock during failures. Imagine, I have the cereal object and won&#8217;t give it up until I get the milk object. But you have the milk object and won&#8217;t give it up until you get the cereal object. Timeouts can be used to possibly break deadlocks or to deal with clients who fail to release the lock.\u00a0<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">For simplicity sake, users might pick the same locking strategy across their application. This\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">works well if the access requirements of all the different objects across your application are\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">the same but in reality, this is not the case &#8211; different application objects have different access\u00a0<\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">requirements. For example, in the case of social games &#8211;<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">1. Character and player inventory information is heavily accessed during gameplay,<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">requiring fast read-write access. First choice &#8211; Use optimistic locking. Next choice &#8211;<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Pessimistic locking<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">2. Player accounts and preferences are read during player login or at the start of a game<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal;font-size: 11px;font-family: Helvetica\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">but not frequently updated. Optimistic locking would work well here too.<\/span><\/p>\n<p style=\"margin-bottom: 0px;font-style: normal\"><span style=\"font-family: 'proxima nova', proxima-nova-1, proxima-nova-2, Avenir, Futura, 'Gill Sans', Helvetica, Arial, sans-serif;font-size: 16px;font-style: normal;font-weight: bold\">Obtaining a pessimistic lock in Couchbase Server<\/span><\/p>\n<p style=\"font-family: Helvetica;font-size: 11px;margin-bottom: 0px;font-style: normal\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Obtaining a lock in Couchbase Server consists of the following steps :<\/span><\/p>\n<ol>\n<li style=\"font-family: Helvetica;font-size: 10px;margin-bottom: 0px;font-style: normal\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Use the get-and-lock API to retrieve a value for a given key and lock that key<\/span><\/li>\n<li style=\"font-family: Helvetica;font-size: 10px;margin-bottom: 0px;font-style: normal\"><span style=\"font-family: Arial;font-size: 15px;font-style: normal\">The application now has exclusive control over the document<\/span><\/li>\n<\/ol>\n<p style=\"margin-bottom: 0px;font-style: normal\"><span style=\"font-family: 'proxima nova', proxima-nova-1, proxima-nova-2, Avenir, Futura, 'Gill Sans', Helvetica, Arial, sans-serif;font-size: 16px;font-style: normal;font-weight: bold\">Obtaining a optimistic lock in Couchbase Server<\/span><\/p>\n<p style=\"font-family: Helvetica;font-size: 11px;margin-bottom: 0px;font-style: normal\"><span class=\"Apple-style-span\" style=\"font-size: 15px;font-family: Arial\">Obtaining a lock in Couchbase Server consists of the following steps :<\/span><\/p>\n<ol>\n<li style=\"font-family: Helvetica;font-size: 11px;margin-bottom: 0px;font-style: normal\"><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">Use the check-and-set (CAS) API to retrieve a CAS revision number<\/span><\/li>\n<\/ol>\n<h6 style=\"margin-bottom: 0px;font-style: normal\">Releasing a lock in Couchbase Server<\/h6>\n<p style=\"font-style: normal;font-size: 16px;font-family: ff-meta-serif-web-pro-1, ff-meta-serif-web-pro-2, Georgia, 'Times New Roman', Times, serif\"><span style=\"font-family: Arial\"><span style=\"font-size: 15px;line-height: 22px\">Perform these steps to manually release a lock<\/span><\/span><span style=\"font-size: 15px;font-family: Arial;font-style: normal\">:<\/span><\/p>\n<ol style=\"font-style: normal;font-size: 16px;font-family: ff-meta-serif-web-pro-1, ff-meta-serif-web-pro-2, Georgia, 'Times New Roman', Times, serif\">\n<li style=\"font-style: normal;font-size: 11px;font-family: Helvetica\"><span style=\"font-style: normal;font-size: 15px;font-family: Arial\">Use CAS to modify the value and release the lock<\/span><\/li>\n<\/ol>\n<p><span style=\"font-family: 'proxima nova', proxima-nova-1, proxima-nova-2, Avenir, Futura, 'Gill Sans', Helvetica, Arial, sans-serif;font-size: 16px;font-style: normal;font-weight: bold\">Behind the scenes of CAS<\/span><\/p>\n<p><span style=\"background-color: transparent;font-style: normal\">CAS operation is a simple concept which can be used to build more advanced concurrency control mechanisms. CAS determines if an object has been updated by another client between the time it was initially read and the time the save was attempted. If the object is modified by another client, an error is raised and the application has to re-read the value and retry the operation. If objects are not in high contention, the transformation of the data is idempotent and retrying the operation is easily accomplished without too much wasted work, optimistic locking is a good solution that provides high performance in the average case. <\/span><\/p>\n<p><span style=\"text-align: justify;background-color: transparent;font-style: normal\">A common way of interacting with CAS involves a CAS loop as shown in the community developed <\/span><a style=\"text-align: justify\" href=\"https:\/\/github.com\/dustin\/gomemcached\/blob\/c8a7845be6b4010a3a4ddd93118e7da11d0a64e2\/client\/mc.go#L297\"><span style=\"color: #1155cc;background-color: transparent;font-style: normal;text-decoration: underline\">go memcached client<\/span><\/a><span style=\"text-align: justify;background-color: transparent;font-style: normal\">.<\/span><\/p>\n<p><span style=\"background-color: transparent;font-weight: bold;font-style: normal\">For example: <\/span><span style=\"background-color: transparent;font-style: normal\">Imagine there are 3 clients as shown in the interaction diagram below. All of the three clients attempt to update object X using CAS &#8211; each client succeeds, one at a time.<\/span><\/p>\n<p><span style=\"font-family: 'proxima nova', proxima-nova-1, proxima-nova-2, Avenir, Futura, 'Gill Sans', Helvetica, Arial, sans-serif;font-size: 16px;font-style: normal;font-weight: bold\">You didn&#8217;t release the lock, let Couchbase do it for you<\/span><\/p>\n<p>When you perform a get-and-lock operation you provide an expiration for the lock as a parameter. The default amount of time a key can be locked is 15 seconds. After 15 seconds, if you don&#8217;t release the lock manually, Couchbase releases it automatically.<\/p>\n<p><span style=\"font-family: 'proxima nova', proxima-nova-1, proxima-nova-2, Avenir, Futura, 'Gill Sans', Helvetica, Arial, sans-serif\"><b>Final Thoughts on Pessimistic and Optimistic Locking in Databases<\/b><\/span><\/p>\n<p>Optimistic locking might not be the best solution for every situation. While some use-cases work well with optimistic locking, others might need stricter schemes like pessimistic locking.<\/p>\n<p>Locking might not be good for all cases &#8211; your application can have a problem if there is a lock contention. A thread can hold a lock and be de-scheduled by the OS. Then all the threads that want to acquire this lock will be blocked. One option is to avoid locking altogether where possible by using atomic operations. These API&#8217;s can be very helpful on heavily contested data.<\/p>\n<p>However, if you really need locking and feel that optimistic locking covers most of your applications&#8217; use-cases, optimistic locking using CAS in Couchbase Server is so easy to implement there&#8217;s no reason you shouldn&#8217;t try.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Assume that Alice and Joe both read the same data item from Couchbase Server, then they\u00a0both changed the data, and then both tried to write the new versions back to the database.\u00a0Whose changes should be saved? Alice\u2019s? Joe\u2019s? Neither? A [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"ppma_author":[8972],"class_list":["post-1752","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Optimistic vs Pessimistic Locking: What Are the Differences?<\/title>\n<meta name=\"description\" content=\"This blog page explains optimistic locking vs. pessimistic locking and the differences between the two, including locking APIs in Couchbase Server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Optimistic vs Pessimistic Locking \u2013 Which One Should You Pick?\" \/>\n<meta property=\"og:description\" content=\"This blog page explains optimistic locking vs. pessimistic locking and the differences between the two, including locking APIs in Couchbase Server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-12-16T18:50:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-13T02:08:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/11\/couchbase-nosql-dbaas.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Don Pinto, Principal Product Manager, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Don Pinto, Principal Product Manager, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/\"},\"author\":{\"name\":\"Don Pinto, Principal Product Manager, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/eb130a1e0278989e089a7fbbf8bc754c\"},\"headline\":\"Optimistic vs Pessimistic Locking \u2013 Which One Should You Pick?\",\"datePublished\":\"2014-12-16T18:50:42+00:00\",\"dateModified\":\"2022-11-13T02:08:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/\"},\"wordCount\":1145,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/\",\"name\":\"Optimistic vs Pessimistic Locking: What Are the Differences?\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2014-12-16T18:50:42+00:00\",\"dateModified\":\"2022-11-13T02:08:51+00:00\",\"description\":\"This blog page explains optimistic locking vs. pessimistic locking and the differences between the two, including locking APIs in Couchbase Server.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Optimistic vs Pessimistic Locking \u2013 Which One Should You Pick?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/eb130a1e0278989e089a7fbbf8bc754c\",\"name\":\"Don Pinto, Principal Product Manager, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/39c6d6178c73f0dc09af63f930a4f37d\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/574759a111515cb8c5d5a1f5268d2759050bd8383654dc0d9393324f0c35fae0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/574759a111515cb8c5d5a1f5268d2759050bd8383654dc0d9393324f0c35fae0?s=96&d=mm&r=g\",\"caption\":\"Don Pinto, Principal Product Manager, Couchbase\"},\"description\":\"Don Pinto is a Principal Product Manager at Couchbase and is currently focused on advancing the capabilities of Couchbase Server. He is extremely passionate about data technology, and in the past has authored several articles on Couchbase Server including technical blogs and white papers. Prior to joining Couchbase, Don spent several years at IBM where he maintained the role of software developer in the DB2 information management group and most recently as a program manager on the SQL Server team at Microsoft. Don holds a master's degree in computer science and a bachelor's in computer engineering from the University of Toronto, Canada.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/don-pinto\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Optimistic vs Pessimistic Locking: What Are the Differences?","description":"This blog page explains optimistic locking vs. pessimistic locking and the differences between the two, including locking APIs in Couchbase Server.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/","og_locale":"en_US","og_type":"article","og_title":"Optimistic vs Pessimistic Locking \u2013 Which One Should You Pick?","og_description":"This blog page explains optimistic locking vs. pessimistic locking and the differences between the two, including locking APIs in Couchbase Server.","og_url":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/","og_site_name":"The Couchbase Blog","article_published_time":"2014-12-16T18:50:42+00:00","article_modified_time":"2022-11-13T02:08:51+00:00","og_image":[{"width":1800,"height":630,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/11\/couchbase-nosql-dbaas.png","type":"image\/png"}],"author":"Don Pinto, Principal Product Manager, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Don Pinto, Principal Product Manager, Couchbase","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/"},"author":{"name":"Don Pinto, Principal Product Manager, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/eb130a1e0278989e089a7fbbf8bc754c"},"headline":"Optimistic vs Pessimistic Locking \u2013 Which One Should You Pick?","datePublished":"2014-12-16T18:50:42+00:00","dateModified":"2022-11-13T02:08:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/"},"wordCount":1145,"commentCount":6,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/","url":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/","name":"Optimistic vs Pessimistic Locking: What Are the Differences?","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2014-12-16T18:50:42+00:00","dateModified":"2022-11-13T02:08:51+00:00","description":"This blog page explains optimistic locking vs. pessimistic locking and the differences between the two, including locking APIs in Couchbase Server.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/optimistic-or-pessimistic-locking-which-one-should-you-pick\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Optimistic vs Pessimistic Locking \u2013 Which One Should You Pick?"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/eb130a1e0278989e089a7fbbf8bc754c","name":"Don Pinto, Principal Product Manager, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/39c6d6178c73f0dc09af63f930a4f37d","url":"https:\/\/secure.gravatar.com\/avatar\/574759a111515cb8c5d5a1f5268d2759050bd8383654dc0d9393324f0c35fae0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/574759a111515cb8c5d5a1f5268d2759050bd8383654dc0d9393324f0c35fae0?s=96&d=mm&r=g","caption":"Don Pinto, Principal Product Manager, Couchbase"},"description":"Don Pinto is a Principal Product Manager at Couchbase and is currently focused on advancing the capabilities of Couchbase Server. He is extremely passionate about data technology, and in the past has authored several articles on Couchbase Server including technical blogs and white papers. Prior to joining Couchbase, Don spent several years at IBM where he maintained the role of software developer in the DB2 information management group and most recently as a program manager on the SQL Server team at Microsoft. Don holds a master's degree in computer science and a bachelor's in computer engineering from the University of Toronto, Canada.","url":"https:\/\/www.couchbase.com\/blog\/author\/don-pinto\/"}]}},"authors":[{"term_id":8972,"user_id":4,"is_guest":0,"slug":"don-pinto","display_name":"Don Pinto, Principal Product Manager, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/574759a111515cb8c5d5a1f5268d2759050bd8383654dc0d9393324f0c35fae0?s=96&d=mm&r=g","author_category":"","last_name":"Pinto, Principal Product Manager, Couchbase","first_name":"Don","job_title":"","user_url":"","description":"Don Pinto is a Principal Product Manager at Couchbase and is currently focused on advancing the capabilities of Couchbase Server. He is extremely passionate about data technology, and in the past has authored several articles on Couchbase Server including technical blogs and white papers. Prior to joining Couchbase, Don spent several years at IBM where he maintained the role of software developer in the DB2 information management group and most recently as a program manager on the SQL Server team at Microsoft. Don holds a master's degree in computer science and a bachelor's in computer engineering from the University of Toronto, Canada."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/1752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=1752"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/1752\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=1752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=1752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=1752"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=1752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}