in-solana by Supanode

Solana gRPC vs WebSocket vs RPC — Which to Use

Solana offers three main approaches for consuming on-chain data: RPC polling, WebSocket subscriptions, and gRPC (Yellowstone) streaming. Each has different latency, reliability, and complexity characteristics.

Disclosure: This site is affiliated with Supanode. Supanode links on this page are marked. All technical comparisons are based on public documentation and protocol specifications.

Comparison overview

FeatureRPC pollingWebSocketgRPC (Yellowstone)
LatencyHighest (~400ms+)Medium (~200ms)Lowest (~50ms)
Delivery modelRequest/responsePush (subscribe)Push (stream)
Missed eventsPossible between pollsPossible on disconnectBackfill possible
FilteringPer-request paramsSubscription filtersServer-side filters
ThroughputLimited by rate limitsConnection-limitedHigh throughput
ComplexityLowestMediumHighest
CostPer-requestIncluded in planUsually separate pricing

When to use each

RPC polling

Best for: simple queries, infrequent reads, prototyping.

// Poll account balance every 5 seconds
setInterval(async () => {
  const balance = await connection.getBalance(pubkey);
  console.log("Balance:", balance);
}, 5000);

Drawbacks: wastes requests on unchanged data, latency is poll interval + request time, misses events between polls.

WebSocket subscriptions

Best for: real-time account updates, transaction notifications, moderate-throughput applications.

connection.onAccountChange(pubkey, (accountInfo) => {
  console.log("Account changed:", accountInfo.data);
});

connection.onLogs(programId, (logs) => {
  console.log("Program log:", logs);
});

Drawbacks: connections drop under load, no guaranteed delivery, reconnection loses events, limited filtering server-side.

gRPC (Yellowstone)

Best for: high-throughput indexing, trading bots, real-time analytics, any workload that cannot afford missed updates.

// Yellowstone gRPC subscription
const stream = client.subscribe();
stream.write({
  accounts: {
    tokenAccounts: {
      owner: ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"],
      filters: [{ datasize: 165 }],
    },
  },
});

Advantages: server-side filtering reduces bandwidth, supports backfill on reconnect, handles high-volume streams efficiently.

Decision flowchart

Need real-time data? 
  No → RPC polling
  Yes → Can afford missed events?
    Yes → WebSocket
    No → Need high throughput (>100 updates/sec)?
      No → WebSocket with reconnection logic
      Yes → gRPC (Yellowstone)

FAQ

Is gRPC always better than WebSocket? Not always. gRPC adds infrastructure complexity and cost. For applications that monitor a few accounts and can tolerate occasional missed events, WebSocket is simpler and cheaper.

Can I use WebSocket and gRPC together? Yes. A common pattern uses gRPC for critical data streams (order monitoring, liquidation detection) and WebSocket for lower-priority notifications. RPC polling serves as a fallback for both.

What is Yellowstone? Yellowstone is the Geyser plugin framework that exposes Solana validator data via gRPC. It streams account updates, transactions, slots, and blocks directly from the validator without going through the RPC layer.

Updated: