Jim Moody
Jim Moody

Reputation: 808

How would you get near real-time data from a server that does not support server sent events?

We are building an application that needs to call an API for some data but the API we are calling does not support "pushing" or server sent events. So what would be the best way to get at least near real-time data?

From what I have researched it looks like short polling would be the best approach, but I'm curious if there is a different/better way to solve this problem.

Upvotes: 0

Views: 193

Answers (1)

Freiheit
Freiheit

Reputation: 8777

A fast poll is probably the easiest solution to implement given your current constraints. Your ability to be "real time" is dependent on the poll window and the applications ability to return results fast enough. There is also a risk that you are hitting the service with a lot of API requests.

Since you have access to the underlying database you might also want to consider adding triggers to the database. Even a simple trigger which puts an ID or key suitable for use with API calls into a table with a timestamp then lets you poll that table to get your real-time event then use the ID to call the API to get the event details. Some databases may allow triggers that make syscalls or send messages over a network. Adding DB triggers may be less effort than adding a new application feature and is more of a "push" than outright polling.

It is hard to provide a concrete answer without more details about the applications, APIs, and databases involved.

The level of effort for a workaround may exceed that of adding a proper event system.

Upvotes: 1

Related Questions