SlideShare a Scribd company logo
Facebook on Rails

                              CardinalBlue
                              info@cardinalblue.com

                              Ruby Tuesday 2009.10.20


Friday, October 23, 2009
40% of all
                                       Internet Users in
                                        North America
                                             are on
                                           Facebook!



              300 million Facebook users around the world
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 :balloons
                                t.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.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
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'
             end
           end

           NewrelicTracer.query do
             location = facebook_session.user.current_location
           end

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

More Related Content

PDF
News21 Social Networking
PDF
Doonish
PPT
期末專題報告:嵌入式系統之影像處理器
PPT
Tyler Projects talk at the Facebook Developer Garage--Taiwan
PPTX
Facebook developers garage taiwan 2010--Jia Shen's presentation
KEY
Graph API - Facebook Developer Garage Taipei
PDF
Google Developer Days Brazil 2009 - Make your site social with Google Friend ...
ZIP
Promiscuous Drupal
News21 Social Networking
Doonish
期末專題報告:嵌入式系統之影像處理器
Tyler Projects talk at the Facebook Developer Garage--Taiwan
Facebook developers garage taiwan 2010--Jia Shen's presentation
Graph API - Facebook Developer Garage Taipei
Google Developer Days Brazil 2009 - Make your site social with Google Friend ...
Promiscuous Drupal

Similar to Facebook on Rails (18)

PDF
BuddyPress and the Future of WordPress Plugins
PDF
It's a beautiful day in your (online) neighborhood
PDF
Social Media and Your (online) Neighborhood
PDF
URIplay for Media Futures Conference (2009)
PPTX
Hacking And Hosting Hot Potatoes
PDF
Health Care Social Media Summit Keynote
PDF
Kevin Coughlin Brand Presentation TCNJ 9/23/13
PDF
Strategies Tech It Up
PDF
All The Little Pieces
PDF
Using Drupal
PDF
Social Media and philanthropy - tracking the buzz, making connections
PDF
NoTube User Model slides
PDF
Education Wants To Be Free
PDF
URIplay for Open Video Conference (2009)
PPTX
Creative Commons in Practice: Application, Search and Attribution - Cheryl Fo...
PDF
Cloud Computing Presentation - Kenosee Retreat 2013
PDF
Vincent Evers Trendwatcher High Profile New Media Congres 091123114846 Phpapp01
PDF
Highprofile New Media Congres
BuddyPress and the Future of WordPress Plugins
It's a beautiful day in your (online) neighborhood
Social Media and Your (online) Neighborhood
URIplay for Media Futures Conference (2009)
Hacking And Hosting Hot Potatoes
Health Care Social Media Summit Keynote
Kevin Coughlin Brand Presentation TCNJ 9/23/13
Strategies Tech It Up
All The Little Pieces
Using Drupal
Social Media and philanthropy - tracking the buzz, making connections
NoTube User Model slides
Education Wants To Be Free
URIplay for Open Video Conference (2009)
Creative Commons in Practice: Application, Search and Attribution - Cheryl Fo...
Cloud Computing Presentation - Kenosee Retreat 2013
Vincent Evers Trendwatcher High Profile New Media Congres 091123114846 Phpapp01
Highprofile New Media Congres
Ad

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
Teaching material agriculture food technology
PDF
cuic standard and advanced reporting.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Spectroscopy.pptx food analysis technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
Programs and apps: productivity, graphics, security and other tools
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Teaching material agriculture food technology
cuic standard and advanced reporting.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Ad

Facebook on Rails

  • 1. Facebook on Rails CardinalBlue info@cardinalblue.com Ruby Tuesday 2009.10.20 Friday, October 23, 2009
  • 2. 40% of all Internet Users in North America are on Facebook! 300 million Facebook users around the world Friday, October 23, 2009
  • 3. Facebook Trends ( ) 73 Friday, October 23, 2009
  • 4. Facebook Apps Boom Friday, October 23, 2009
  • 6. Demographic Trends • More female gamers • More younger (ages 8-15) gamers • More older (ages 50+) gamers Friday, October 23, 2009
  • 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. 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. FBML Application Architecture Friday, October 23, 2009
  • 10. Facebook apps on Rails • Rails 2.3.3 • Facebook API via Facebooker • Hosted on Heroku • Monitor via NewRelic Friday, October 23, 2009
  • 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. Facebooker • Wrapper for Facebook API • Facebooker::User to query user data • Facebooker::Publisher for feeds/notifications Friday, October 23, 2009
  • 13. Facebooker • Wrapper for Facebook API • Facebooker::User to query user data • Facebooker::Publisher for feeds/notifications Friday, October 23, 2009
  • 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. 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. 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
  • 18. Scaled to over 10000 requests per minute Friday, October 23, 2009
  • 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. New Relic Facebooker Friday, October 23, 2009
  • 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. Observations • Facebook is growing • Facebook games are social • Rails + Facebooker = Facebook app • Heroku is fun (and scalable) Friday, October 23, 2009
  • 23. Thank you. http://cardinalblue.com/about jobs@cardinalblue.com Friday, October 23, 2009