How does facebook store the friends of a user? - facebook

I am wondering how exactly the information that a user with id x is friends with users with ids z,y,w is stored in a very large scale app like facebook.
I am thinking of several possibilities
a) Have a table which maps friendships with the ids of the people involved as foreign keys, as shown here:
Person|isFriendsWith
x -------------------y
x ------------------ z
x------------------- w
Which seems to me it wouldnt scale well at all.
b) Have a field in the users row that stores the ids of their friends in a kind of serialized format like a string "#z#y#w". I suppose with the right algorithm the parsing and updating of this string would be easy.
c) Have a separate table with the friends of each user. Would this be too much load on the server?
d) Something else?
So, if anybody knows what facebook does and can share details it will be appreciated, that's what the question is about. Also, if someone can share insight why what I listed here would not scale well or would have other problems performance-wise, I am interested in hearing it.
Thanks

Here are some links. The first link's page has a link in it on the words "largely complex" that link to a flickr image of a schema. I cannot vouch for the correctness of any of the information in these links:
http://www.makeuseof.com/tag/facebook-work-nuts-bolts-technology-explained/
http://www.theregister.co.uk/2011/07/13/mike_stonebraker_versus_facebook/
http://gigaom.com/cloud/facebook-trapped-in-mysql-fate-worse-than-death/
http://snarfed.org/facebook_data_store_api_thoughts/
The image I mentioned was created by analyzing the business entities in the API that Facebook has opened up. http://blogs.x2line.com/al/archive/2007/06/02/3124.aspx
That was 2007, so may or may not be representative any longer.

Related

Optimal Database design regarding functionality of letting user share posts by other users

I want to implement functionality which let user share posts by other users similar to what Facebook and Google+ share button and twitter retweet.
There are 2 choices:
1) I create duplicate copy of the post and have a column which keeps track of the original post id and makes clear this is a shared post.
2) I have a separate table shared post where I save the post id which is a foreign key to post id in post table.
Talking in terms of programming basically I keep pointer to the original post in a separate table and when need to get post posted by user and also shared ones I do a left join on post and shared post table
Post(post_id(PK), post_content, posted_by)
SharedPost(post_id(FK to Post.post_id), sharing_user, sharedfrom(in case someone shares from non owners profile))
I am in favour of second choice but wanted to know the advice of experts out there?
One thing more posts on my webapp will be more on the lines of facebook size not tweet size.
I would suggest that your system would do one of the two:
Put code inline for the post (similar to a hyperlink) that would reference the original post. I do not know if you are trying to pull in images or other media. When you encounter this inline code, your system could either create a hyperlink to view the original or pull data from the original into the post that is sharing it.
Alternatively your poststable could have a column for shared_post that could either be a post_id or a hyperlink to an external item to share. Your system can then recognize that if the value is null or -1 that it is not a shared post and can treat it normally.
I would not recommend creating a new table for storing duplicates of the shared posts. It becomes harder to maintain and update.
Additionally, if you plan on having sharing groups involved in this system, you will most likely need another table that links post_id to sharing_group_id.

Facebook note shared info

My client need to randomize over everyone that shared a specific note on his facebook page, it's like a raffle, however, i didn't found a way to get any info, even the name in a way that i can randomize over them, is there any way that i can fetch this information?
You can query the note for the comments or likes if you are looking at a specific note. Or you can query the user for all their notes and loop over that.
Depending on what language you are using, randomly choosing from an array of items should be trivial.

The app test users are unable to like the page.

I'm developing a facebook application and I need test users to test it.
I know that facebook provides now the possibility to create tests users, but they can't "like" a public page and this prevent me to use them because the "likes" is the only thing I need.
Do you know any solutions?
Thanks in advance.
Adding Like button code is quite simple, so if the goal of your testing is to make sure it will work properly with Facebook, all you need is to generate Like code using FB Reference , and you can be confident it works without testing.
If the goal of your testing is testing something else, based on number of responses, and you need a good representation of numbers (e.g. 10, 100, 1000, ...), you have 2 options:
hook "pseudo like" to some file/db table where you can change it as you want, test with all the numbers you need to test, and then replace with real FB Like
since Like is based on URL, during testing you could test your logic using Like code for some other pages (that already have different number of likes). For example reference page I gave a link to above, has about 65k likes, so I could use code for that page temporarily to test my logic for 65k likes.
After that you still can test a few numbers by using your friends as test subjects of course.
If only there were a website where you could ask all of your friends to help you... a website that included the ability for those friends to "like" whatever it is you are working on... you'd have to ensure that those friends were willing to spare a brief moment of the work day to (gasp) not work and view the website instead...
Sarcasm aside, I think your best bet will be to ask the people on facebook for a few likes just to help you with a project.

Facebook Graph API: Getting the total number of posts

I've been using the Facebook Graph API to display user posts. When I get the initial "page" of posts, the resulting data object has a paging property object with a previous and next URL property. I was hoping to generate navigation links based on this available paging information. However, sometimes these URLs point to an empty set of data, so I obviously don't want to navigate the user to an empty page.
Is there a way to find the total count of objects in a collection so that better navigation can be derived? Is there any way to get smarter paging data?
Update:
Sorry if my post isn't clear. To illustrate, look at the data at https://graph.facebook.com/7901103/posts and its paging property URLs. Then follow those URLs to see the issue: empty pages of data.
Since it pages the datas with date-time base. You can't get the knowledge of whether if there are datas or not before you actually send the request to it. But you can preload the data from previous url to determine is it suitable to dispaly a previous link in your web page.
Why be dependent of Facebook?
Why don't you preload all data for a user and save into a database. Then you fetch the posts from db and show to user. This way you have all the control on how many posts there are and how to manage next and prev.
I was going to try to post this as a comment to your question, but I can't seem to do so...
I know that the Graph API returns JSON, and while I've never come across a way to have the total number of posts returned, depending on what technology you are using to process the response, you might be able to capture the size of the JSON array containing the posts.
For example, if I were using a java application I could use the libraries available at json.org (or Google GSON, or XStream with the JSON driver) to populate an object and then simply use the JSONArray.length() method to check for the number of posts returned.
see:
http://www.json.org/javadoc/org/json/JSONArray.html
It might seem like a bit of a simplistic solution, but might be the type of work around you require if you can't find a way to have Facebook return that data.
Can you specify what technology your application is based in?

How do I create a user submission feed?

Making this as simple as possible..
All I want to do is make a user-submitted form that looks like facebook's newsfeed.
"I want to" [texbox for user input]
[ (Post button)
Appears right below:
[I want to ___________________]
I feel that this can't be too complicated.. I'm trying to have simple code that will allow a user to submit text and have the text appear right below the submission area.
How should I approach this with AJAX? What else would I need? As you can tell I'm a novice.
That's a very broad question. You'll probably want a database, though you could get away with flat text files - at least for a bit. You could automatically generate the RSS xml on request with any of a number of different scripting languages from the database or flat file, or you could update the static RSS feed whenever you post. If you only needed the RSS, the RSS itself could be your storage.
Restrict us a bit more! Give us a language, a persistence mechanism, and what else you want to do with the data.