diff --git a/2pc.html b/2pc.html index 8767cde..3143f2f 100644 --- a/2pc.html +++ b/2pc.html @@ -8,7 +8,7 @@ - + @@ -170,7 +170,7 @@ @@ -256,41 +256,10 @@

Transaction branch operation - - - Do nothing: reservations were already made - External API - Send a message or call and endpoint of another service - - - Do nothing: the guarantee charge was already made - Internal service - Send a message to another service - - - Update customer details in the internal database - Database - Perform the row update and unlock - - - Update the “recent bookings” cache and release the semaphore - In-memory resource - Edit and unlock an in-memory resource - - - Do nothing: the reminder notifications were already scheduled - Actor cluster - Send a command to an actor - - - Do nothing: the bookings log was already updated - File - Persist a change in a file - - -
Consistency
-

It’s up to the implementer to decide the level of consistency in the execution of the commit. Transaction failure is also a valid state and can be signaled by raising an exception in the target effect. This will lead to some degree of inconsistency in the overall system state, but that can be an acceptable compromise in some use cases.

-

For instance, in our imaginary example the “in-memory cache” could be locked only for a short time to preserve throughput. Because it’s not essential to the journey process, updating it could be skipped in case of delays. On the other hand, if the “internal database” update would still fail despite the lock, this could be signaled by raising an exception. This would conclude the transaction in a failed state, which could be surfaced in the UI to allow for manual remediation.

+ +

| Do nothing: reservations were already made | External API | - | | Do nothing: the guarantee charge was already made | Internal service | - | | Update customer details in the internal database | Database | Perform the row update and unlock | | Update the “recent bookings” cache and release the semaphore | In-memory resource | Edit and unlock an in-memory resource | | Do nothing: the reminder notifications were already scheduled | Actor cluster | - | | Do nothing: the bookings log was already updated | File | - |

Commit consistency
+

It’s up to the implementer to decide the level of consistency in the execution of the commit. Transaction failure is also valid and can be signaled by raising an exception in the target effect. Failure will lead to inconsistency in the overall system state, which can be an acceptable compromise in some use cases.

+

For instance, in our imaginary example, the “in-memory cache” could be locked only briefly to preserve throughput. Because it’s optional to the journey process, updating it could be skipped in case of delays. On the other hand, if the “internal database” update still fails despite the lock, the commit expression could signal this by raising an exception. The exception would conclude the transaction in a failed state, allowing surfacing in the UI for manual remediation.

Abort

This is triggered by the coordinator after at least one branch has voted for abort. The branch is expected to effect the local context to roll back the changes and return a confirmation value. The same flexibility as for prepare and commit applies here.

Some examples of abort operations in the same imaginary process:

@@ -334,10 +303,10 @@

Roll back the change in a file - -

The same flexibility applies here as for the commit operation: it’s up to the implementer to decide the level of consistency in the execution of the abort. In this dummy example, let’s suppose traveler reminders have already been sent, a compensation action could be to schedule a new notification inviting the customer to ignore previous messages. On the other hand, failing to cancel the hotel and flight reservations would be a more serious issue and should be surfaced as a failed transaction, to elicit manual remediation.

+
Abort consistency
+

The same flexibility applies here as for the commit operation: it’s up to the implementer to decide the level of consistency in the execution of the abort. In this dummy example, let’s suppose traveler reminders have already been sent: a compensation action could be to schedule a new notification inviting the customer to ignore previous messages. On the other hand, failing to cancel the hotel and flight reservations would be a more serious issue and should be considered a failed transaction to elicit manual remediation.

State diagram

-

Protocol state throughout the aforementioned phases is tracked by an event-sourced entity, with events representing transitions of the state. The transaction state machine diagram is depicted below. As usual, side-effects are invoked after successful event persistence, and repeated in case of recovery (at least once delivery characteristics).

+

Protocol state throughout the phases mentioned above is tracked by an event-sourced entity, with events representing state transitions. The transaction state machine diagram is depicted below. As usual, side-effects are invoked after successful event persistence and repeated in case of recovery (at least once delivery characteristics).

Consider the use case carefully

Certain use cases call for different techniques: for instance, the classical challenge of publishing events to a broker atomically with a change in a database is best solved by the simpler transaction outbox pattern or event sourcing.

2PC is often used in distributed technologies
@@ -396,7 +365,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme @@ -231,7 +231,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme
- + Edit this page
@@ -264,7 +264,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme @@ -242,7 +242,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme
- + Edit this page
@@ -367,7 +372,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme @@ -228,7 +228,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme @@ -211,7 +211,7 @@ Powered by Paradox and -Paradox Material Theme +Paradox Material Theme @@ -227,7 +228,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme @@ -215,7 +215,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme @@ -274,7 +274,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme @@ -241,7 +241,7 @@

Paradox and -Paradox Material Theme +Paradox Material Theme