Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Service Oriented Applications

1,685 views

Published on

or how we built letitcast.com

Published in: Technology, Education
  • Be the first to comment

Service Oriented Applications

  1. 1. Service OrientedApplicationsHow we built letitcast.com, Ruby Lugdunum, June 26, 2011Michael BensoussanDeveloper
  2. 2. Service OrientedApplications cc @elise_huardHow we built letitcast.com, Ruby Lugdunum, June 26, 2011Michael BensoussanDeveloper
  3. 3. Service OrientedApplicationsHow we built letitcast.com, Ruby Lugdunum, June 26, 2011 Monolithic applications are boooring ! cc @apotonickMichael BensoussanDeveloper
  4. 4. Tons of
  5. 5. It was a
  6. 6. MySQLFront-end
  7. 7. Redis MySQL API for FTP Rails API users and dir. (sinatra)ConfigsEngine video uploaded Client Library on FTP notifier (sinatra) Rails Rails Frontend 1 Frontend 2 Rails Frontend 3 Configs Auth Engine Engine
  8. 8. What did we
  9. 9. Scale With Code Complexity
  10. 10. Scale With Team Size
  11. 11. Monolithic applications don’tscale
  12. 12. Let’s build an API and multiple Front-ends
  13. 13. Choose a communication layerand a serialization format
  14. 14. We choose HTTP
  15. 15. We choose HTTP andJSON
  16. 16. Build theAPI !
  17. 17. Tip: don’t load therails libs you don’t need
  18. 18. require "rails/all"
  19. 19. # Pick the frameworks you want:require "active_record/railtie"require "action_controller/railtie"require "action_mailer/railtie"# require "active_resource/railtie"require "rails/test_unit/railtie"
  20. 20. [ ActionDispatch::Flash, ActionDispatch::Session::CookieStore, ActionDispatch::Cookies, ActionDispatch::Static].each do |klass| config.middleware.delete klassend
  21. 21. Tip: Build the APIresponse
  22. 22. fabrik42 / acts_as_api
  23. 23. class User < ActiveRecord::Base acts_as_api api_accessible(ApiAccessible.init(:user)) def name "#{user.firstname} #{user.lastname}" endend
  24. 24. :user: :default: - :id - :name :full: - :id - :name - :birthday - :created_at - :updated_at
  25. 25. def show user = User.find(params[:id]) render_for_api :full, :json => userend
  26. 26. MySQLRails API
  27. 27. Build your ClientLibrary
  28. 28. citizencast / restparty
  29. 29. class Casting < LetitCastClient resource_for :castings, :except => [:delete], :association => [:parts, :productions], :member => { :add_production => :post, :remove_production => :delete }, :collection => {:search => :get}end Casting.find(:all) # GET /castings.json casting = Casting.find(42) # GET /castings/42.json parts = casting.parts # GET /castings/42/parts.json Casting.delete(1) # DEL /castings/1 Casting.search(:q => "Mike") # GET /castings/search?q=Mike
  30. 30. class Casting < LetitCastClient resource_for :castings, :except => [:delete], :association => [:parts, :productions], :member => { :add_production => :post, :remove_production => :delete }, :collection => {:search => :get}end Casting.find(:all) # GET /castings.json casting = Casting.find(42) # GET /castings/42.json parts = casting.parts # GET /castings/42/parts.json Casting.delete(1) # DEL /castings/1 Casting.search(:q => "Mike") # GET /castings/search?q=Mike
  31. 31. MySQL Rails APIClient Library Rails Frontend 1
  32. 32. MySQL Rails API Client Library Rails RailsFrontend 1 Frontend 2
  33. 33. Rails Engines !
  34. 34. Rails 3 Rails 3.1gem install enginex rails plugin new auth --fullenginex auth
  35. 35. Rails 3 Rails 3.1gem install enginex rails plugin new auth --fullenginex auth
  36. 36. MySQL Rails API Client Library Rails RailsFrontend 1 Frontend 2 Configs Auth Engine Engine
  37. 37. HTTP is slow !
  38. 38. Cache !
  39. 39. jodosha / redis-store
  40. 40. Redis Cache Invalidate HTTP calls CacheFrontends Rails API
  41. 41. def show @casting = Rails.cache.fetch("controller/castings/#{params[:id]}") do Casting.find(params[:id]) endend
  42. 42. class CastingSweeper < ActionController::Caching::Sweeper observe Casting def after_save(casting) Rails.cache.delete_matched("controller/castings/index*") Rails.cache.delete_matched("controller/castings/#{casting.id}*") endend
  43. 43. Redis MySQL Rails API Client Library Rails RailsFrontend 1 Frontend 2 Configs Auth Engine Engine
  44. 44. Redis MySQL API for FTP Rails API users and dir. (sinatra)ConfigsEngine video uploaded Client Library on FTP notifier (sinatra) Rails Rails Frontend 1 Frontend 2 Rails Frontend 3 Configs Auth Engine Engine
  45. 45. Questions?

×