{"id":10266,"date":"2018-05-30T00:00:00","date_gmt":"2018-05-30T05:00:00","guid":{"rendered":"https:\/\/threecloud.wpengine.com\/post\/cosmos-db-consistency-levels\/"},"modified":"2022-11-30T09:13:00","modified_gmt":"2022-11-30T15:13:00","slug":"cosmos-db-consistency-levels","status":"publish","type":"post","link":"https:\/\/3cloudsolutions.com\/resources\/cosmos-db-consistency-levels\/","title":{"rendered":"Cosmos DB: Consistency Levels"},"content":{"rendered":"<p><span style=\"background-color: transparent;\">To continue with my topic of Cosmos DB, today I\u2019ll discuss the data consistency models that are supported within the context of Cosmos DB. If you don\u2019t already know, data consistency is the ability of the data to be read once it has been written. When choosing a consistency model, you want to take into consideration consistency, availability and latency.<\/span><\/p>\n<\/p>\n<p>As you begin to understand what\u2019s going on with Cosmos DB, you\u2019ll realize that we need to have a variety of models. In most scenarios, we have 2 models.<\/p>\n<ul>\n<li><strong>A strong model<\/strong>, which says you can\u2019t read anything until it\u2019s all the way committed to every node that\u2019s readable. Typically, we see this in database structures and SQL Server. What we really want is a transactional model that can mix everything, so we have the advantage of consistent reads. The trade off is that it takes a long time, thus we have a lot of latency while waiting for things to commit and to make sure everything is happening the way we expect it to in the database.<\/li>\n<li>Cosmos can do strong, so the reads are guaranteed to the most recent version of the item and there\u2019s no inconsistency with the data. However, it\u2019s very limiting in its approach in how you can leverage the power of Cosmos within the environment.<\/li>\n<\/ul>\n<ul>\n<li>The extreme opposite side is <strong>eventual<\/strong>. Basically, this means eventually we\u2019re going to get our data consistent; the changes are going to show up eventually and they may not show up in order. Rarely an acceptable scenario, the exception being log files since we want to look at log files after the fact, not when they\u2019re being written. Consistency will eventually straighten itself out.<\/li>\n<\/ul>\n<p>But that\u2019s not a good solution either. What Cosmos DB brings to the table is 3 options with consistency:<\/p>\n<p><em><strong>1. Session<\/strong> <\/em>\u2013 The most common use case, with over 50% of customers using Session in the platform. Session guarantees that you\u2019re able to see what you wrote. So, if I\u2019m working in the application, I\u2019m going to have a consistent read and write experience.<\/p>\n<p>I get a good user experience, while also not having to wait for everything to fully commit around the globe or for the other pieces to happen to make sure it will eventually catch up. You\u2019ll be able to read your writes, it\u2019s going to come in the right order and all the data will be there.<\/p>\n<p><em><strong>2. Consistent Prefix<\/strong><\/em> \u2013 With this you\u2019ll get some of the stuff updated as it starts to go, and the data will come in the right order, but there\u2019s no guarantee that you\u2019re going to get all the pieces you\u2019re expecting. It gives you the opportunity to see less latency in your operation but get more read possibilities.<\/p>\n<p><em><strong>3. Bounded Staleness<\/strong><\/em> \u2013 This is where you\u2019ll draw a boundary around what you want to be strong and what you don\u2019t. This is a level deeper towards the strong side from Session. In this case, the reads will lie behind the writes, but you know the interval that you\u2019re lagging. Also, that there\u2019s going to be some inconsistencies over a smaller period of time, but you don\u2019t need to wait for everything to commit. It goes beyond the scope of Session.<\/p>\n<div class=\"hs-responsive-embed-wrapper hs-responsive-embed\" style=\"width: 100%; height: auto; position: relative; overflow: hidden; padding: 0; max-width: 560px; max-height: 315px; min-width: 256px; margin: 0px auto; display: block;\">\n<div class=\"hs-responsive-embed-inner-wrapper\" style=\"position: relative; overflow: hidden; max-width: 100%; padding-bottom: 56.25%; margin: 0;\"><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/b4nHQcTVCRc\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n<\/div>\n<p>We have all these consistency levels available inside Cosmos DB to meet the needs of our various applications. All of these are guaranteed on SLAs. Microsoft guarantees your consistency model will work within the confines that you\u2019ve given the application to work in.<\/p>\n<p>Keep in mind, you need to weigh out things like lower latency with better read scalability and higher availability. If you can live with the latency and it\u2019s more important that you get consistent reads, then you\u2019ll want to lean towards strong. Point being, you have options.<\/p>\n<p>Need further help? Our expert team and solution offerings can help your business with any Azure product or service, including Managed Services offerings. Contact us at 888-8AZURE or\u00a0 <a href=\"mailto:sales@3cloudsolutions.com\">sales@3cloudsolutions.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To continue with my topic of Cosmos DB, today I\u2019ll discuss the data consistency models&mldr;<\/p>\n","protected":false},"author":22,"featured_media":9548,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[260],"tags":[],"class_list":["post-10266","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai","topics-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/10266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/comments?post=10266"}],"version-history":[{"count":0,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/10266\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media\/9548"}],"wp:attachment":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media?parent=10266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/categories?post=10266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/tags?post=10266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}