facebook on rails

Post on 29-Aug-2014

7.130 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Some observations on Facebook development using Ruby on Rails, Heroku, Facebooker, New Relic Presented at Ruby Tuesday, Taipei, 2009.10.20

TRANSCRIPT

Facebook on Rails

CardinalBlue

Ruby Tuesday 2009.10.20

info@cardinalblue.com

Friday, October 23, 2009

300 million Facebook users around the world

40% of all Internet Users in North America

are on Facebook!

Friday, October 23, 2009

Facebook Trends (台灣)

73 天後*用戶者成長了三倍

*連續幾個禮拜成長率世界第一

女性使用者稍多

學生與白領階級居

Friday, October 23, 2009

Facebook Apps Boom

Friday, October 23, 2009

Friday, October 23, 2009

Demographic Trends

• More female gamers

• More younger (ages 8-15) gamers

• More older (ages 50+) gamers

Friday, October 23, 2009

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

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

FBML Application Architecture

Friday, October 23, 2009

Facebook apps on Rails

• Rails 2.3.3

• Facebook API via Facebooker

• Hosted on Heroku

• Monitor via NewRelic

Friday, October 23, 2009

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 :balloonst.column :user_id, :bigint...t.timestamps

end

Friday, October 23, 2009

Facebooker

• Wrapper for Facebook API

• Facebooker::User to query user data

• Facebooker::Publisher for feeds/notifications

Friday, October 23, 2009

Facebooker

• Wrapper for Facebook API

• Facebooker::User to query user data

• Facebooker::Publisher for feeds/notifications

Friday, October 23, 2009

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.newpreload_fql[:preload_user_data] = { :pattern => ".*", :query => "SELECT name,birthday_date FROM user WHERE uid={*user*};"}

Facebooker::Admin.new(Facebooker::Session.create).set_app_properties({:preload_fql => preload_fql.to_json})

• Obtain the preloaded data on every page: params[:fb_sig_user_data]

Friday, October 23, 2009

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

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

Heroku

Friday, October 23, 2009

Scaled to over 10000 requests per minute

Friday, October 23, 2009

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

New Relic

Facebooker

Friday, October 23, 2009

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' endend

NewrelicTracer.query do location = facebook_session.user.current_locationend

Friday, October 23, 2009

Observations

• Facebook is growing

• Facebook games are social

• Rails + Facebooker = Facebook app

• Heroku is fun (and scalable)

Friday, October 23, 2009

Thank you. 謝謝觀賞

http://cardinalblue.com/about

jobs@cardinalblue.com

Friday, October 23, 2009

top related