How are Temporal Activities better than a while loop which retries

I want to understand why I need to use temporal activities instead of writing a retry logic myself as shown below.

image

  • One thing I can think right of the bat is, temporal activities are more cleaner code than the while loop.

But is there anything to temporal activates advantage apart from that?
Let’s not bring in statefullness workflows offer and the advantages it can bring in to the activities. Let’s talk purely in the context of activities.

FYI : I’m conducting a Brown Bag session. First I’m going to show the above code and explain how we can implement retries and make our applications more resilient. Then I’m going to show temporal activities. And I need few points to highlight the advantageous of activities against self written retry logic.

  • Activity retries are driven from the service. So they are retried not only on failures but on crashes or downtimes of the activity worker processes.
  • Activities support cancellation.
  • There is a visibility API/UI to see the current state of an activity retries. It shows how many times it attempted execution, the identity of the process that executed the last attempt, the last failure information, and the next attempt’s time. The arguments of the activity are also shown.
  • Any duration of activity retries is supported. Yes, you can retry for a year if needed.
  • They don’t consume resources (threads and memory) on the worker process while waiting for the next attempt.
  • Activity tasks are delivered through task queues. This way their invocations are flow and rate controlled. The worker doesn’t pick a task from a queue if it doesn’t have the capacity to execute it.
  • Temporal supports global (across multiple workers) rate limit per task queue. It is useful to ensure that calls don’t overload a downstream service an activity calls.
  • Long running activities are supported. Activity heartbeating can be used to save the current progress of activity execution.
  • No need to have an end point and load balancer to invoke activities as their worker calls into the Temporal service. This is good for security as the host that executes activities doesn’t need to listen on any open ports.
  • Activities can be routed to specific hosts and processes. For example, it is possible to ensure that a sequence of activities is executed by the same process.
7 Likes