Skip to main content

Overview

The Retry is a fundamental concept in the Serverless Workflow DSL, used to define the strategy for retrying a failed task when an error is encountered during execution. This policy provides developers with fine-grained control over how and when to retry failed tasks, enabling robust error handling and fault tolerance within workflows.

Retry Policy

when
string
A runtime expression used to determine whether or not to retry running the task, in a given context.
exceptWhen
string
A runtime expression used to determine whether or not to retry running the task, in a given context.
delay
duration
The duration, if any, to wait between retry attempts.
limit
object
The limits, if any, to impose to the retry policy.
backoff
object
The backoff strategy to use, if any.
jitter
object
The parameters, if any, that control the randomness or variability of the delay between retry attempts.

Retry Limit

The definition of retry limits.
attempt.count
integer
The maximum attempts count.
attempt.duration
duration
The duration limit, if any, for all retry attempts.
duration
duration
The maximum duration, if any, during which to retry a given task.

Backoff Strategies

The definition of a retry backoff strategy.
constant
object
The definition of the constant backoff to use, if any.Required if exponential and linear are not set, otherwise ignored.
exponential
object
The definition of the exponential backoff to use, if any.Required if constant and linear are not set, otherwise ignored.
linear
object
The definition of the linear backoff to use, if any.Required if constant and exponential are not set, otherwise ignored.

Jitter

Represents the definition of the parameters that control the randomness or variability of a delay, typically between retry attempts.
from
duration
required
The minimum duration of the jitter range.
to
duration
required
The maximum duration of the jitter range.

Examples

Exponential Backoff with Retry Limit

document:
  dsl: '1.0.3'
  namespace: test
  name: retry-example
  version: '0.1.0'
do:
  - callExternalService:
      try:
        - makeRequest:
            call: http
            with:
              method: get
              endpoint: https://api.example.com/data
      catch:
        errors:
          with:
            type: https://serverlessworkflow.io/spec/1.0.0/errors/communication
        retry:
          delay:
            seconds: 3
          backoff:
            exponential: {}
          limit:
            attempt:
              count: 5

Retry with Jitter

retry:
  delay:
    seconds: 1
  backoff:
    exponential: {}
  jitter:
    from:
      milliseconds: 100
    to:
      milliseconds: 500
  limit:
    attempt:
      count: 3

Linear Backoff

retry:
  delay:
    seconds: 2
  backoff:
    linear: {}
  limit:
    attempt:
      count: 5
    duration:
      minutes: 5

Constant Backoff with Duration Limit

retry:
  delay:
    seconds: 5
  backoff:
    constant: {}
  limit:
    duration:
      minutes: 10

Conditional Retry

retry:
  when: .error.status >= 500
  delay:
    seconds: 2
  backoff:
    exponential: {}
  limit:
    attempt:
      count: 3

Retry with Exception Condition

retry:
  exceptWhen: .error.status == 401
  delay:
    seconds: 1
  backoff:
    exponential: {}
  limit:
    attempt:
      count: 5

Reusable Retry Policies

You can define retry policies in the workflow’s reusable components and reference them by name:
document:
  dsl: '1.0.3'
  namespace: test
  name: reusable-retry-example
  version: '0.1.0'
use:
  retries:
    standardRetry:
      delay:
        seconds: 3
      backoff:
        exponential: {}
      limit:
        attempt:
          count: 5
do:
  - callService:
      try:
        - makeRequest:
            call: http
            with:
              method: get
              endpoint: https://api.example.com/data
      catch:
        errors:
          with:
            type: https://serverlessworkflow.io/spec/1.0.0/errors/communication
        retry: standardRetry

Duration Format

Durations can be defined through properties or with an ISO 8601 string:

Using Properties

delay:
  hours: 2
  minutes: 15
  seconds: 30

Using ISO 8601 String

delay: PT2H15M30S

Duration Properties

days
integer
Number of days, if any.
hours
integer
Number of hours, if any.
minutes
integer
Number of minutes, if any.
seconds
integer
Number of seconds, if any.
milliseconds
integer
Number of milliseconds, if any.

Build docs developers (and LLMs) love