If You Are Used to Polling APIs

Previously, you might have sent a GET request every few minutes to receive a list of recent events. With WebSockets, you:

  1. Connect once.
  2. Authenticate by sending a connection_init JSON message with your oAuth token.
  3. Send a subscription request.
  4. Send regular ping requests and reply with pong to server pings to keep the connection open.
  5. Wait and process events as they stream in. There is no need to poll. Each event will be a JSON next message.
  6. Exchange heartbeat messages to keep the connection open.
  7. When done, send a complete message, but wait for the server to close the connection.

You only need to reconnect if the connection drops or if your authentication expires.

  Polling API Streaming API (WebSocket)
API Complexity Simple Requires ping/pong, reconnection, etc.
Connection New connection for each poll Persistent once-open connection
Data Arrival On schedule (e.g., every N minutes) Real-time (as soon as event happens)
Network Load High (many HTTP requests) Low (connection stays open)
Sample Output List of events; may contain duplicates Single event per message; processed sequentially