Skip to content

Long polling

Instead of polling for changes frequently, consumers can also decide whether to send Long Poll requests to fetch event messages. Long Poll reduces empty messages by allowing consumers to wait until a message is available from the Event server.

This feature is supported in all three available SDKs

Event batching is still applicable. If more than one message is available at the time you initiate a long poll request, you will be delivered up to X messages for that poll request; where X is the max batch size you have configured with the SDK

The benefits to consumers:

  • Best for low frequency topics where you need low lag but don’t want to waste processing power on continually polling the service

Long poll request process

When a consumer sends a Long Poll request, the server will internally poll Kafka to fetch the event. During the Long Poll request, the server will immediately return the response when an event is available and close the Long Poll request. If no event is available within 60 seconds, the server will close the Long Poll request after the time out (60 seconds is the mandatory time out, consumers cannot customize this). After the consumer has either received an event or the 60-second connection time-out message, they can initiate another Long Poll to continue listening for events.

Response

  • If no event is available to the consumer during the 60-second open connection time, the Long Poll request is closed, and the server will send the response with “End Of Long Poll Request.”
  • The server will allow only one Long Poll request for a subscription at any given time.
  • If a new Long Poll request is requested when the server is processing another Long Poll request for the same subscription, the server will send the error with the message - “Already long poll is in progress.”
  • If the consumer sends the Long Poll request with a time out other than 60000 ms, then the server will send back the error with the message - “long.poll.duration should be 60000 ms.”

Long poll tracking

  • The Tracking feature will determine whether the requested Long Poll from a subscription is eligible for a Long Poll or not.
  • Tracking allows you to disable the Long Poll feature for a subscription if the received messages exceed 15 events in 1 min.
  • Long Poll is applicable for consumers who only receive a low volume of events. The server tracks the consumed events of a Long Poll request to check this.
  • When the Long Poll feature is disabled for a subscription, all requests from that subscription will be treated as regular Poll only. Long Poll will be disabled for 15 min.