feat(ha): High Availability RelayMiner - Horizontally Scalable Architecture #1873
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 High Availability RelayMiner
A complete rewrite of the RelayMiner architecture enabling horizontal scalability for enterprise-grade deployments. Run multiple relayer and miner instances behind a load balancer with Redis-based coordination.
🎯 Why This Matters
The current RelayMiner is a single-process monolith that limits scalability. This HA architecture separates concerns and enables:
📊 Architecture Overview
flowchart TB subgraph Gateways["Gateway Layer"] G1[Gateway 1] G2[Gateway 2] G3[Gateway N] end subgraph LB["Load Balancer"] HAProxy[HAProxy / Nginx / K8s Ingress] end subgraph Relayers["Relayer Instances (Stateless)"] R1[HA Relayer 1] R2[HA Relayer 2] R3[HA Relayer N] end subgraph Redis["Redis Cluster"] RS[(Redis Streams)] RL[(Leader Election)] RD[(Deduplication)] RC[(Session Cache)] end subgraph Miners["Miner Instances (Stateful)"] M1[HA Miner 1<br/>Leader] M2[HA Miner 2<br/>Standby] M3[HA Miner N<br/>Standby] end subgraph Chain["Pocket Network"] PN[Full Node / RPC] end G1 & G2 & G3 --> HAProxy HAProxy --> R1 & R2 & R3 R1 & R2 & R3 --> RS R1 & R2 & R3 -.-> PN RS --> M1 & M2 & M3 M1 & M2 & M3 --> RL M1 & M2 & M3 --> RD M1 & M2 & M3 --> RC M1 -.->|Claims & Proofs| PN🔄 Request Flow
sequenceDiagram participant G as Gateway participant R as HA Relayer participant B as Backend Service participant Redis as Redis Streams participant M as HA Miner (Leader) participant Chain as Pocket Network G->>R: RelayRequest (signed) R->>R: Validate session & signature R->>B: Forward request B-->>R: Response R->>R: Sign response + check mining difficulty R-->>G: RelayResponse (signed) alt Relay meets difficulty R->>Redis: Publish mined relay Redis->>M: Consume from stream M->>M: Deduplicate + Add to SMST M->>M: Update WAL end Note over M,Chain: At session end... M->>Chain: Submit Claim (leader only) Note over M,Chain: After claim window... M->>Chain: Submit Proof (leader only)🏗️ Component Details
HA Relayer (Stateless)
HA Miner (Stateful with HA)
⚙️ Configuration Examples
Relayer Configuration (
relayer-config.yaml)Miner Configuration (
miner-config.yaml)Supplier Keys File (
supplier-keys.yaml)📈 Metrics
Relayer Metrics (
:9090/metrics)ha_relayer_relays_received_totalha_relayer_relays_served_totalha_relayer_relays_rejected_totalha_relayer_relays_published_totalha_relayer_relay_latency_secondsha_relayer_backend_latency_secondsha_relayer_validation_latency_secondsha_relayer_websocket_connections_activeha_relayer_grpc_streams_activeha_relayer_current_block_heightMiner Metrics (
:9091/metrics)ha_miner_relays_consumed_totalha_miner_relays_processed_totalha_miner_relays_deduplicated_totalha_miner_sessions_by_stateha_miner_session_relay_countha_miner_session_compute_unitsha_miner_claims_submitted_totalha_miner_proofs_submitted_totalha_miner_leader_statusha_miner_wal_size_entries🧪 Testing
Tested with 150 parallel relay requests:
*gRPC failures were test script timeouts, not relay failures
Running Tests
🚀 Deployment
Kubernetes (Recommended)
Docker Compose
📋 What's Included
pkg/ha/relayer/- Stateless relay proxy (HTTP, WebSocket, gRPC)pkg/ha/miner/- Stateful miner with leader electionpkg/ha/transport/redis/- Redis Streams transport layerpkg/ha/cache/- Session, supplier, and params cachingpkg/ha/keys/- Multi-source key managementpkg/ha/observability/- Prometheus metricspkg/ha/cmd/- CLI commandstools/scripts/ha_relayer_miner/- Test scriptslocalnet/kubernetes/- K8s deployment manifests🤝 Help Us Test!
We're looking for community members to help test this in various environments:
How to Contribute
Note: This is a DRAFT PR for community feedback and testing. Not yet ready for production merge.