in the course’s code that shows the sage pattern using typescript - the compensation is added BEFORE the activity is done, while in this example the compensation is added AFTER the activity is done.
does it matter if it’s before or after? what’s the correct way?
If an activity guarantees that it never returns failure after updating the service state then you can register the compensation after it call. It usually happens when the activity is retried indefinitely on intermittent failures like timeouts. If retries are limited then there is possibility that activity changes the sate and then fails due to some error. In this case you want to register compensations before calling it. In the latter case make sure that compensation doesn’t fail if the activity never executed.