views:

163

answers:

3

Hi,

In my facebook application, I use peoples friends names in the application. I can either get the names from facebook. Or save them the first time the person logs in. So everytime his/her friends received from the database.

Which method is faster?

+2  A: 

As a rule local Db connections are usualy much faster to access than webservice calls. I would suggest you setup both options and record some time metrics to test this, but keep in mind the response of Facebook is also going to change at diffent times of the day under different loads.

Dont forget the friends list are always changing too, I would suggest you fetch the list in the background on every login to update your database copy too.

Tj Kellie
+7  A: 

Storing the friends names in the database will almost certainly be faster - Facebook's API is not particularly fast, and since the query needs to go across the internet there's added latency.

However, storying the friends names retrieve directly from the API on first use for more than 24 hours as in breach of the developers terms of service. So you should expect to have to query the API regularly, either on every view of the page or else implement a more complex data caching system of your own.

Karl B
+1: This is even more important than being out of sync with them. Good find.
Chris Lively
Basically I'm going to store each persons own name. When a person comes I get who is his friends who are playing the application. So it retrieves their names. I'm not storing his friends information in his database.
Fahim Akhter
Even storing the user's own name is breaking the developer terms. The only away around that is to present the user with a blank text field and ask them to input a name themselves - you can't even have it pre-filled with data from the API.
Karl B
+1 - never, ever store Facebook user information in your own database. Implement a local session cache to prevent excessive API querying, but do not store user data permanently.
zombat
Now my app screen takes forever ah! I wonder how zynga loads his screen so quick with all the neighbors. I think they might be calling facebook api from facebook. Cause from server it takes forever.
Fahim Akhter
You can cache the results for 24 hours remember, and I know Zynga will have invested in that kind technology. It also helps to have a server that's closer to Facebook's, which generally means either central or western US.
Karl B
A: 

Obviously pulling the names from your local database would be faster.

But that doesn't matter. Being out of sync with facebook is the overriding concern.

Let's say they use the facebook site to remove a friend. Will they then have to click a "sync" button in your app to remove them as well? So my recommendation is not to worry about performance and always get the latest from facebook.

Chris Lively