Play Framework looks very interesting but it encourages minimal state on the server side. My question is how can I synchronize client state with server state easily? What if I want to have server state such as in the development of a chat application, how easy or difficult is it to keep server state and synchronize client and server state?
Play Framework looks very interesting but it encourages minimal state on the server side.
Share
For standard web applications, state is held in either the cookie, in the database, or in a cache (remembering that cache is unreliable and must be accessible from the DB if the cache does not contain the data you want). Nothing is therefore held in state in server side sessions.
However, there is a slight nuance here as far as what is defined as stateless for a Play application for a chat type application. If you look at the chat application in the early versions of the Play (before Websocket support), you would have found all ‘Message’ objects which are individual lines in a chat, stored in the database. However, in the most recent version, which includes WebSocket support, you will find that the state of the chat is stored in a Singleton object, which will last for the enter length of the chat.
The argument from the Play devs is that a Websocket communication, therefore a full chat can be thought of as a single request, over many back and forth communications. Therefore, by keeping the state held in a singleton on the serverside does not break the rules of a stateless architecture. The reason why this is true, is because once a websocket communication is set up, the conversation along the socket will always be between the client and the single server, until the websocket is closed.