Facebook on Rails

5,396 views

Published on

Some observations on Facebook development using Ruby on Rails, Heroku, Facebooker, New Relic

Presented at Ruby Tuesday, Taipei, 2009.10.20

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,396
On SlideShare
0
From Embeds
0
Number of Embeds
1,813
Actions
Shares
0
Downloads
61
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Facebook on Rails

  1. 1. Facebook on Rails CardinalBlue info@cardinalblue.com Ruby Tuesday 2009.10.20 Friday, October 23, 2009
  2. 2. 40% of all Internet Users in North America are on Facebook! 300 million Facebook users around the world Friday, October 23, 2009
  3. 3. Facebook Trends ( ) 73 Friday, October 23, 2009
  4. 4. Facebook Apps Boom Friday, October 23, 2009
  5. 5. Friday, October 23, 2009
  6. 6. Demographic Trends • More female gamers • More younger (ages 8-15) gamers • More older (ages 50+) gamers Friday, October 23, 2009
  7. 7. FB Games are Social • Trend #1: Virtual Worlds • e.g.,YoVille, PetSociety • Trend #2: Customization & Personalization • e.g., Nintendo’s “Mii” avatars, Buddy Poke • Trend #3: Collections and Wish Lists • e.g., Mafia Wars • Trend #4: Interaction and Engagement • Farm Town, FarmVille, Barn Buddy • Trend #5: Narrative and Missions Friday, October 23, 2009
  8. 8. FB Games are Social • Trend #6: Gift Invites • e.g., Lil Green Patch, Give a Heart • Trend #7: Donations as Revenue • e.g., SpareChange, PayPal • Trend #8: Virtual Goods • e.g., Mafia Wars, PetSociety • Trend #9: Recruiting Users • e.g., FarmVille, Restaurant City, Tycoons • Trend #10: Capitalizing on Player Resources • e.g., All that Glitters, Photo-of-the-Day Friday, October 23, 2009
  9. 9. FBML Application Architecture Friday, October 23, 2009
  10. 10. Facebook apps on Rails • Rails 2.3.3 • Facebook API via Facebooker • Hosted on Heroku • Monitor via NewRelic Friday, October 23, 2009
  11. 11. User model Facebook UIDs are 64-bit, so need bigint for User#id create_table :users, :id => false do |t| t.column :id, "bigint PRIMARY KEY", :null => false ... t.timestamps end Associations can be done based on user_id create_table :balloons t.column :user_id, :bigint ... t.timestamps end Friday, October 23, 2009
  12. 12. Facebooker • Wrapper for Facebook API • Facebooker::User to query user data • Facebooker::Publisher for feeds/notifications Friday, October 23, 2009
  13. 13. Facebooker • Wrapper for Facebook API • Facebooker::User to query user data • Facebooker::Publisher for feeds/notifications Friday, October 23, 2009
  14. 14. Preload FQL • Facebooker::User to query user data • Since query can take 500ms or more, use Preload FQL to pre-query the data preload_fql = Hash.new preload_fql[:preload_user_data] = { :pattern => ".*", :query => "SELECT name,birthday_date FROM user WHERE uid={*user*};" } Facebooker::Admin.new(Facebooker::Session.create).set_app_pro perties({:preload_fql => preload_fql.to_json}) • Obtain the preloaded data on every page: params[:fb_sig_user_data] Friday, October 23, 2009
  15. 15. Open Stream API • Facebooker::Publisher for feeds/notifications • Facebook has deprecated template bundles • Instead use the Open Stream API: <script> var attachment = {'media':[{'type':'image', 'src':'http:// cardinalblue.com/images/cblue_logo_white100.png', 'href':'http:// cardinalblue.com'}]}; Facebook.streamPublish('Hello Cardinal Blue', attachment); </script> Friday, October 23, 2009
  16. 16. Functional tests with facebook_get test "requires-login page, logged in" do facebook_get :install assert_response :success assert_nil facebook_redirect_url end test "requires-login page, not logged in" do # access a page that requires login facebook_get :install, :fb_sig_user => nil assert_response :success assert_not_nil facebook_redirect_url assert facebook_redirect_url.match("http://www.facebook.com/install.php") end Friday, October 23, 2009
  17. 17. Heroku Friday, October 23, 2009
  18. 18. Scaled to over 10000 requests per minute Friday, October 23, 2009
  19. 19. Heroku features • Uses nginx, thin, postgres, Amazon EC2 • Easy Deployment: git push heroku master • Flexible Scaling: heroku dynos +1 • Free Memcache: Rails.cache • Delayed Job: facebook_session.send_notification(...) facebook_session.send_later(:send_notification,...) • New Relic Friday, October 23, 2009
  20. 20. New Relic Facebooker Friday, October 23, 2009
  21. 21. Can set up custom tracers: Facebook/query Facebook/notify Facebook/feed class NewrelicTracer def self.query yield end class << self add_method_tracer :query, 'Custom/Facebook/query' end end NewrelicTracer.query do location = facebook_session.user.current_location end Friday, October 23, 2009
  22. 22. Observations • Facebook is growing • Facebook games are social • Rails + Facebooker = Facebook app • Heroku is fun (and scalable) Friday, October 23, 2009
  23. 23. Thank you. http://cardinalblue.com/about jobs@cardinalblue.com Friday, October 23, 2009

×