Question
· May 21

Customizing retry frequency of transaction

I want to customized retry frequency of transaction so that 503 error can be prevented while pushing FHIR bundle to the LFS.

How do I achieve this?

Reference the following algorithm to increase the retry interval of IRIS transaction

An exponential backoff algorithm retries requests exponentially, increasing the waiting time between retries up to a maximum backoff time. The following algorithm implements truncated exponential backoff with jitter:

  1. Send a request to the Cloud Healthcare API.
  2. If the request fails, wait 1 + random-fraction seconds, then retry the request.
  3. If the request fails, wait 2 + random-fraction seconds, then retry the request.
  4. If the request fails, wait 4 + random-fraction seconds, then retry the request.
  5. Continue this pattern, waiting 2n + random-fraction seconds after each retry, up to a maximum-backoff time.
  6. After deadline seconds, stop retrying the request.

Use the following values as you implement the algorithm:

  • Before each retry, the wait time is min((2n + random-fraction), maximum-backoff), with n starting at 0 and incremented by 1 for each retry.
  • Replace random-fraction with a random fractional value less than or equal to 1. Use a different value for each retry. Adding this random value prevents clients from becoming synchronized and sending many retries at the same time.
  • Replace maximum-backoff with the maximum amount of time, in seconds, to wait between retries. Typical values are 32 or 64 (25 or 26) seconds. Choose the value that works best for your use case.
  • Replace deadline with the maximum number of seconds to keep sending retries. Choose a value that reflects your use case.

The client can retry after reaching the maximum-backoff time using the same value as the backoff. For example, if the maximum-backoff time is 64 seconds, retry every 64 seconds. Ensure that the client doesn't retry indefinitely.

Discussion (2)2
Log in or sign up to continue

If I were to write this in an operation using the EnsLib.HTTP.OutboundAdapter, my approach would be something similar to:


	Set tSC = ..Adapter.SendFormData(.webresponse,"GET",webrequest)

	//begin backoff algorithm
	
	//Get start time in seconds
	Set startInSeconds = $ZDTH($H,-2)
	
	//Set initial params for algorithm
	Set wait = 1, maximumBackoff=64, deadline=300
	
	//Only run while Status Code is 504
	While (webresponse.StatusCode = "504"){
		
		//HANG for x.xx seconds
		HANG wait_"."_$RANDOM(9)_$RANDOM(9)
		
		//Call endpoint
		Set tSC = ..Adapter.SendFormData(.webresponse,"GET",webrequest)
		
		//Increment potential wait periods
		If wait < maximumBackoff Set wait = wait*2

		//Adjust wait if previous action takes us above the maximum backoff
		If wait > maximumBackoff Set wait = maximumBackoff
		
		//Check if deadline has been hit, exiting the While loop if we have
		Set currentTimeInSeconds = $ZDTH($H,-2)
		If (currentTimeInSeconds-startInSeconds>=deadline){Quit}
	}

This is untested however, so massive pinch of salt is required 😅