Skip to content
0%

Webhooks vs WebSockets vs gRPC: which should you use?

Alchemy team headshot

Written by Alchemy

Published on May 19, 20266 min read

Cover graphic comparing webhooks, WebSockets, and gRPC for real-time data delivery

A liquidation bot that polls every 400 milliseconds will always be a little late, a little wasteful, or both. So should you use a webhook, a WebSocket, or gRPC? The answer comes down to who should be watching the chain for you, and how fast you need to know when something changes.

Use a webhook when you want to be told when something happens onchain. Use a WebSocket when a running service needs updates the moment they happen. Use gRPC streaming when you're watching a lot of data, which today mostly means Solana.

What is a webhook?

A webhook is a push notification over plain HTTP. You register a URL once, and we watch the chain and call that URL when a matching event happens: a transaction touching an address, an NFT transfer, or a contract event that matches a filter. No connection to maintain, no reconnect logic, nothing listening around the clock on your side. Your server just needs an endpoint that can accept a POST request.

What is a WebSocket?

A WebSocket is a single two-way connection that your app opens once and keeps open. Instead of asking "did anything happen?" over and over, you subscribe to a topic such as new block headers, pending transactions, or log events for a contract. The provider pushes matching events down that same connection the moment they happen. The tradeoff is that your app now owns that connection: it has to notice when the connection drops, reconnect, and figure out what it missed while it was gone.

What is gRPC streaming?

gRPC streaming looks like a WebSocket in spirit, a persistent connection that pushes data, but every message follows a fixed format (a schema) instead of loose JSON, and the transport is built for much higher throughput. This is the model behind our Solana gRPC streams, which work with Yellowstone, the standard open-source way to stream Solana data. On Solana, blocks come in under a second, and a JSON WebSocket frame for every event would be too much overhead. If you're watching Solana account or transaction activity at volume, this is the option built for it.

Why the delivery model is a decision, not a preference

Each model answers a different question about your app: does it need to run all the time, how much delay can it tolerate, and how much data is it watching? Picking the wrong one shows up later as cost, missed events, or an on-call page at 2am, not as a bug in your code.

Webhooks vs WebSockets vs gRPC, side by side

Webhooks
WebSockets
gRPC streaming
Polling
How it works
The provider calls your endpoint
You keep a connection open
You keep a connection open, with typed messages
You ask on a timer
Best for
Alerts, serverless apps, backend jobs
Always-on services, live dashboards
High-volume Solana streams
Occasional checks
Speed
Slower: one HTTP request per event
Fast
Fast, at high volume
Only as fast as your timer
If you miss something
The provider retries
You backfill after reconnecting
You replay from a recent slot
You query the gap
Security
Check the signature on each request
API key on the connection
API key on the connection
API key on each request

How do you choose?

Use a webhook when you don't want to run a server all the time. Webhooks fit serverless functions, internal alerts, and anything where "call me when X happens" is all you need. You give up a little speed and never have to manage a connection.

Use a WebSocket when you already run a service that's always on and speed matters: trading bots, live dashboards, anything watching pending transactions. You take on reconnect and backfill logic in exchange for faster updates.

Use gRPC streaming when the first two can't keep up, which today mostly means Solana. There's enough activity there that JSON over a WebSocket becomes the bottleneck before the chain does.

How do retries, replay, and backfill work?

If a webhook can't be delivered, we retry it with backoff for up to about ten minutes on Free and Pay As You Go plans, and up to an hour on Enterprise. If your endpoint is down longer than that, query for anything you missed: the Transfers API (alchemy_getAssetTransfers) on Ethereum and supported L2s, or getSignaturesForAddress on Solana. The Transfers API doesn't cover Solana.

A WebSocket connection will drop eventually, and it won't remember what you missed. Keep track of the last block you processed. When you reconnect, fetch anything newer before you trust the live stream again: eth_getLogs or the Transfers API on Ethereum and supported L2s, or getSignaturesForAddress on Solana.

gRPC streaming on Solana can replay recent activity. When you reconnect, ask to resume from the last slot you saw (a slot is Solana's unit of time, about 400 milliseconds) instead of starting over. That window is limited, so a long outage still needs a backfill.

How do you secure each one?

Webhooks are the one option where your endpoint is open to the internet, so check the signature on every request before you trust it. WebSocket and gRPC connections use your API key when they connect, and data only flows while that connection is open.

Where to start

For webhooks, start with Alchemy Webhooks. For WebSockets, start with eth_subscribe. For Solana, start with the Yellowstone gRPC quickstart. You'll need an Alchemy API key with access to Solana gRPC, and the quickstart lists the prerequisites. You can use all three from one Alchemy account and mix them as your app grows.

Ready to start building? Sign up for free, or talk to our team if you're planning for high volume.

Frequently asked questions

What's the difference between webhooks, WebSockets, and gRPC?

A webhook calls your server when something happens. A WebSocket is a connection you keep open so updates arrive as they happen. gRPC streaming is like a WebSocket built to handle much more data. Think of a webhook as a doorbell and a WebSocket as an open phone line.

Is a webhook faster than a WebSocket?

No. A WebSocket sends updates over a connection that's already open, which is faster than a webhook making a new request each time. Webhooks are simpler, not faster.

Can I use webhooks and WebSockets together?

Yes, and many teams do. WebSockets handle the real-time updates in a running service, and webhooks act as a backup or serve teams that don't want to run that service.

How do I check that a webhook really came from Alchemy?

Every Alchemy webhook is signed over the raw request body, so read the body as raw bytes before any JSON parsing (for example, with express.raw()). Recreate the signature from those bytes with your signing key and compare it to the X-Alchemy-Signature header. If they don't match, reject the request.

javascript
Copied
import crypto from 'node:crypto'; import express from 'express'; const app = express(); const SIGNING_KEY = process.env.ALCHEMY_SIGNING_KEY; app.post('/webhooks/alchemy', express.raw({ type: 'application/json' }), (req, res) => { if (!isValidSignature(req)) return res.sendStatus(401); handleEvent(JSON.parse(req.body)); res.sendStatus(200); }); function isValidSignature(req) { const expected = Buffer.from(crypto.createHmac('sha256', SIGNING_KEY).update(req.body).digest('hex')); const received = Buffer.from(req.get('x-alchemy-signature') ?? ''); return received.length === expected.length && crypto.timingSafeEqual(received, expected); }

What happens to webhooks while my endpoint is down?

Alchemy retries with backoff for up to about 10 minutes on Free and Pay As You Go plans, and up to an hour on Enterprise. Because of retries, the same event can arrive twice, so keep track of what you've handled. Key each transfer on the fields that tell it apart, such as transaction hash, addresses, asset, value, token ID, and log index, plus its removed flag, rather than the webhook's ID. One transaction can hold several transfers, so the hash alone isn't enough. That matters for reorgs: if a block is dropped, the same transfer comes back with removed: true. That isn't a duplicate. It tells you to undo something you already handled. Keep keys for a limited time, such as a day, so the store doesn't grow forever. If you're down longer than your plan's retry window, query for missed events with the Transfers API on Ethereum and supported L2s, or getSignaturesForAddress on Solana.

javascript
Copied
const { event } = JSON.parse(req.body); const counts = new Map(); for (const a of event.activity) { // Tell transfers apart: one tx can hold several internal transfers or an ERC-1155 batch. const id = [a.hash, a.category, a.fromAddress, a.toAddress, a.rawContract?.address, a.erc721TokenId, a.erc1155Metadata?.map((t) => `${t.tokenId}x${t.value}`).join('+'), a.value, a.log?.logIndex, a.log?.removed ?? false].join(':'); const n = (counts.get(id) ?? 0) + 1; // identical transfers in one tx stay distinct counts.set(id, n); const key = `${id}#${n}`; // removed: true gets its own key: a reorg notice, not a repeat if (await seen.has(key)) continue; await queue.push(a.log?.removed ? { undo: a } : { apply: a }); await seen.add(key, { ttlSeconds: 86400 }); // keep a day of keys, not forever } res.sendStatus(200);

How do I catch up after a WebSocket disconnects?

When you reconnect, subscribe again, then use eth_getLogs to fetch everything after the last block you processed. Fetch a long gap in chunks, because eth_getLogs limits how many blocks one call can cover (limits). Skip anything you've already handled. Also watch for reorgs: if a block is dropped, the logs subscription re-sends its logs with removed: true, and your handler needs to undo them.

javascript
Copied
ws.on('open', async () => { ws.send(JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'eth_subscribe', params: ['logs', { address: CONTRACT }] })); const head = parseInt(await rpc('eth_blockNumber', []), 16); for (let from = lastBlock + 1; from <= head; from += CHUNK) { // CHUNK fits your block-range limit const to = Math.min(from + CHUNK - 1, head); const logs = await rpc('eth_getLogs', [{ address: CONTRACT, fromBlock: '0x' + from.toString(16), toBlock: '0x' + to.toString(16) }]); logs.forEach(handleLog); } }); function handleLog(log) { if (log.removed) return undo(log); // block was reorged out apply(log); }

Do I need gRPC for Solana?

Not always. Solana's WebSockets work fine for a few accounts. If you're watching a lot of accounts or can't afford gaps, gRPC holds up better.

How do I resume a Solana gRPC stream after a disconnect?

Pass the last slot you processed as fromSlot when you subscribe again. Alchemy replays from that slot, including it, then picks up the live stream. You can get updates you've already processed, so skip any you've already handled. The sample uses CONFIRMED commitment. PROCESSED is faster, but a replay at that level can include transactions from forks that later get skipped.

javascript
Copied
stream.write({ transactions: { wallet: { accountInclude: [WALLET], vote: false, failed: false } }, accounts: {}, slots: {}, transactionsStatus: {}, blocks: {}, blocksMeta: {}, entry: {}, accountsDataSlice: [], commitment: CommitmentLevel.CONFIRMED, fromSlot: String(lastSlot), });

Can I use webhooks for Solana wallets?

Yes. Alchemy's Address Activity webhooks support Solana, so your server gets a request when a wallet you're watching sends or receives. If you're watching many wallets at high volume, gRPC is usually a better fit.

Do I need to run my own node?

No. You can, but then you're responsible for keeping it running and catching up after outages. Alchemy runs that part for you.

What does Alchemy offer for each?

  • Webhooks for address activity on 30+ EVM chains and Solana, NFT activity on Ethereum, Arbitrum, Optimism, and Polygon, and custom filters on EVM chains.
  • WebSockets through eth_subscribe for new blocks, pending transactions, and contract events.
  • Solana gRPC, compatible with Yellowstone, with filters and replay after a disconnect.
Background gradient

Build blockchain magic

Alchemy combines the most powerful web3 developer products and tools with resources, community and legendary support.