Reputation: 1224
My problem schematically is:
The problem is that service B just responded slowly and service A caught a timeout exception and rolled back the transaction. Service B, however, processed the data (although it did not respond in time). When, the process is considered successful if both service A and service B have saved and processed the data. In this case, due to the rollback of the transaction, the data of service A was not saved.
Is there a general solution to this problem? I look towards 2PC and event-based distributed transactional mechanism (such as saga pattern). Thans for any help/links/etc.
Upvotes: 0
Views: 106
Reputation: 9456
I generally solve this by splitting the call to Service B into a "prepare" and a "commit" phase. This is effectively putting in-place 2PC for a service layer, inserting records in a "Pending" state, and then having a final call to "Activate" the change.
The fact of the matter is, REST over HTTP is not great for transactional consistency. You are much better off with eventual consistency models when you are talking about potential long-running processes. Put a message queue behind Service B, queue the update up, and have Service A poll for completion (or have a call-back).
Upvotes: 1