Graph API vs FQL which is faster?

nate picture nate · Oct 4, 2011 · Viewed 10.8k times · Source

just wondering when it comes to just the basic GET/POST. (i.e something simple as getting the users profile and not something complicated like getting a pictures from every album)

which is faster? Graph or FQL.

i know FQL is newer than graph, but unsure if its more efficient.

Answer

Juicy Scripter picture Juicy Scripter · Oct 4, 2011

It's in no way comparable like this. While you can get same data (in some cases) from both their intents are completely different: FQL is a query language, Graph is an API.

Calling to FQL query if using new JS SDK is a Graph API call itself...

You can (and probably should, if you worry about real comparison and not theoretical speculation) compare speed of calls returning same data but you should take into account some things:

  • Graph API still sucks at data filtering conditions and aggregation of data
  • FQL just can't provide you too many of functionality required in today's applications (like Real-Time updates)
  • Graph API have an ability batch calls, which may speed up things a lot, this also can be used to call fql.query and fql.multiquery (in a bit cumbersome way).
  • Graph API rocks at data filtering with Field Expansion

Consider following example from FQL documentation, subquery that fetches all user information for the active user and friends:

SELECT uid, name, pic_square FROM user WHERE uid = me()
OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

This simply not possible to achieve with a single Graph API call. (see Update)

Once you define desired subset of data to get you can choose appropriate method of retrieval based on your requirements.

BTW, FQL is much older than Graph, we had it aside to FBML (rip) and FBJS (rip)

Update:

Graph API providing way for Batch Requests and specifying dependencies between operations in the request. For example same sample as above can be achieved in a single call to Graph API

POST https://graph.facebook.com/
POST Data:
batch=[
  {
    "method": "GET",
    "name" : "get-friends",
    "relative_url": "me/friends?fields=id",
  },
  {
    "method": "GET",
    "relative_url": "?ids={result=get-friends:$.data.*.id}&fields=id,name,picture"
  }
]

Update 2:
As of 30 August 2012 Graph API is also support Field Expansion as additional (very powerful) mechanism of data retrieval (including nested data)