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:
and the socket server is here:
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:9999AND 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 to
https://mydomain.com/socket:9999and 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