You are currently viewing Developed Facebook Style Notification System
vteams- blog

Developed Facebook Style Notification System

  • Post published:December 22, 2015

vteam #265 was formed to work on developing a Facebook Style Notification System with real-time comments functionality. The application was built using PHP, Microsoft IIS 6, and MS SQL Server 2008 R2 with minimal hardware specifications. The notifications could be accessed by multiple instances of the same user, or by various other users too. Administrator of the application needed to stamp a comment as viewed once it was seen.

Problem:

For resolving real-time notifications issue, vteams engineer Danish Khan had to generate an Ajax request which could be sent to maximum with 5 seconds interval. There could be multiple users or same users with multiple instances which means that there would be a minimum of 12 HTTP requests from a single node for notifications only. It would be generating 12 Database connections + multiple queries for user validation and other stuff individually. If 100 users were considered at a time, it would become 1200 Ajax requests in a minute only to carry notifications data. This whole process required tons of bandwidth and was also involved in Database locking.

normal-way-of-processing

Normal Way of Processing

Solution:

Danish developed such a notification system that would keep the log of active users in a table. A JSON file called ‘Hash File’ would be created for every node containing IP-USERID-OS-UID. This hash file would be removed once node would become offline (means user would go offline from a machine). A Scheduler would be executed after every 3 seconds and performing the following processes:

Single Query for All (Users/Nodes)

This process would collect all logged in users IDs and find notifications required to be pushed. System would automatically check either this notification had been pushed already to the node via Hash file or not. If not then it would get appended to the list. After complete iteration, system would pack this list to Hash file.

Minimizing Traffic Bandwidth

When a node (User with any instance) would hit the server for notifications data, this system would then distribute the notification data from hash file. This hash file was processed with a single query rather than querying the whole Database each and every time for every single node. System would check either this file was touched recently before interval time or not. If yes then it would not send anything and touch the file (operating system task updated the touch time stamp) for next request. Otherwise, it would resend the recent notifications.

Single Update action for viewed Items

When a node would send a request for notifications data, it would contain recently viewed items IDs (that were required to mark as viewed). It would then save an HTTP request sent for acknowledging the Server that the notification had been viewed.

recommended-way-of-processing

Recommended Way of Processing

Conclusion:

As a result of the applied solution mentioned above, following outcomes were achieved:

  1. Minimized HTTP Request counts
  2. Minimized Network Bandwidth volume
  3. Minimized Database Load (Database connections and processing)
  4. Minimized System processing
  5. Distributed the load to user and made the processing faster