RoundRobinRoutingStrategy

Overview

The RoundRobinRoutingStrategy distributes requests evenly across all available gateways in a cyclical manner. Each gateway is selected in turn, ensuring fair load distribution and preventing any single gateway from being overwhelmed.

How It Works

  1. Initialize Gateway List: Start with an ordered list of available gateways
  2. Track Current Position: Maintain a pointer to the current gateway in the rotation
  3. Select Next Gateway: Choose the next gateway in the sequence
  4. Cycle Through List: Return to the first gateway after reaching the end
  5. Handle Failures: Skip failed gateways and continue rotation

Configuration

Basic Usage

import { RoundRobinRoutingStrategy } from '@ar.io/wayfinder-core'

const strategy = new RoundRobinRoutingStrategy({
  gateways: [new URL('https://arweave.net'), new URL('https://permagate.io')],
})

With Weighted Rotation

const strategy = new RoundRobinRoutingStrategy({
  gateways: [
    new URL('https://high-capacity-gateway.com'),
    new URL('https://medium-capacity-gateway.com'),
    new URL('https://low-capacity-gateway.com'),
  ],
});

// selects the next gateway in the list
const selectedGateway = strategy.selectGateway()

Parameters

ParameterTypeDefaultDescription
gatewaysURL[]requiredArray of gateway URLs to rotate through
loggerLoggerdefaultLoggerOptional logger instance

Was this page helpful?