Routing Strategies

Prism's intelligent request routing system with consensus validation, hedging, scoring, and failover.

Table of Contents


Overview

Prism implements a SmartRouter that automatically selects the best routing strategy based on the method and system state:

Request → SmartRouter

           ├─ Critical method? ──────────→ CONSENSUS (3+ upstreams)

           ├─ Scoring enabled? ──────────→ SCORING (best upstream)

           ├─ Hedging enabled? ──────────→ HEDGING (parallel requests)

           └─ Fallback ───────────────────→ LOAD BALANCER (round-robin)

Routing Priority

  1. Consensus (if method requires validation)

  2. Scoring (if enabled)

  3. Hedging (if enabled and scoring disabled)

  4. Load Balancer (fallback)


Consensus Validation

Multi-upstream validation for critical methods requiring data integrity guarantees.

How It Works

  1. Send to multiple upstreams: Request sent to 3+ providers in parallel

  2. Collect responses: Wait for responses (with timeout)

  3. Compare results: Check if responses match

  4. Consensus achieved?

    • YES: Return agreed-upon response

    • NO: Return error or fall back

Configuration

Option
Type
Default
Description

enabled

boolean

false

Enable consensus validation

max_count

integer

3

Maximum upstreams to query simultaneously

min_count

integer

2

Minimum upstreams required for consensus

timeout_seconds

integer

10

Timeout for consensus requests

dispute_behavior

string

"PreferBlockHeadLeader"

How to resolve disputes

methods

array

[eth_getBlockByNumber, ...]

Methods requiring consensus

Use Cases

When to use consensus:

  • Critical data integrity requirements

  • Financial applications (MEV, arbitrage)

  • Cross-chain bridge validation

  • Reorg detection

Trade-offs:

  • Higher latency: 3× upstream calls

  • Higher cost: More upstream API usage

  • Better reliability: Detect data inconsistencies

  • Reorg protection: Identify chain forks early

Example

Request: eth_getBlockByNumber("latest")

Behavior:

  1. Send to alchemy, infura, quicknode in parallel

  2. Receive responses:

    • Alchemy: block 18500000

    • Infura: block 18500000

    • QuickNode: block 18499999 (lagging)

  3. Consensus: 2/3 agree on 18500000

  4. Return: block 18500000

  5. Warning logged about QuickNode lag

Metrics


Hedging for Tail Latency

Parallel request execution to reduce P99 latency.

The Problem: Tail Latency

Scenario: You have 3 upstreams with these latencies:

  • Alchemy: P50=50ms, P95=120ms, P99=800ms

  • Infura: P50=45ms, P95=100ms, P99=600ms

  • QuickNode: P50=55ms, P95=150ms, P99=1200ms

Without hedging: Your P99 = ~800ms (slowest typical response)

With hedging: Your P99 = ~100-150ms (first response wins)

How It Works

  1. Send primary request to best upstream (by score)

  2. Wait initial_timeout_ms (e.g., 50ms)

  3. If no response yet:

    • Send hedge request to next-best upstream

  4. Return first successful response

  5. Cancel other requests

Configuration

Option
Type
Default
Description

enabled

boolean

false

Enable request hedging

latency_quantile

float

0.95

Latency percentile for hedge trigger (0.0-1.0)

min_delay_ms

integer

50

Minimum delay before sending hedge

max_delay_ms

integer

2000

Maximum delay before sending hedge

max_parallel

integer

2

Maximum parallel requests including primary

Example Timeline

Result: 65ms latency instead of waiting for Alchemy's 120ms

Hedging Decision Tree

Use Cases

Good for hedging:

  • High-variance latency (P99 >> P50)

  • Latency-sensitive applications

  • User-facing queries

  • Real-time data needs

Bad for hedging:

  • Cost-sensitive (2× API calls)

  • Low latency variance (P99 ≈ P50)

  • Batch processing

  • Background jobs

Metrics


Scoring Algorithm

Multi-factor upstream ranking for intelligent selection.

Scoring Factors

Each upstream receives a composite score based on:

  1. Latency (weight: 0.4): How fast it responds

  2. Error Rate (weight: 0.3): How often it fails

  3. Throttle Rate (weight: 0.2): How often it rate-limits

  4. Block Lag (weight: 0.1): How far behind chain tip

Configuration

Score Calculation

Factors (all normalized 0-1, higher is better):

Latency Factor:

Error Rate Factor:

Throttle Factor:

Block Lag Factor:

Example

Upstreams:

  • Alchemy: 50ms latency, 1% errors, 0% throttles, block 18500000

  • Infura: 45ms latency, 2% errors, 5% throttles, block 18499998

  • QuickNode: 60ms latency, 0.5% errors, 0% throttles, block 18500000

Scoring (assuming worst_latency=60ms, max_lag=2):

Alchemy:

Infura:

QuickNode:

Result: Alchemy (0.664) > QuickNode (0.599) > Infura (0.584)

Selection: Alchemy chosen for next request

Metrics


Load Balancing

Fallback strategy when advanced routing is disabled.

Round-Robin

Simple round-robin distribution among healthy upstreams.

Weighted Round-Robin

Distribution based on upstream weights.

Result: Primary gets 75% traffic, backup gets 25%

Response-Time Based

Select upstream with best recent response time.


Circuit Breaker

Automatic isolation of failing upstreams.

State Machine

Configuration

Behavior

CLOSED (normal):

  • All requests go through

  • Track consecutive failures

  • If failures ≥ threshold → OPEN

OPEN (isolated):

  • Requests fail immediately with CircuitBreakerOpen error

  • Wait timeout_seconds

  • After timeout → HALF-OPEN

HALF-OPEN (testing):

  • Allow one test request

  • Success → CLOSED (restore upstream)

  • Failure → OPEN (continue isolation)

Metrics


Routing Decision Flow

Complete request routing logic:


Next: Learn about Authentication or Monitoring.

Last updated