{"id":5465,"date":"2026-09-24T00:55:22","date_gmt":"2026-09-24T03:55:22","guid":{"rendered":"https:\/\/tucumandevelopers.com\/index.php\/2026\/09\/24\/day-3-saga-design-pattern\/"},"modified":"2026-09-24T00:55:22","modified_gmt":"2026-09-24T03:55:22","slug":"day-3-saga-design-pattern","status":"publish","type":"post","link":"https:\/\/tucumandevelopers.com\/index.php\/2026\/09\/24\/day-3-saga-design-pattern\/","title":{"rendered":"DAY 3 &#8211; SAGA Design Pattern"},"content":{"rendered":"<div>\n<div><\/header>\n<div data-article-id=\"4729067\" id=\"article-body\">\n<ul>\n<li>To manage distributed transactions across multiple microservices.<\/li>\n<li>It divides a large transaction into a series of smaller local transactions.<\/li>\n<li>Executed independently.<\/li>\n<li>Each service performs its own transaction via events or commands.<\/li>\n<li>If one transaction fails &#8211;&gt; compensating actions are executed to undo previously completed operations.<\/li>\n<\/ul>\n<h2> <a name=\"distributed-transaction\" href=\"#distributed-transaction\"> <\/a> Distributed Transaction <\/h2>\n<ul>\n<li>Multiple db or system working together to complete a single task.<\/li>\n<li>If any step fails &#8211;&gt; the entire transaction may need to be rolled back.<\/li>\n<\/ul>\n<h2> <a name=\"why-saga\" href=\"#why-saga\"> <\/a> Why SAGA <\/h2>\n<ul>\n<li>To manage distributed transaction in microservices without using complex protocols like 2PC.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiiz5t9yp8ns4upuqp0j0.png\"><\/a><\/p>\n<ul>\n<li>All these are achieved because they are executed independently.<\/li>\n<li>2PC is notorious for blocking resource locks over a network, creating performance bottlenecks and single points of failure in high-throughput banking systems, whereas Saga decouples local transactions and relies on compensation.<\/li>\n<\/ul>\n<h2> <a name=\"working-of-saga\" href=\"#working-of-saga\"> <\/a> Working of SAGA <\/h2>\n<ul>\n<li>Distributed transactions by dividing them into a sequence of smaller transactions that execute independently across multiple services.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdt2o26h9aupc5vtxj9ds.png\"><\/a><\/p>\n<h2> <a name=\"example\" href=\"#example\"> <\/a> Example <\/h2>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhedyqvr9mwdmsy6w9a7l.png\"><\/a><\/p>\n<h2> <a name=\"flow\" href=\"#flow\"> <\/a> Flow <\/h2>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frpbio9laud4eii3hdt8m.png\"><\/a><\/p>\n<h2> <a name=\"approaches\" href=\"#approaches\"> <\/a> Approaches <\/h2>\n<h3> <a name=\"choreographybased-approach-eventdriven\" href=\"#choreographybased-approach-eventdriven\"> <\/a> Choreography-Based Approach (Event-Driven) <\/h3>\n<ul>\n<li>No central coordinator<\/li>\n<li>each service knows what to do ( independent )<\/li>\n<li>Events based via message queues or event streams.<\/li>\n<li>If a service fails &#8211;&gt; it publishes a failure event accordyingly perform compensating actions.<\/li>\n<\/ul>\n<h3> <a name=\"orchestrationbased-approach-centralized\" href=\"#orchestrationbased-approach-centralized\"> <\/a> Orchestration-Based Approach (Centralized) <\/h3>\n<ul>\n<li>SAGA Execution Coordinator (orchestrator) controls the flow.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F60b8j2198kpvtvehyszf.png\"><\/a><\/p>\n<ul>\n<li>The orchestrator tells each service when to start, what to do, and when to proceed to the next step.<\/li>\n<li>In choreography, services listen to and emit events without a central coordinator. As the system scales, understanding the exact workflow path becomes complex, and accidental event loops can occur.<\/li>\n<\/ul>\n<h2> <a name=\"advantages\" href=\"#advantages\"> <\/a> Advantages <\/h2>\n<ul>\n<li>flexibility &amp; scalability &#8211;&gt; to execute transactions independently without global locking.<\/li>\n<li>NO single points of failure since transactions are distributed across multiple services.<\/li>\n<li>fault tolerance &#8211;&gt; ompensating actions to handle failures gracefully.<\/li>\n<li> <strong>Sagas embrace eventual consistency.<\/strong> The system transitions through intermediate states, and good banking application UX transparently reflects this operational reality to the end user.<\/li>\n<\/ul>\n<h2> <a name=\"disadvantages\" href=\"#disadvantages\"> <\/a> Dis-Advantages <\/h2>\n<ul>\n<li>Increase system complexity due to distributed transaction handling and compensating operations.<\/li>\n<li>Consider how communication happens when there is no &#8220;conductor&#8221; or central manager directing the traffic between microservices<\/li>\n<\/ul>\n<h2> <a name=\"notes-\" href=\"#notes-\"> <\/a> Notes : <\/h2>\n<ul>\n<li>2PC &#8211;&gt; two phase commit<\/li>\n<\/ul>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F29nd7zu83udev5r3v7g7.png\"><\/a><\/p>\n<h2> <a name=\"questions\" href=\"#questions\"> <\/a> Questions <\/h2>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgxznmsd7xwxvakzq07ua.png\"><\/a><\/p>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fshn723wrmt84lfmsqb01.png\"><\/a><\/p>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmf17skl7o1x6qgg85bbr.png\"><\/a><\/p>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs1ng4s47a4yqwvag6buv.png\"><\/a><\/p>\n<p><a href=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F66sodjthjdi2srjm1zy7.png\"><\/a><\/p>\n<\/p><\/div>\n<\/article>\n<p> <!-- Bottom content skipped via SKIP_BOTTOM_CONTENT config --> <\/div>\n<p> <\/main> <\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Fuente: <a href=\"https:\/\/dev.to\/technonotes\/day-3-saga-design-pattern-59lh\">Art\u00edculo original<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To manage distributed transactions across multiple microservices. It divides a large transaction into a series of smaller local transactions. Executed independently. Each service performs its own transaction via events or commands. If one transaction fails &#8211;&gt; compensating actions are executed to undo previously completed operations. Distributed Transaction Multiple db or system working together to complete [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5464,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"webixso_pending_account_ids":""},"categories":[41],"tags":[],"class_list":["post-5465","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devto"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/5465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/comments?post=5465"}],"version-history":[{"count":0,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/5465\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/media\/5464"}],"wp:attachment":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/media?parent=5465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/categories?post=5465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/tags?post=5465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}