1

We are developing a REST API where client (application) will make call to our REST APIs.

The client (application) will handle the business logic with rollback capabilities (eg. client can rollback if update "Shipment" services [pass] and update "Stock" services [failed]).

There are many online articles about TCC [Try/Confirm/Cancel] which describe reserving/cancelling a resource via POST/DELETE method but none describe how to handle PUT request (eg. update "Stock" count by 1 and rollback on failure).

Anyone know of a solution to handle a PUT rollback (since PUT request overwrite the original data, how can we rollback to the original data)?

Ethan
  • 11
  • 2

2 Answers2

0

TCC is only a concept to implement transactional behaviour using HTTP/REST. It covers a standard how to model the transaction including timeouts and cancellation. In this model the transaction is bound to any kind of resource with an id so you are able to either confirm or cancel it at any point. As the transaction has a timeout you may end up with an invalid or no longer existing transaction.

Whatever you do from start to the end of the transaction is up to you. But you need something to identify a transaction. As an overwrite of a resource using PUT does not create a resource object by itself you would need a kind of virtual resource to do so.

You may create a new version (maybe using locking) of the resource (the entities is just a placeholder here):

  • Start: PUT /entities/42 -> link rel:tcc, href: /entities/42/version/7
  • Confirm: PUT <application/tcc> /entities/42/version/7
  • Cancel: DELETE /entities/42/version/7

Instead of a version you can also think of a kind of transaction id if you have such.

Arne Burmeister
  • 20,046
  • 8
  • 53
  • 94
0

Per TCC pattern, the confirm operation uses PUT for its idempotent characteristics. When implementing such behavior if partial reservation is confirmed while others has expired, we could use the cancel operation to mimic the rollback behavior so that each confirmed participant link will be sent with another DELETE request. I wrote a tutorial article about a minimal TCC implementation with Java in a Booking system. You can refer to the implementation there.

Downhillski
  • 2,555
  • 2
  • 27
  • 39