vendredi 9 juillet 2021

How does Two Phase Commit really work at low level?

There are tons of articles on 2 phase commit on the internet. They are all saying the same thing and I am not getting it. I need a low-level understanding of it.

The orders and Payment service example is the most popular example on the internet.

Let's say we have Orders service and Payments service. When an order is placed, the Order service writes it to its database but the payment service must also write it to its own database in order for the transaction to be complete.

Here is my inadequate understanding:

  1. User sends a place order request to Orchestrator

  2. Orchestrator invokes Orders service to as well as Payment service at the same time. Now according to what I have read, Order and Payment services are supposed to respond to Orchestrator by telling it whether or not they are ready. What does that mean? What does it mean to be ready here?

  3. Order and Payment service respond back, telling Orchestrator that they are "ready" (whatever that means).

  4. Orchestrator sends another request to both the services (commit request).

  5. Order writes the record to its database. The Payment service writes the record to its own database. They both respond back with status 200 to Orchestrator.

  6. Orchestrator checks if both of the participants have returned status code 200. If yes, then it does nothing. If no then it asks them to ABORT?? How? One of the participants already wrote the transaction to its database.

Aucun commentaire:

Enregistrer un commentaire