Lamar
✅ How to notify clients when an db update occurs
Hello!
I am trying to build a Voting-ish application.
What I am trying to achieve is to send notifications to the connected clients once a db entity has been updated, but I am unsure what would be the best approach.
A constraint I have set is that I am trying to use SSE to communicate with the clients.
For now I thought of constructing some observable. In my mind it would work similar to this:
- client sends a request to update the voting count
- the database updates the entity
- I send a notification that a changed occurred
- in the SSE endpoint, I have a listener that waits for changes and once it receives a change it sends data to the clients which will tell the clients to send another request to fetch for the new updated votes
However I am unsure if this approach is good or if it even works.
Do you have any suggestions on how I can improve the approach?
134 replies