In the process of developing a realtime Single Page Application, I have progressively adopted websockets to empower my users with up to date data. During this phase, I was sad to notice that I was destroying way too much of my app structure, and I failed to find a solution to this phenomenon.
Before getting into specifics, just a bit of context:
- The webapp is a realtime SPA ;
- The Backend is in Ruby on Rails. Realtime events are pushed by Ruby to a Redis key, then a micro node server pulls back that and pushes it to Socket.Io ;
- The Frontend is in AngularJS, and connects directly to the socket.io server in Node.
On the server side, before realtime I had a clear controller/model based separation of the resources, with processing attached to each. This classical MVC design was completely shredded down, or at least bypassed, right when I started push stuff via websockets to my users. I have now a single pipe where all of my app flows down more or less structured data. And I find it stressful.
On the front end, the main concern is the duplication of business logic. When the user loads the page, I have to load my models trough classical AJAX calls. But I also have to handle realtime data flooding in, and I find myself duplicating much of my client-side business logic to maintain consistency of my client-side models.
After some researches, I can't find any good posts, articles, books or whatever that would give advices about how one can and should design the architecture of a modern webapp with a few specific topics in mind :
- How to structure the data that is sent from the server to the user?
- Should I only send events like "this resource has been updated and you should reload it via an AJAX call" or push the updated data and replace previous data loaded via initial AJAX calls?
- How to define a coherent and scalable skeleton to data sent? is this a model update message or "there was an error with blahblahblah" message
- How not to send data about everything from anywhere in the backend?
- How to reduce the business logic duplication both on the server and the client side?