First of all compliments for the book. I am working through and I am learning a lot, mostly from using futures. After finishing the book I want to create my first small vapor project and I have a question regarding it. Perhaps somebody can give me a hint.
How would you implement this scenario. I would create a vapor api with an database, where every user has a table with its own data or even its own database. AS frontend I would create a SPA using React. Now my question. I would like that if i have two devices that work on the same data and if the data in the backend changes the other device receive the changes immediately without sync or refresh button. I mean the server should notify the connected devices, only the user of the corresponding table.
My idea were two:
- (Preferred idea) Using websocket as described in the book. On a change in the table, notify the client with his userId and the client checks if its his userId and then the client fetches his data.
- The client is polling the server every 2 seconds and asks for changes. But I think this not a good idea.
Or there exists another method to notify the client, that data changed in the meantime.
I know that there exists databases like Google Firestone, that have this feature on board, but this costs money and I want create only a small project for my own using Vapor and MySQL.
I know that this question refers not directly to the book, but perhaps nevertheless somebody can give me a tip, as here are some Vapor(Backend) experts.
Thanks,
Arnold