Enhancing Saga Pattern for Distributed Transactions within a Microservices Architecture
Abstract
:1. Introduction
2. Literature Review
2.1. Distributed Transactions in Microservices
2.1.1. Two Phases Commit Protocol
2.1.2. Saga Pattern
3. Proposed Approach: Design and Components
3.1. Workflow of a Standard E-Commerce Application
3.2. Components of the Proposed Approach
3.2.1. Microservices
3.2.2. Message Queue Middleware
3.2.3. Quota Cache
3.2.4. Eventual Commit Sync Service
3.2.5. Orchestrator Module
3.2.6. Main Database
4. System Implementation
- With the orchestration-based saga, the manager controller manages all the communications among the microservices. As shown in Figure 3, in our proposal, the orchestrator module is responsible for telling the corresponding microservice what transactions have to be executed. Thus, the order of the workflow could easily be managed without changing any microservices. When the orchestration module captures a “buy-event”, it tells the Warehouse-Service to start fetching goods. Additionally, the orchestration handles both the failure and the completion events via the message queue middleware where each event happens in an asynchronous manner. When all transactions are completed successfully, the orchestration publishes a “complete-event” to the message queue middleware which enables the Warehouse-Service and the Billing-Service to consume it and perform database commit.
- The choreography service applies a decentralized approach to service composition. In our proposal, via the choreography-based saga, after a microservice finishes its local transaction, it will publish domain events that will be subscribed by the other microservices to trigger their local transactions.
4.1. Version 1: A System with the Standard Baseline Standard Saga Pattern
4.2. Version 2: A System Implemented the Proposed Approach (Enhanced Saga Pattern)
5. System Validation and Performance Evaluation
5.1. System Validation
5.1.1. Monitoring Tools
5.1.2. Experiment Results
- Experiment 1: Testing the Baseline Standard System (version 1: Utilizing the standard saga pattern) with Scenario 1
- 2.
- Experiment 1: Testing the improved System (version 2: Utilizing the enhanced saga pattern) with Scenario 1
- 3.
- Experiment 2: Testing the Baseline Standard System (version 1: Deploying standard saga pattern) with Scenario 2
- 4.
- Experiment 2: Testing the improved System (version 2: Deploying the enhanced saga pattern) with Scenario 2
6. System Evaluation
- VUs: The number of the virtual users (VUs) to run the specified script concurrently;
- Iterations: The fixed number of iterations that specify the script, usually works together with VUs;
- Duration: The string which specifies the total duration time to run the testing script.
Performance Analysis
- Throughput: Number of requests that are handled in a specified duration
- Throughput Results: 1 min duration
- Throughput Results: 3 min duration
- 2.
- Response-time “Consumed time in a scenario with failure events”
- 10% error rate in 1000 requests (900 successful orders);
- 9% Warehouse-Service fetch goods occur error;
- 1% Billing-Service payment failed.
- 40% error rate in 1000 requests (600 successful orders);
- 36% Warehouse-Service fetch goods occur error;
- 4% Billing-Service payment failed.
- 70% error rate in 1000 requests (300 successful orders);
- 63% Warehouse-Service fetch goods occur error;
- 17% Billing-Service payment failed.
7. Conclusions and Future Work
Supplementary Materials
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Bucchiarone, A.; Dragoni, N.; Dustdar, S.; Lago, P.; Mazzara, M.; Rivera, V.; Sadovykh, A. Microservices: Science and Engineering; Springer International Publishing: Cham, Switzerland, 2019; ISBN 978-3-030-31646-4. [Google Scholar]
- Hasselbring, W.; Steinacker, G. Microservice Architectures for Scalability, Agility and Reliability in E-Commerce. In Proceedings of the 2017 IEEE International Conference on Software Architecture Workshops (ICSAW), Paris, France, 21–25 May 2017; IEEE: Gothenburg, Sweden, 2017; pp. 243–246. [Google Scholar]
- Štefanko, M.; Chaloupka, O.; Rossi, B. The Saga Pattern in a Reactive Microservices Environment. In Proceedings of the 14th International Conference on Software Technologies, Prague, Czech Republic, 26–28 July 2019; SCITEPRESS-Science and Technology Publications: Prague, Czech Republic, 2019; pp. 483–490. [Google Scholar]
- Ahluwalia, K.S.; Jain, A. High availability design patterns. In Proceedings of the 2006 conference on Pattern Languages of Programs—PLoP ’06, Portland, OR, USA, 21–23 October 2006; ACM Press: Portland, OR, USA, 2006; p. 1. [Google Scholar]
- Richardson, C. Microservices Patterns: With Examples in Java; Manning Publications: Shelter Island, NY, USA, 2019; ISBN 978-1-61729-454-9. [Google Scholar]
- Messina, A.; Rizzo, R.; Storniolo, P.; Tripiciano, M.; Urso, A. The Database-is-the-Service Pattern for Microservice Architectures. In Information Technology in Bio- and Medical Informatics; Renda, M.E., Bursa, M., Holzinger, A., Khuri, S., Eds.; Lecture Notes in Computer Science; Springer International Publishing: Cham, Switzerland, 2016; Volume 9832, pp. 223–233. ISBN 978-3-319-43948-8. [Google Scholar]
- Uyanik, H.; Ovatman, T. Enhancing Two Phase-Commit Protocol for Replicated State Machines. In Proceedings of the 2020 28th Euromicro International Conference on Parallel, Distributed and Network-Based Processing (PDP), Västerås, Sweden, 11–13 March 2020; IEEE: Västerås, Sweden, 2020; pp. 118–121. [Google Scholar]
- Mohan, C.; Lindsay, B.; Obermarck, R. Transaction management in the R* distributed database management system. ACM Trans. Database Syst. 1986, 11, 378–396. [Google Scholar] [CrossRef]
- Thomson, A.; Diamond, T.; Weng, S.-C.; Ren, K.; Shao, P.; Abadi, D.J. Calvin: Fast distributed transactions for partitioned database systems. In Proceedings of the 2012 International Conference on Management of Data—SIGMOD ’12, Scottsdale AL, USA, 20–24 May 2012; ACM Press: Scottsdale, AL, USA, 2012; p. 1. [Google Scholar]
- Garcia-Molina, H.; Salem, K. Sagas. In Proceedings of the 1987 ACM SIGMOD International Conference on Management of Data—SIGMOD ’87, San Francisco, CA, USA, 27–29 May 1987; ACM Press: San Francisco, CA, USA, 1987; pp. 249–259. [Google Scholar]
- Campbell, R.H.; Richards, P.G. SAGA: A system to automate the management of software production. In Proceedings of the May 4–7, 1981, National Computer Conference on—AFIPS ’81, Chicago, IL, USA, 4–7 May 1981; ACM Press: Chicago, IL, USA, 1981; p. 231. [Google Scholar]
- Luckow, A.; Lacinski, L.; Jha, S. SAGA BigJob: An Extensible and Interoperable Pilot-Job Abstraction for Distributed Applications and Systems. In Proceedings of the 2010 10th IEEE/ACM International Conference on Cluster, Cloud and Grid Computing, Melbourne, Australia, 17–20 May 2010; IEEE: Washington, DC, USA, 2010; pp. 135–144. [Google Scholar]
- Limόn, X.; Guerra-Hernández, A.; Sánchez-García, Á.J.; Arriaga, J.C.P. SagaMAS: A Software Framework for Distributed Transactions in the Microservice Architecture. In Proceedings of the 2018 6th International Conference in Software Engineering Research and Innovation (CONISOFT), San Luis Potosí, Mexico, 24–26 October 2018; pp. 50–58. [Google Scholar]
- Petrasch, R. Model-based engineering for microservice architectures using Enterprise Integration Patterns for inter-service communication. In Proceedings of the 2017 14th International Joint Conference on Computer Science and Software Engineering (JCSSE), Nakhon Si Thammarat, Thailand, 12–14 July 2017; IEEE: Nakhon Si Thammarat, Thailand, 2017; pp. 1–4. [Google Scholar]
- Shopping Process. Available online: https://www.books.com.tw/web/sys_qalist/qa_1_2/0?loc=000_002 (accessed on 10 May 2022).
- Martin, R.C.; Martin, R.C. Clean Architecture: A Craftsman’s Guide to Software Structure and Design; Robert C. Martin series; Prentice Hall: London, UK, 2018; ISBN 978-0-13-449416-6. [Google Scholar]
- Walls, C. Spring Boot in Action; Manning Publications: Shelter Island, NY, USA, 2016; ISBN 978-1-61729-254-5. [Google Scholar]
- Mass, M. REST API Design Rulebook; O’Reilly: Sebastopol, CA, USA, 2012; ISBN 978-1-4493-1790-4. [Google Scholar]
- Rodríguez, C.; Báez, M.; Daniel, F.; Casati, F.; Trabucco, J.C.; Canali, L.; Percannella, G. REST APIs: A Large-Scale Analysis of Compliance with Principles and Best Practices. In Proceedings of the ICWE, Lugano, Switzerland, 6–9 June 2016. [Google Scholar]
- Kreps, J. Kafka: A Distributed Messaging System for Log Processing; ACM Pres: Athens, Greece, 2011. [Google Scholar]
- Narkhede, N.; Shapira, G.; Palino, T. Kafka: The Definitive Guide: Real-Time Data and Stream Processing at Scale, 1st ed.; O’Reilly Media: Sebastopol, CA, USA, 2017; ISBN 978-1-4919-3616-0. [Google Scholar]
- Redis. Available online: https://redis.io/ (accessed on 11 April 2022).
- Nurkiewicz, T.; Christensen, B. Reactive Programming with RxJava: Creating Asynchronous, Event-Based Applications, 1st ed.; O’Reilly Media, Inc.: Sebastopol, CA, USA, 2016; ISBN 978-1-4919-3165-3. [Google Scholar]
- Douglas, K.; Douglas, S. PostgreSQL: A Comprehensive Guide to Building, Programming, and Administering PostgresSQL Databases, 1st ed.; Developer’s Library; Sams: Indianapolis, IN, USA, 2003; ISBN 978-0-7357-1257-7. [Google Scholar]
- PostgreSQL on Linux. In DBAs Guide to Databases Under Linux; Elsevier: Frisco, CO, USA, 2000; pp. 359–418. ISBN 978-1-928994-04-6.
- Bailis, P.; Ghodsi, A. Eventual consistency today: Limitations, extensions, and beyond. Commun. ACM 2013, 56, 55–63. [Google Scholar] [CrossRef]
- Logstash-Logback-Encoder. Available online: https://portal.bu.edu.sa/en/web/science-college/-17 (accessed on 11 April 2022).
- Loki. Available online: https://github.com/grafana/loki (accessed on 11 April 2022).
- Grafana. Available online: https://github.com/grafana/grafana (accessed on 11 April 2022).
- Promtail. Available online: https://grafana.com/docs/loki/v2.1.0/clients/promtail/ (accessed on 11 April 2022).
- K6. Available online: https://github.com/grafana/k6 (accessed on 11 April 2022).
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |
© 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Daraghmi, E.; Zhang, C.-P.; Yuan, S.-M. Enhancing Saga Pattern for Distributed Transactions within a Microservices Architecture. Appl. Sci. 2022, 12, 6242. https://doi.org/10.3390/app12126242
Daraghmi E, Zhang C-P, Yuan S-M. Enhancing Saga Pattern for Distributed Transactions within a Microservices Architecture. Applied Sciences. 2022; 12(12):6242. https://doi.org/10.3390/app12126242
Chicago/Turabian StyleDaraghmi, Eman, Cheng-Pu Zhang, and Shyan-Ming Yuan. 2022. "Enhancing Saga Pattern for Distributed Transactions within a Microservices Architecture" Applied Sciences 12, no. 12: 6242. https://doi.org/10.3390/app12126242
APA StyleDaraghmi, E., Zhang, C.-P., & Yuan, S.-M. (2022). Enhancing Saga Pattern for Distributed Transactions within a Microservices Architecture. Applied Sciences, 12(12), 6242. https://doi.org/10.3390/app12126242