I am confused here on how real time analytics is accomplished with web sockets when data is inserted into the system via a REST API. In my (admitted immature) understanding of web sockets, you have many clients connected to the socket server and the socket server emits events to the connected clients. The only communication is between that socket server and those clients. What I can't figure out is how web sockets can "detect" that something in the database was updated, if that database was updated at:
https://mydomain.com/api/v1/path/here/
and the socket server is here:
https://mydomain.com/socket:9999
I can really only come up with one of two ways that this will work, and I know both are wrong:
- ALL API endpoints are changed to
https://mydomain.com/socket:9999
AND THEN AFTER the clients are updated with the info, the socket server makes an API call to the correct place with the correct info. - AFTER the API does its thing at:
https://mydomain.com/api/v1/path/here/
, it makes a short-lived call tohttps://mydomain.com/socket:9999
and updates the client data as needed, and then closes the connection.
AGAIN, I know both of these solutions are BAD, BAD solutions (they're not clean at all, they lend to writing bad code, they're incredibly brittle, not fault-tolerant, not performant, etc...), but I can't figure out another solution.
What am I missing here that allows the web socket server to update the client when data changes in the database?
I am running our REST API on PHP and the web socket server on Node.JS
https://mydomain.com/socket:9999
does. Is that a port that you send messages to that then get distributed to the clients?