1

I have a question. Facebook probably uses ajax to notify user about a new message, is this correct? If yes, would not this tax db to incredible levels? I mean millions of users every second of being online requesting message status. Or am I thinking about this in a wrong way?

1 Answers1

0

You are asking about a technique called polling. And you are correct that it has scalability issues. In general not a good idea.

[rant]I have no idea what facebook does. I hate facebook. It's like a drunk whore who won't stop texting/emailing you and needs to be used.[/rant].

There are better alternatives to polling. One technique is called long polling, and then there is server side push.

See How do I implement basic "Long Polling"? and https://stackoverflow.com/questions/6883540/http-server-to-client-push-technologies-standards-libraries.

In long polling, the client sends a request but does not expect a response immediately; the response could come immediately, in a second, or in an hour. The challenge is for the server to manage the outstanding requests in a non-resource intensive way.

With server side push, the server maintains a connection with clients and can broadcast messages to its connections when events occur.

Which alternative to use depends a bit on your technology stack. For example, node.js has something called socket.io (which I think is server side push using html5 websockets) which I hear good things about.

Community
  • 1
  • 1
hvgotcodes
  • 118,147
  • 33
  • 203
  • 236