TC/C and Saga are both application-level distributed transactions. Table 5 summarizes their similarities and differences.
TC/C Saga
Compensating action In Cancel phase In rollback phase
Central coordination Yes Yes (orchestration mode)
Operation execution order any linear
Parallel execution possibility Yes No (linear execution)
Could see the partial inconsistent status Yes Yes
Application or database logic Application Application
Table 5 TC/C vs Saga
Which one should we use in practice? The answer depends on the latency requirement. As Table 5 shows, operations in Saga have to be executed in linear order, but it is possible to execute them in parallel in TC/C. So the decision depends on a few factors:
If there is no latency requirement, or there are very few services, such as our money transfer example, we can choose either of them. If we want to go with the trend in microservice architecture, choose Saga.
If the system is latency-sensitive and contains many services/operations, TC/C might be a better option.
Candidate: To make the balance transfer transactional, we replace Redis with a relational database, and use TC/C or Saga to implement distributed transactions.
Interviewer: Great work! The distributed transaction solution works, but there might be cases where it doesn’t work well. For example, users might enter the wrong operations at the application level. In this case, the money we specified might be incorrect. We need a way to trace back the root cause of the issue and audit all account operations. How can we do this?