Skip to main content
Hyrex provides automatic retry mechanisms to handle transient failures and ensure reliable task execution.

Basic Retry Configuration

Configure retries using the maxRetries option:

Default Behavior

  • Default retries: 3 attempts (configurable 0-10)
  • Retry trigger: Any thrown exception
  • Success condition: Task returns without throwing
  • Backoff strategy: Exponential backoff (built-in)

Exponential Backoff

The TypeScript SDK implements exponential backoff automatically:
  • First 5 failures: No delay (offset period)
  • After offset: 1.5s, 3s, 4.5s, 6s… up to 15s max
  • Backoff resets on successful execution

Retry Patterns

Conditional Retries

Control which errors trigger retries:

Return vs Throw

Control retry behavior with return values:

Using Attempt Number

Access the current attempt for custom logic:

Common Retry Scenarios

External API Calls

Database Operations

File Processing

Best Practices

  1. Set Appropriate Retry Limits
  2. Consider Idempotency
  3. Log Retry Attempts
  4. Handle Final Failures

Limitations

  • Max retries: Limited to 10 attempts
  • No custom backoff: Exponential backoff is built-in and not configurable
  • All exceptions retry: Cannot configure which error types retry
  • No retry delay control: Cannot set custom delays between retries

Next Steps

Tasks

Configure tasks with retries

Error Handling

Handle errors in tasks

Queues

Route retryable tasks