How do Facebook Notifications Work?

espfutbol98

New Member
Messages
200
Reaction score
2
Points
0
I have been wondering for a while how the notifications on Facebook work, most noteably the bubble on the bottom left that says something like ".... commented on your photo" and the number balloon by the messages drop-down menu. I know AJAX is involved along with PHP and a database engine such as MySQL but I'm not sure exactly how it works. I someone could show the method, I'm sure I can figure out the rest. Thanks!
 

RicardoCabral

New Member
Messages
18
Reaction score
0
Points
0
There are many ways to do that and I don't know which one facebook chose.

But the first idea that comes to my mind is having a table with the notifications and field one of the fields can be a boolean that changes the value when the user reads the notification. As facebook store the last notifications, when a new notification is inserted, the oldest is removed (if it was already read).

The changes on the interface are made by AJAX. facebook uses jQuery? I don't know. But it could be done easily with jQuery to handle the AJAX process. I know that the response is returned using JSON.

Just a side note. If you find out how exactly facebook does it (or anything else), I advise you to do the opposite. facebook is the second most visited in the web, but it does not mean it has good programmers.
 
Last edited:

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
Facebook uses a LOT of AJAX. I remember my school unbanned it for a bit, but it crippled the server.

~Callum
 

smithee

New Member
Messages
45
Reaction score
2
Points
0
Following on from what Alex has said, here's only a few features on Facebook where chances are it uses Ajax:
  • The three icons at the top-left to alert you of any new friend requests, private messages, or notifications
  • The search box
  • The news feed (regularly updates itself)
  • Recommended pages (when you like/dismiss one, it'll show another)
  • Shows which friends are online
  • Facebook chat itself
  • The news feed again when you scroll to the bottom

And the list above only shows the ones that are fully automated on the Home page!! These will be fetched regularly from a database by using a JavaScript timer. I'm not even going to mention the ones where you click to activate an Ajax script, simply because there's far too many! If you click on a link anywhere on Facebook, 98% of the time it will run an Ajax script one way or another. Notice that when you go to another page, the http address doesn't really change, but only the end part after a hash (#), pretty much like for a bookmark anchor... yep, you guessed it, the entire clean-up of a page and loading a new one is done through Ajax as well! That's why the top and bottom bar stays where they are; even after what seems to be like going to a new page as it shows completely different content, you are still in fact on the same page.
 

espfutbol98

New Member
Messages
200
Reaction score
2
Points
0
Alright guys, thanks. This should help me get started a little easier.
 
Top