You've already used the pattern this lesson names. Tiffin's checkout doesn't take the customer's ₹640 straight away. It authorises the card, which puts a hold on the money. Later it either captures the hold or voids it. Reserve, then confirm or cancel: that's try-confirm-cancel, or TCC.
Sagas commit each step for real and repair afterwards. TCC makes every step a reservation first, and only turns the reservations into real effects once all of them have succeeded. This lesson compares the two, covers the three bugs every TCC implementation has to handle, and then answers a question both patterns share: what happens when the process running the transaction crashes halfway?
The shape
Every participant offers three operations instead of one:
- Try checks the business rules and reserves what's needed: hold 1 portion of the chef's special, hold coupon
DIWALI50, authorise ₹640. The reservation is visible as "held", not "used". - Confirm turns the reservation into the real thing. It only uses what Try reserved, so it can't fail for a business reason like "out of stock". It can only fail temporarily, and is retried until it works.
- Cancel releases the reservation.
A coordinator runs every Try. If all succeed, it confirms all of them. If any Try fails or times out, it cancels all of them.
%% caption: TCC. Nothing becomes real until every participant has reserved what it needs. sequenceDiagram autonumber participant C as Coordinator participant K as Kitchen stock participant P as Promotions participant PA as Payment C->>K: try: hold 1 chef's special C->>P: try: hold DIWALI50 C->>PA: try: authorise 640 K-->>C: held P-->>C: held PA-->>C: authorised Note over C: all held, decide confirm C->>K: confirm C->>P: confirm C->>PA: confirm: capture
TCC splits each step into a reservation (try), and then either making it real (confirm) or releasing it (cancel). The decision is made only after every reservation is in place.
If that sounds like two-phase commit, it is, one level up. Try is prepare, and confirm or cancel is the decision. The difference is what's held while waiting. 2PC holds database locks, and if the coordinator vanishes, participants are stuck holding them. TCC holds business reservations, which other requests can see and which carry an expiry. If the coordinator vanishes, the hold times out and is released, and nothing is stuck forever.