# Event Polling

In our system, events are generated by physical hosts and follow different routes to the event storage. Therefore, the order in which they appear in the storage and become retrievable - via the events API - does not always correspond to the order in which they occur. Consequently, this system behavior makes straight forward implementation of event polling miss some events. The page of most recent events returned by the events API may not contain all the events that occurred at that time because some of them could still be on their way to the storage engine. When the events arrive and are eventually indexed, they are inserted into the already retrieved pages which could result in the event being missed if the pages are accessed too early (i.e. before all events for the page are available).

To ensure that all your events are retrieved and accounted for, please implement polling in the following way:

1. Make a request to the events API specifying an ascending time range that begins sometime in the past (e.g. half an hour ago)
2. Retrieve a result page
3. Check the timestamp of the last event on the result page. If it is older than the threshold age (e.g. half an hour), then go to step (4), otherwise proceed to step (6).
4. The result page is trustworthy, use events from the page as you please.
5. Make a request using the next page URL retrieved with the result safe, proceed with step (2).
6. Discard the result page for it is not trustworthy.
7. Pause for some time (at least 15 seconds)
8. Repeat the previous request and processed with step (2).