# Enhancing Saga Pattern for Distributed Transactions within a Microservices Architecture
## 5 System Validation and Performance Evaluation
### System Validation
#### 5.1.2 Experiment Results  
Two scenarios were designed for validating the systems, one with no exception occurring and the other with an exception occurring during the payment. 1. **Experiment 1: Testing the Baseline Standard System (version 1: Utilizing the standard saga pattern) with Scenario 1** Once the orchestrator module captures a \"buy-event\", the event workflow will be tackled by the corresponding microservices. The Warehouse-Service starts to fetch the specified number of goods at the first step, as shown in Figure 7. As shown in the \"logger_name\" field, this operation was handled in the main database. After that, the Order-Service initializes the order. The payment validation then will be handled via the Billing-Service. In the case of validation failure, the workflow will be terminated and the order will be marked as \"FAILED\". Since this scenario represents the case with zero error, the validation will be completed successfully. In the third step, the Billing-Service collects the specified payment (Figure 7 shows the steps performed from 1 to 4). The Shipping-Service then dispatches the delivery based on the customer's request. Figure 8 shows that the customer selects \"boat\" as a delivery means. In the last step, the Order-Service completes the order and updates the required information, including the order status, the shipping id, the amount, and the order status. Figure 8: Steps 5, 6 in version 1 (deploying standard saga pattern). Figure 7: Steps 1–4 in version 1 (deploying standard saga pattern). Experiment 1: Testing the improved System (version 2: Utilizing the enhanced saga pattern) with Scenario 1  
**Step 1 and Step 2** performed by version 2 are almost the same as version 1 as only the Warehouse-Service and the Billing-Service apply the proposed approach. Note that as shown in (Figure 9), data access was handled by Redis, the memory cache server, instead of the main database. In other words, no transactions on the main database are needed at these steps. **Step 3** is shown in Figure 9, where validating the payment is transferred from the main database to the memory cache server. **Step 4:** After the validation is completed successfully, the Billing-Service collects the payment and updates the specified fields at the memory cache serve. **Steps 5 and 6** are the same as version 1 except that the orchestrator module publishes the completion event to the corresponding message queue middleware. Once the Warehouse-Service and Billing-Service consume the \"completion-event\" message, they will perform the specified transaction to the main database, respectively. The update operation has already moved to the memory cache server in both the Warehouse-Service and the Billing-Service. It will perform the relevant transactions to the main database as long as they get the completion event message. 3. **Experiment 2: Testing the Baseline Standard System (version 1: Deploying standard saga pattern) with Scenario 2**  
The event workflow of an e-commerce microservices-based system with a payment exception is shown in Figure 10. This workflow will be deployed to test both versions of the system. Figure 11 shows the steps performed by the standard version that applies the standard saga pattern. The first and the second steps fetch goods and initialize the order. Step 3 shows  
Figure 10: The event workflow of the application with a payment error scenario. that a large amount is given that the customer cannot afford so payment validation failure will occur. As an exception occurs, rollbacks will be executed at step 4, the Warehouse-Service reverts the fetched goods. After rolling back the fetched goods, the Order-Service completes the order and marks it as failed. Experiment 2: Testing the improved System (version 2: Deploying the enhanced saga pattern) with Scenario 2  
Figure 12 shows the steps performed by version 2 that applies the proposed enhanced saga pattern. In the first and second steps, the goods will be fetched and the order will be initialized.