I'm implementing an app that has among other things shared todo lists. I want it to sync in real time. This has to work for "normal" single user items (e.g. user has app opened in 2 devices, doing an update in one device shows immediately in the other device) as well as the shared lists, where all the participants have to receive the update in real time.
I'm not entirely sure which kind of structure is best in order to accomplish this. I was thinking about storing a dictionary of user uuid -> socket list. When users log in or open the app while being logged in, they'll initiate a connection. Here I add an entry or update to the dictionary. When they log out or close the app, the connection is closed and I update the map accordingly. Whenever the app does an update in the server, I look up the affected users, then look up in my dictionary for possible open websockets for these users, and send the updates to them.
Another idea I had, was to associate the connections rather than with the users, with items, like e.g. the todo lists. So again I have a dictionary, but this time the key is the todo list uuid and it has an array of connections ("observers") for this list, where I broadcast wherever the list is modified. This approach is not suitable for the "single user sync" though, here the elements don't necessarily have an own identity, rather associated with the user - so I'm back to the first approach with a dictionary user -> connections.
But before I dive into more details I'd like to confirm if this is the correct train of thought. How is this normally modelled? This is rather a theory question, but in case it's relevant for something, I'm using Play Framework 2.4 / Scala.