18

I am building a social application and was wondering how facebook achieve their notifications. As you know, facebooks notifications are instant. As soon as someone takes an action, people are notified.

I assume they don't have a query running on the database all the time.

Can someone point me in the right direction. Thanks

Wesley Skeen
  • 7,977
  • 13
  • 42
  • 56
  • 1
    The question is quite a bit open-ended as there's a ton of alternatives. You'll need something to allow server to push to client. [StackOverlow old question with info](http://stackoverflow.com/questions/471780/asp-net-http-server-push-to-client) – Pedro Ferreira Jul 10 '12 at 08:50

3 Answers3

26

Since your question is tagged with C#, ASP.NET you should use the awesome SignalR library. Basically SignalR enables you to send push notifications to the clients. Which exact underlying technique it uses is influenced by the capabilities of the Server and the Client.

There is a big real time chat site called jabbR that is built on top of SignalR:

http://jabbr.net/

Here are some more links that should get you started.

Christoph
  • 26,519
  • 28
  • 95
  • 133
8

Facebook uses a messaging protocol (which it designed) called Thrift. This allows notifications from clients to servers with very low latency. I would imagine updates on the server would be triggered depending on the user action and relevant users that are logged in would be notified by the same mechanism.

Using a messaging protocol such as thrift (also see Protocol buffers) clients don't have to poll the server for updates, instead the server can push notifications to clients. To do this the server needs to have a notion of who is logged in at any one time (Login, logout handshaking) and of them, who should receive notifications from a particular client action.

Easier said than done, especially when you have 800 million potential users logged in!

Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178
0

You might want to take a look at http://nodejs.org/ - it is an event-driven model which is perfectly ideal for a 'social network' / instant notifications scenario.

FYI: You also might find that using a non-SQL database such as MongoDB (http://www.mongodb.org/) will be a lot faster when querying from the DB since each 'person' object in a social network scenario has his/her own unique attributes - which in a normal SQL database is hard to design.

James Gatt
  • 86
  • 1
  • 3
  • 15