I have a scenario where my pega flow makes three REST calls (C1, C2 and C3) sequentially to three different external systems to complete a business transaction. All these are POST operations and makes some changes in their respective systems. If C3 fails, I want changes occurred within C1 and C2 should be rolled back. Is there a standard design approach for this? Please advise.
Since REST is stateless by design, there is no way to roll back a transaction. A possible way is to create certain endpoints/methods designated to validating a request. Let's say that you want to call UploadDocument -- there could be a ValidateUploadDocument. If the latter returns anything else than 200, you just won't call the former.
In your case:
Call C1Validate, C2Validate, and C3Validate
If all calls return status code 200, call C1, C2, and C3.
Naturally, this could require changing your services in the first place. Another potentially less elegant way is to use DELETE for C1 and C2 if C3 fails (if DELETE methods are available).
Thanks mrwolf for the response. It appears C1Validate can validate the request structure and available of C1's end point but still C1 can fail due to other points of failures like it can call other external services. Currently we are doing like DELETE kind of option.