We discussed multiple approach and chose one for development.
Approach 1) Poll for changes
This is kind of classical pull approach where every 'n' second poll for changes and update UI. The problem with polling every 30 sec were,
- Unnecessary extra load on the server means fake http requests, 1 will have new message out of 100+ requests. Major hurdle in scaling app, suddenly the no of requests on server will increase multiple fold.
- Delay in data refresh based on poll frequency and it won't be realtime.
- We can't http cache the request using reverse proxy since it is user's personal data
Approach may be okay for sites like live cricket scores where requests can be http cached and served to multiple users and data changes frequently.
Approach 2) Push for changes
Second approach we came up with was push messages using websockets and libraries like socket.io etc. Using push the user experience is really awesome, user gets notified instantaneously about the new messages. No extra fake requests on the server and helps in scaling easily.
However, there are challenges
- Setting up the Notification Server. We were using Apache server and it doesn't support websocket connections. Needs upgrade to our infrastructure.
- Implementing server side component for Notification Server with security and authentication was significant effort.
- More effort as compared to poll for maintaining state logic on Notification server & Javascript, requires resilience in building edge cases around data loss
Approach 3) Push notification for changes
To overcome the problem of data security we came with the tweaked approach as shown above. We use PaaS for Push Notification only to notify end user about there is new message and no data. When the notification is received we do the poll request on main server to refresh the UI.
Key advantages of using this approach:
- No effort required for building & maintaining Notification Server. Leverage the PaaS.
- Just send the change notification, so issues with data security.
- Less development effort since most of the PaaS provider has their own library to support all browsers.
- Realtime updates to end user. Better user experience.
- High availability and scalability using PaaS
No comments:
Post a Comment