{"id":4424,"date":"2018-01-10T21:21:37","date_gmt":"2018-01-11T05:21:37","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=4424"},"modified":"2023-06-23T09:00:33","modified_gmt":"2023-06-23T16:00:33","slug":"saga-pattern-implement-business-transactions-using-microservices-part","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/","title":{"rendered":"Saga Pattern | Application Transactions Using Microservices \u2013 Part I"},"content":{"rendered":"<p><a href=\"https:\/\/www.couchbase.com\/blog\/distributed-multi-document-acid-transactions-in-couchbase\/\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-7564\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/Couchbase-transaction.png\" alt=\"\" width=\"1110\" height=\"134\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Couchbase-transaction.png 704w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Couchbase-transaction-300x36.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Couchbase-transaction-20x2.png 20w\" sizes=\"auto, (max-width: 1110px) 100vw, 1110px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">Transactions are an essential part of applications. Without them, it would be impossible to maintain data consistency.<\/span><\/p>\n<p><span style=\"font-weight: 400\">One of the most powerful types of transactions is called a Two-Phase Commit, which is in summary when <\/span><span style=\"font-weight: 400\">the commit of a first transactions depends on the completion of a second.<\/span><span style=\"font-weight: 400\"> It is useful especially when you have to update multiples entities at the same time, like confirming an order and updating the stock at once. <\/span><\/p>\n<p><span style=\"font-weight: 400\">However, when you are performing Microservices orchestration, for example, things get more complicated. Each service is a system apart with its own database, and you no longer can leverage the simplicity of local two-phase-commits to maintain the consistency of your whole system.<\/span><\/p>\n<p><span style=\"font-weight: 400\">When you lose this ability, RDBMS becomes quite a bad choice for storage, as you could accomplish the same \u201csingle entity atomic transaction\u201d but dozens of times faster by just using a <a href=\"https:\/\/www.couchbase.com\/products\/capella\/\">NoSQL database<\/a> like Couchbase. That is why the majority of companies working with microservices are also using NoSQL.<\/span><\/p>\n<p><span style=\"font-weight: 400\">To exemplify this problem, consider the following high-level Microservices architecture of an e-commerce system:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4425\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/e-commerce-architecture-1024x693.png\" alt=\"\" width=\"573\" height=\"388\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/e-commerce-architecture-1024x693.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/e-commerce-architecture-300x203.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/e-commerce-architecture-768x520.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/e-commerce-architecture-235x160.png 235w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/e-commerce-architecture-20x14.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/e-commerce-architecture.png 1176w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/p>\n<p><span style=\"font-weight: 400\">In the example above, one can\u2019t just place an order, charge the customer, update the stock and send it to delivery all in a single ACID transaction. To execute this entire flow consistently, you would be required to create a distributed transaction.<\/span><\/p>\n<p><span style=\"font-weight: 400\">We all know how difficult is to implement anything distributed, and transactions, unfortunately, are not an exception. Dealing with transient states, eventual consistency between services, isolations, and rollbacks are scenarios that should be considered during the design phase.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Fortunately, we<\/span> already<span style=\"font-weight: 400\"> came up with some good patterns for it as we have been implementing distributed transactions for over 20 years now. The one that I would like to talk about today is called Saga pattern.<\/span><\/p>\n<h2><b>The SAGA Pattern<\/b><\/h2>\n<p>A <strong>saga pattern<\/strong> is a sequence of local transactions where each transaction updates data within a single service. The first transaction in a saga is initiated by an external request corresponding to the system operation, and then each subsequent step is triggered by the completion of the previous one.<\/p>\n<p><span style=\"font-weight: 400\">One of the most well-known patterns for distributed transactions is called Saga. The first paper about it<\/span><a href=\"https:\/\/www.cs.cornell.edu\/andru\/cs711\/2002fa\/reading\/sagas.pdf\"> <span style=\"font-weight: 400\">was published back in 1987<\/span><\/a><span style=\"font-weight: 400\"> and sagas have been a popular<\/span> solution<span style=\"font-weight: 400\"> since then.<\/span><\/p>\n<p><span style=\"font-weight: 400\"> Using our previous e-commerce example, in a very high-level design a saga pattern implementation would look like the following:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10012\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/saga-pattern-sequence.png\" alt=\"saga implementation\" width=\"1024\" height=\"627\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-sequence.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-sequence-300x184.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-sequence-768x470.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-sequence-20x12.png 20w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p><span style=\"font-weight: 400\">There are a couple of different ways to implement a saga transaction, but the two most popular are:<\/span><\/p>\n<ul>\n<li><b>Events\/Choreography:<\/b><span style=\"font-weight: 400\"> When there is no central coordination, each service produces and listen to other service\u2019s events and decides if an action should be taken or not.<\/span><\/li>\n<li><b>Command\/Orchestration<\/b><span style=\"font-weight: 400\">: when a coordinator service is responsible for centralizing the saga\u2019s decision making and sequencing business logic \u2028<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Let\u2019s go a little bit deeper in each implementation to understand how sagas work.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h4><b>Events\/Choreography<\/b><\/h4>\n<p><span style=\"font-weight: 400\">In the Events\/Choreography approach, the first service executes a transaction and then publishes an event. This event is listened by one or more services which execute local transactions and publish (or not) new events.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The distributed transaction ends when the last service executes its local transaction and does not publish any events or the event published is not heard by any of the saga\u2019s participants.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let\u2019s see how the saga pattern would look like in our e-commerce example:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4427\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-09-at-6.13.39-PM.png\" alt=\"\" width=\"476\" height=\"506\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.13.39-PM.png 936w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.13.39-PM-282x300.png 282w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.13.39-PM-768x817.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.13.39-PM-300x319.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.13.39-PM-20x20.png 20w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/p>\n<ol>\n<li><span style=\"font-weight: 400\"><em>Order Service<\/em> saves a\u00a0new order, set the state as <em>pending<\/em> and publish an event called <em><strong>ORDER_CREATED_EVENT<\/strong><\/em>.<\/span><\/li>\n<li>The <em>Payment Service<\/em> listens to <em><strong>ORDER_CREATED_EVENT<\/strong><\/em>, charge the client and publish the event <strong><em>BILLED_ORDER_EVENT<\/em><\/strong>.<\/li>\n<li>The <em>Stock Service<\/em> listens to <em><strong>BILLED_ORDER_EVENT<\/strong><\/em>, update the stock, prepare the products bought in the order and publish <em><strong>ORDER_PREPARED_EVENT<\/strong><\/em>.<\/li>\n<li><em>Delivery Service<\/em> listens to <em><strong>ORDER_PREPARED_EVENT<\/strong><\/em> and then pick up and deliver the product. At the end, it publishes an <em><strong>ORDER_DELIVERED_EVENT<\/strong><\/em><\/li>\n<li>\u00a0Finally, <em>Order Service<\/em> listens to <em><strong>ORDER_DELIVERED_EVENT<\/strong><\/em> and set the state of the order as concluded.<\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">In the case above, if the state of the order needs to be tracked, Order Service could simply listen to all events and update its state.<\/span><\/p>\n<h4><\/h4>\n<p>&nbsp;<\/p>\n<h4><b>Rollbacks in distributed transactions<\/b><\/h4>\n<p><span style=\"font-weight: 400\">Rolling back a distributed transaction does not come for free. Normally you have to implement another compensating transaction for what has been done before.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Suppose that Stock Service has failed during a transaction. Let\u2019s see what the rollback would look like:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4428\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-09-at-6.36.17-PM-1024x702.png\" alt=\"\" width=\"567\" height=\"389\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.36.17-PM-1024x702.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.36.17-PM-300x206.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.36.17-PM-768x526.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.36.17-PM-235x160.png 235w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.36.17-PM-20x14.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Screen-Shot-2018-01-09-at-6.36.17-PM.png 1074w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/p>\n<ol>\n<li><span style=\"font-weight: 400\"><em>Stock Service<\/em> produces <strong><em>PRODUCT_OUT_OF_STOCK_EVENT<\/em><\/strong>;<\/span><\/li>\n<li>Both <em>Order Service<\/em> and <em>Payment Servic<\/em>e listen to the previous message:\n<ol>\n<li><span style=\"font-weight: 400\">P<em>ayment Service<\/em> refund the client<\/span><\/li>\n<li><span style=\"font-weight: 400\"><em>Order Service<\/em> set the order state as failed \u00a0\u00a0\u00a0\u00a0<\/span><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">Note that it is crucial to define a common shared ID for each transaction, so whenever you throw an event, all listeners can know right away which transaction it refers to.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h4><b>Benefits and drawbacks of using Saga\u2019s Event\/Choreography design pattern<\/b><\/h4>\n<p><span style=\"font-weight: 400\">Events\/Choreography is a natural way to implement a Saga orchestration pattern. It is simple, easy to understand, does not require much effort to build, and all <\/span><span style=\"font-weight: 400\">participants are loosely coupled as they don\u2019t have direct knowledge of each other<\/span><span style=\"font-weight: 400\">.<\/span><span style=\"font-weight: 400\"> If your transaction involves 2 to 4 steps, it might be a very good fit.<\/span><\/p>\n<p><span style=\"font-weight: 400\">However, this approach can rapidly become confusing if you keep adding extra steps in your transaction as it is difficult to track which services listen to which events. Moreover, it also might add a cyclic dependency between services<\/span> <span style=\"font-weight: 400\">as they have to subscribe to one another\u2019s<\/span> <span style=\"font-weight: 400\">events<\/span><span style=\"font-weight: 400\">.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Finally, testing would be tricky to implement using this design, in order to simulate the transaction pattern you should have all services running.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\"><a href=\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part-2\/\">In the next post<\/a>, I will explain how to address most of the problems with the Saga\u2019s <\/span><span style=\"font-weight: 400\">Events\/Choreography approach using another Saga implementation called <\/span><b>Command\/Orchestration<\/b>.<\/p>\n<p><span style=\"font-weight: 400\">In the meantime, if you have any Saga Design Pattern questions about Microservices, the Saga architecture, or Saga applications feel free to ask me at <a href=\"https:\/\/twitter.com\/deniswsrosa\">@deniswsrosa<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Transactions are an essential part of applications. Without them, it would be impossible to maintain data consistency. One of the most powerful types of transactions is called a Two-Phase Commit, which is in summary when the commit of a first [&hellip;]<\/p>\n","protected":false},"author":8754,"featured_media":9925,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1814],"tags":[],"ppma_author":[9059],"class_list":["post-4424","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Saga Pattern: Microservices Design Examples | Couchbase<\/title>\n<meta name=\"description\" content=\"A saga pattern is a sequence of local transactions where each transaction updates data within a single service. Check out design examples at Couchbase.\" \/>\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\/saga-pattern-implement-business-transactions-using-microservices-part\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Saga Pattern | Application Transactions Using Microservices \u2013 Part I\" \/>\n<meta property=\"og:description\" content=\"A saga pattern is a sequence of local transactions where each transaction updates data within a single service. Check out design examples at Couchbase.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-11T05:21:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-23T16:00:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/saga-pattern-blogbanner.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1575\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Denis Rosa, Developer Advocate, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@deniswsrosa\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Rosa, Developer Advocate, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/\"},\"author\":{\"name\":\"Denis Rosa, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/fe3c5273e805e72a5294611a48f62257\"},\"headline\":\"Saga Pattern | Application Transactions Using Microservices \u2013 Part I\",\"datePublished\":\"2018-01-11T05:21:37+00:00\",\"dateModified\":\"2023-06-23T16:00:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/\"},\"wordCount\":998,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-blogbanner.jpg\",\"articleSection\":[\"Application Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/\",\"name\":\"Saga Pattern: Microservices Design Examples | Couchbase\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-blogbanner.jpg\",\"datePublished\":\"2018-01-11T05:21:37+00:00\",\"dateModified\":\"2023-06-23T16:00:33+00:00\",\"description\":\"A saga pattern is a sequence of local transactions where each transaction updates data within a single service. Check out design examples at Couchbase.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-blogbanner.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-blogbanner.jpg\",\"width\":1575,\"height\":628,\"caption\":\"A developer holding a smartphone and a credit card checks the saga pattern on visible on the device.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Saga Pattern | Application Transactions Using Microservices \u2013 Part I\"}]},{\"@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\/fe3c5273e805e72a5294611a48f62257\",\"name\":\"Denis Rosa, Developer Advocate, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/be0716f6199cfb09417c92cf7a8fa8d6\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g\",\"caption\":\"Denis Rosa, Developer Advocate, Couchbase\"},\"description\":\"Denis Rosa is a Developer Advocate for Couchbase and lives in Munich - Germany. He has a solid experience as a software engineer and speaks fluently Java, Python, Scala and Javascript. Denis likes to write about search, Big Data, AI, Microservices and everything else that would help developers to make a beautiful, faster, stable and scalable app.\",\"sameAs\":[\"https:\/\/x.com\/deniswsrosa\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/denis-rosa\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Saga Pattern: Microservices Design Examples | Couchbase","description":"A saga pattern is a sequence of local transactions where each transaction updates data within a single service. Check out design examples at Couchbase.","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\/saga-pattern-implement-business-transactions-using-microservices-part\/","og_locale":"en_US","og_type":"article","og_title":"Saga Pattern | Application Transactions Using Microservices \u2013 Part I","og_description":"A saga pattern is a sequence of local transactions where each transaction updates data within a single service. Check out design examples at Couchbase.","og_url":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/","og_site_name":"The Couchbase Blog","article_published_time":"2018-01-11T05:21:37+00:00","article_modified_time":"2023-06-23T16:00:33+00:00","og_image":[{"width":1575,"height":628,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/saga-pattern-blogbanner.jpg","type":"image\/jpeg"}],"author":"Denis Rosa, Developer Advocate, Couchbase","twitter_card":"summary_large_image","twitter_creator":"@deniswsrosa","twitter_misc":{"Written by":"Denis Rosa, Developer Advocate, Couchbase","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/"},"author":{"name":"Denis Rosa, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/fe3c5273e805e72a5294611a48f62257"},"headline":"Saga Pattern | Application Transactions Using Microservices \u2013 Part I","datePublished":"2018-01-11T05:21:37+00:00","dateModified":"2023-06-23T16:00:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/"},"wordCount":998,"commentCount":2,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-blogbanner.jpg","articleSection":["Application Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/","url":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/","name":"Saga Pattern: Microservices Design Examples | Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-blogbanner.jpg","datePublished":"2018-01-11T05:21:37+00:00","dateModified":"2023-06-23T16:00:33+00:00","description":"A saga pattern is a sequence of local transactions where each transaction updates data within a single service. Check out design examples at Couchbase.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-blogbanner.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/saga-pattern-blogbanner.jpg","width":1575,"height":628,"caption":"A developer holding a smartphone and a credit card checks the saga pattern on visible on the device."},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/saga-pattern-implement-business-transactions-using-microservices-part\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Saga Pattern | Application Transactions Using Microservices \u2013 Part I"}]},{"@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\/fe3c5273e805e72a5294611a48f62257","name":"Denis Rosa, Developer Advocate, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/be0716f6199cfb09417c92cf7a8fa8d6","url":"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g","caption":"Denis Rosa, Developer Advocate, Couchbase"},"description":"Denis Rosa is a Developer Advocate for Couchbase and lives in Munich - Germany. He has a solid experience as a software engineer and speaks fluently Java, Python, Scala and Javascript. Denis likes to write about search, Big Data, AI, Microservices and everything else that would help developers to make a beautiful, faster, stable and scalable app.","sameAs":["https:\/\/x.com\/deniswsrosa"],"url":"https:\/\/www.couchbase.com\/blog\/author\/denis-rosa\/"}]}},"authors":[{"term_id":9059,"user_id":8754,"is_guest":0,"slug":"denis-rosa","display_name":"Denis Rosa, Developer Advocate, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g","author_category":"","last_name":"Rosa, Developer Advocate, Couchbase","first_name":"Denis","job_title":"","user_url":"","description":"Denis Rosa is a Developer Advocate for Couchbase and lives in Munich - Germany. He has a solid experience as a software engineer and speaks fluently Java, Python, Scala and Javascript. Denis likes to write about search, Big Data, AI, Microservices and everything else that would help developers to make a beautiful, faster, stable and scalable app."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4424","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\/8754"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=4424"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4424\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/9925"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=4424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=4424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=4424"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=4424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}