I am working on a Java application (JSP/Servlets) where users can send messages to each other. For this purpose I am using a single table in MySQL with fields such as msg_id
, sender_id
, receiver_id
, msg_content
etc. When user_A sends a message to user_B I want to pop a notification to user_B that indicates that he has a new message (Something like how Facebook notifications work).
I've searched for a solution to this and found out that a possible way to implement it is by AJAX polling. That means that every 60 seconds for example the application will check the table mentioned above for new rows (messages to user_B) and if new messages are found then it will pop the message.
However, lets say that 100 users are connected. This means that for every single user there is going to be a request to the database every 60 seconds, which sounds pretty bad.
Won't the application get really "heavy" when something like the example above happens? What are other alternatives to achieve this?