Active and passive API callout strategies

Active and passive API callout strategies

API failure management is critical and needs to be designed properly to ensure the API calls are successfully made as well as retried in case of failures. External platforms, frameworks and tools like Mulesoft, Spring Boot have a structured way of doing this. Inspired from Spring boot RestTemplate the following is a reference design for a robust active and passive API callout strategy within APEX.

No alt text provided for this image

Active strategy

This strategy is used when the callout fails for the first time and needs to be tried subsequently and immediately. The code needs to be decomposed as shown above or similarly for better separation of concerns. The actual callout is made via a Queueable inside a Base callout class. The Base class ensure that the code is applied to all callouts within the application.

The following JSON object is defined in a 'Retry metadata'.

{
  
  "allowRetires" : "true",
  "noOfretires"  : "3",
  "exponential-backoff" : "true",
  "retryInterval" : "1"
  "failover" : "RetryBatch"  
}

The Base class reads the above configuration for a specific callout. If the callout fails it will retry the same callout as specified by the above control flags. E.g. If noOfretries = 3, then the callout is retired 3 times with an interval of 1s between them via a recursive function.. If exponential-backoff control is true, then the callout interval follows a quadratic distribution f(x) = x^^2. If the API callout still fails after all retries are exhausted, then the whole request payload is written to a custom object 'CalloutFailureTracker'. Similarly if the queueable that made the original invocation fails for some reason the request payload gets written to the tracker object as part of 'Transaction finalizer'.

Passive strategy

In the passive strategy the callouts are retried via a batch. It is passive since the retry does not happen immediately. The retry batch will read all the failed requests written to the tracker object and then make the callouts. Since it invokes the same Base class the original active strategy gets applied as well.

There are few variables that need to be taken into account to fine tune the values of the metadata. These include

  • 120s limit for the total duration of all callouts within a transaction
  • 100 callout limit within a single transaction
  • DMLs not allowed after a callout
  • 2 queueables cannot be created within a batch


要查看或添加评论,请登录

Kedar Bhumkar的更多文章

  • Part 2 - Training data for LLM fine tuning

    Part 2 - Training data for LLM fine tuning

    In part 1 of this series, a general LLM architecture for APIs and inference overview was presented. In this article, we…

    1 条评论
  • Part 1 - Generalized Architecture for LLM API's in Client Applications

    Part 1 - Generalized Architecture for LLM API's in Client Applications

    The below diagram presents a generalized inference architecture designed for the integration of Language Model (LLM)…

  • Github copilot runs on LWC

    Github copilot runs on LWC

    Recently, I got access to the GitHub copilot Beta program. GitHub copilot is the GPT3 based AI pair programming tool…

    2 条评论
  • Performance tracking using the chrome network tab

    Performance tracking using the chrome network tab

    The Chrome network tab is a powerful arsenal for performance tracking any web application including Salesforce. In this…

  • Leveraging Kafka for ETL operations within Salesforce

    Leveraging Kafka for ETL operations within Salesforce

    Traditional ETL is slowly getting replaced within the enterprise landscape with real time event based ETL. The classic…

    1 条评论
  • Using Platform events to overcome async operation limits

    Using Platform events to overcome async operation limits

    Platform events (PE) are great for what they are designed for; which is event based loose coupling and processing…

    1 条评论
  • Using AWS for ML insights inside Salesforce

    Using AWS for ML insights inside Salesforce

    Salesforce Einstein is a fairly capable predictive analytics tool available for use within Salesforce. However it has…

  • Simulating DB locking errors

    Simulating DB locking errors

    "Unable to lock row" is a peculiar and difficult to simulate error which often occurs when multiple requests try to…

  • Offloading batch processing using Map-reduce

    Offloading batch processing using Map-reduce

    Recently, I was involved in a large scale migration operation on Salesforce. It was done using the Salesforce Batch…

    1 条评论
  • Enhanced field history tracking

    Enhanced field history tracking

    Salesforce has a robust history tracking feature which is used by most projects to track the timeline of changes done…

    2 条评论

社区洞察

其他会员也浏览了