New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Webhook vs WebSocket vs polling: how another system should hear about new device data

Three ways for another system to hear about new device data, compared on firewalls, outages and catching up, with the pattern I use: a push channel plus a history read.

Webhook vs WebSocket comes down to who opens the connection. A webhook is an HTTP request the data source sends to an address you expose. A WebSocket is a connection your system opens and keeps open to receive messages. Polling means asking again on a timer. Whichever you pick, keep a history read for catching up after an outage.

From the integration side, I find the choice turns on two things: firewalls, and what happens to events that arrive while the receiving side is down.

What is the difference between polling and webhooks?

With polling, your system asks for new data on a schedule; with a webhook, the source calls your system when something happens. Polling is simple and only needs outbound connections, but every empty answer is wasted work, and new data waits up to one interval.

Long polling sits in between. The server holds each request open and answers only when there is something to deliver. RFC 6202 reports success with timeouts as high as 120 seconds but calls 30 seconds the safer value, because proxies may cut longer requests.

A webhook needs an endpoint the sender can reach from the internet, which means an inbound firewall rule on your side. If your endpoint is down, you depend on the sender’s retries, and those differ from one service to the next.

When should you use a WebSocket?

Use a WebSocket when your side should open the connection and both sides may need to talk. RFC 6455 defines a handshake that starts as an HTTP Upgrade request, designed to work over ports 80 and 443, after which messages flow both ways. Ping and Pong frames serve as a keepalive.

Because the receiver opens the connection, it needs no new inbound firewall rule. While the socket is down, messages are not stored for you unless the server keeps them.

When to use server-sent events?

Server-sent events (SSE) fit a one-way feed from server to client over plain HTTP. The HTML specification defines the text/event-stream format, and when the connection drops, the browser reconnects and sends the last event ID it saw in a Last-Event-ID header, so the server can resume.

The specification also suggests a comment line about every 15 seconds, because some older proxies drop idle HTTP connections. SSE has no channel for the client to talk back, so commands go in separate requests.

CriterionPollingWebhookWebSocketSSE
Who opens the connectionReceiverSenderReceiverReceiver
Inbound firewall rule at the receiverNoYesNoNo
DirectionRequest and replySender to receiverBoth waysServer to client
Receiver downNext poll picks upSender retries, if it doesMessages missedResume by last event ID, if the server supports it

How to switch from polling to events without losing data?

Keep a read of history as the safety net and add the push channel on top. Device data has timestamps, so a gap can be filled from stored readings, as long as the source still keeps them.

  1. Store a cursor: the timestamp or event ID of the last item you processed.
  2. Open the push channel: a webhook endpoint, a WebSocket or an SSE stream.
  3. On start and after every reconnect, read history from the cursor to now through the source’s history API.
  4. Deduplicate by event ID or by device and timestamp, since the history read and the push will overlap.
  5. Advance the cursor only after the item is safely stored.

Step 4 matters most for webhooks. RFC 9110 lists PUT, DELETE and the safe methods as idempotent, not POST, and webhooks usually arrive as POST. A repeated delivery must therefore be harmless on your side. Plan for late and duplicate readings in the same handler. If your devices still choose between protocols, I compared MQTT vs HTTP for IoT devices earlier.

Frequently asked questions

Do webhooks need a public IP address?

The receiver needs an address that the sender can reach, which usually means a public endpoint and an inbound firewall rule. If that is not allowed, choose a model where your side opens the connection: polling, a WebSocket or an SSE stream.

How often should I poll for device data?

Poll no faster than the data changes and the source allows. If you need lower latency without hammering the server, long polling with a timeout of about 30 seconds, as RFC 6202 suggests, is a middle ground.

What does idempotent mean for a webhook receiver?

It means that handling the same delivery twice has the same effect as handling it once. RFC 9110 defines idempotency for HTTP methods, and POST is not among the idempotent methods, so the receiver must make itself idempotent, for example by storing each event ID and ignoring repeats.

Share

See your field data live this week

Start a trial in your region with your first devices, or book a demo and bring your own use case.