Multi-Region
Slipstream regions are dynamic — they are discovered at runtime from the discovery service. Regions and workers change as infrastructure scales, so the SDK auto-discovers the best connection at connect time.
Discovery Service
The SDK queries https://discovery.allenhark.network/v1/discovery at connect time. This returns:
- Regions — Available regions with display names and current leader RTT
- Workers — Individual workers per region with IP, ports, health status, and version
- Recommended region — The region with lowest leader RTT right now
The discovery endpoint is public and requires no authentication.
How Auto-Discovery Works
- SDK queries the discovery service for available regions and workers
- SDK probes latency to each healthy worker
- SDK connects to the worker with the lowest measured round trip, using the protocol fallback chain
- If the connection drops, SDK automatically reconnects to the next best worker
Querying Regions
Regions — Rust
// Get available regions (no auth required)
let regions = client.get_regions().await?;
for region in ®ions {
println!("{} ({})", region.display_name, region.region_id);
if let Some(geo) = ®ion.geolocation {
println!(" Location: {:.2}, {:.2}", geo.lat, geo.lon);
}
}Regions — TypeScript
const regions = await client.getRegions();
for (const region of regions) {
console.log(`${region.displayName} (${region.regionId})`);
}Regions — Python
regions = await client.get_regions()
for region in regions:
print(f"{region.display_name} ({region.region_id})")Pinning to a Region
You can optionally pin to a specific region by passing its ID in the config. Use the region IDs returned by the discovery service.
let config = Config::builder()
.api_key("sk_live_...")
.region("us-east-2") // Pin to a specific region
.build()?;const config = configBuilder()
.apiKey("sk_live_...")
.region("eu-central")
.build();config = config_builder().api_key("sk_live_...").region("ap-southeast-1").build()Direct Endpoint
To bypass discovery entirely and connect to a specific worker:
let config = Config::builder()
.api_key("sk_live_...")
.endpoint("84.32.34.7") // Direct IP
.build()?;const config = configBuilder()
.apiKey("sk_live_...")
.endpoint("84.32.34.7")
.wsEndpoint("ws://84.32.34.7:9000")
.build();Routing Recommendations
Get real-time routing recommendations based on the current leader.
Routing — Rust
let rec = client.get_routing_recommendation().await?;
println!("Best region: {}", rec.best_region);
println!("Leader: {}", rec.leader_pubkey);
println!("Slot: {}", rec.slot);
println!("Confidence: {}%", rec.confidence);
println!("Expected RTT: {:?}ms", rec.expected_rtt_ms);
println!("Fallback regions: {:?}", rec.fallback_regions);
println!("Fallback strategy: {:?}", rec.fallback_strategy);
println!("Valid for: {}ms", rec.valid_for_ms);Routing — TypeScript
const rec = await client.getRoutingRecommendation();
console.log("Best region:", rec.bestRegion);
console.log("Leader:", rec.leaderPubkey);
console.log("Confidence:", rec.confidence, "%");
console.log("Fallback strategy:", rec.fallbackStrategy);Routing — Python
rec = await client.get_routing_recommendation()
print(f"Best region: {rec.best_region}")
print(f"Leader: {rec.leader_pubkey}")
print(f"Confidence: {rec.confidence}%")
print(f"Fallback strategy: {rec.fallback_strategy}")Fallback Strategies
| Strategy | Description |
|---|---|
sequential | Try regions in order of latency |
broadcast | Fan-out to every discovered region at once |
retry | Retry same region with backoff |
none | No fallback |
Use broadcast_mode: true in SubmitOptions to fan-out a transaction to every discovered region.
Connection Info
Check which region and protocol you're connected to:
Connection — Rust
let info = client.connection_info();
println!("Region: {:?}", info.region);
println!("Protocol: {:?}", info.protocol);
println!("Session: {}", info.session_id);Connection — TypeScript
const info = client.connectionInfo();
console.log("Region:", info.region);
console.log("Protocol:", info.protocol);Latency & Time Sync
The SDK maintains latency measurements and clock synchronization via keep-alive pings.
Latency — Rust
// Median RTT/2 from keep-alive pings
if let Some(latency) = client.latency_ms() {
println!("Latency: {}ms", latency);
}
// Client-server clock offset
if let Some(offset) = client.clock_offset_ms() {
println!("Clock offset: {}ms", offset);
}
// Corrected server time
let server_time = client.server_time();
// Manual ping
let ping = client.ping().await?;
println!("RTT: {}ms, offset: {}ms", ping.rtt_ms, ping.clock_offset_ms);Landing Rates by Region
Track landing rates per region to understand performance.
Landing Rates — Rust
let stats = client.get_landing_rates(None).await?;
println!("Overall: {:.1}% ({}/{})",
stats.landing_rate * 100.0, stats.total_landed, stats.total_sent);
for region in &stats.by_region {
println!(" {}: {:.1}% ({}/{})",
region.region, region.landing_rate * 100.0,
region.total_landed, region.total_sent);
}Landing Rates — TypeScript
const stats = await client.getLandingRates();
console.log(`Overall: ${(stats.landingRate * 100).toFixed(1)}%`);
for (const region of stats.byRegion) {
console.log(` ${region.region}: ${(region.landingRate * 100).toFixed(1)}%`);
}Next Steps
- Configuration — Protocol and timeout settings
- Billing & Tokens — Cross-region billing
- Error Handling — Region failover errors
