SOA AND RUBY ON RAILS
           a product case study for NYC on Rails




Avi Flombaum                                July 6th 2011
DesignerPages.com                           Infogroup
WHAT’S A SERVICE?
      a system that responds to HTTP Requests,
       usually to write, retrieve, or modify data.

    Service                                                       Client

Amazon AWS: S3                                           DesignerPages.com
                              HTTP PUT
    PUT /ergoergo.jpg HTTP/1.1
    Host: designerpages.amazonaws.com
    Date: Wed, 12 Oct 2009 17:50:00 GMT
    Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE=
    Content-Type: text/plain
    Content-Length: 11434
    Expect: 100-continue
    [11434 bytes of object data]
WHAT’S A SERVICE?
      Services can be internal.

“If you hit the Amazon.com gateway
page, the application calls more than
   100 services to collect data and
     construct the page for you.”
 Werner Vogels, Amazon.com CTO
INTERNAL SERVICES



              loads via 4 requests, total time10ms
    10ms           4ms              1ms              9ms


New For You      Recommendations      Ad Units       Bestsellers
BUT WHY SOA?
Isolation (encapsulation)

       rails application

  Product         Authentication
   News
                    Search



             DB
BUT WHY SOA?
                         Isolation
news.designerpages.com               designerpages.com


       Sinatra                            Rails
      Application                       Application




         DB                                 DB
BUT WHY SOA?
                    Benefits of Isolation
•Robustness
    You can upgrade an underlying system without effecting
    clients
•Scalability
    Each isolated system can scale independently
•Organization
    Isolated systems are easy for teams to work on
•Testing
    An encapsulated system is easier to test, single functionality
•Agility
    You can make gradual improvements to smaller systems
BUT WHY SOA?
                 And some more
•Speed
   Parallel Requests
•Interoperability
   Instant API
•Reuse
   Client wrappers
BUT WHY SOA?
And finally, a practical reason
THE RUBY SOA TOOLSET
                Sinatra - http://www.sinatrarb.com/
 Sinatra is a DSL for quickly creating web applications in
 Ruby with minimal effort:
# myapp.rb
require 'rubygems'
require 'sinatra'

get '/' do
  'Hello world!'
end

#=>   ruby myapp.rb
#=>   == Sinatra/1.2.1 has taken the stage   on 4567 for development
#=>   >> Thin web server (v1.2.11 codename   Bat-Shit Crazy)
#=>   >> Maximum connections set to 1024
#=>   >> Listening on 0.0.0.0:4567, CTRL+C   to stop
#=>   127.0.0.1 - - [06/Jul/2011 06:48:25]   "GET / HTTP/1.1" 200 12 0.0038

#=> curl http://localhost:4567
#=> Hello world!
THE RUBY SOA TOOLSET
                     httparty - a party in your http
 A simple module that turns a class into a basic HTTP
 wrapper.
require 'rubygems'
require 'httparty'

class Twitter
  include HTTParty
  base_uri 'search.twitter.com'
  format :json
end

Twitter.get('/search.json', :query => {:q => "#rubyonrails"})
['results'].first['text']
#=> "Who is going to NYC on Rails tonight? http://dsgnr.us/qrdh21 #rubyonrails"
NOW FOR SOME CODE...
THANKS!

SOA on Rails

  • 1.
    SOA AND RUBYON RAILS a product case study for NYC on Rails Avi Flombaum July 6th 2011 DesignerPages.com Infogroup
  • 2.
    WHAT’S A SERVICE? a system that responds to HTTP Requests, usually to write, retrieve, or modify data. Service Client Amazon AWS: S3 DesignerPages.com HTTP PUT PUT /ergoergo.jpg HTTP/1.1 Host: designerpages.amazonaws.com Date: Wed, 12 Oct 2009 17:50:00 GMT Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE= Content-Type: text/plain Content-Length: 11434 Expect: 100-continue [11434 bytes of object data]
  • 3.
    WHAT’S A SERVICE? Services can be internal. “If you hit the Amazon.com gateway page, the application calls more than 100 services to collect data and construct the page for you.” Werner Vogels, Amazon.com CTO
  • 5.
    INTERNAL SERVICES loads via 4 requests, total time10ms 10ms 4ms 1ms 9ms New For You Recommendations Ad Units Bestsellers
  • 6.
    BUT WHY SOA? Isolation(encapsulation) rails application Product Authentication News Search DB
  • 7.
    BUT WHY SOA? Isolation news.designerpages.com designerpages.com Sinatra Rails Application Application DB DB
  • 8.
    BUT WHY SOA? Benefits of Isolation •Robustness You can upgrade an underlying system without effecting clients •Scalability Each isolated system can scale independently •Organization Isolated systems are easy for teams to work on •Testing An encapsulated system is easier to test, single functionality •Agility You can make gradual improvements to smaller systems
  • 9.
    BUT WHY SOA? And some more •Speed Parallel Requests •Interoperability Instant API •Reuse Client wrappers
  • 10.
    BUT WHY SOA? Andfinally, a practical reason
  • 11.
    THE RUBY SOATOOLSET Sinatra - http://www.sinatrarb.com/ Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort: # myapp.rb require 'rubygems' require 'sinatra' get '/' do 'Hello world!' end #=> ruby myapp.rb #=> == Sinatra/1.2.1 has taken the stage on 4567 for development #=> >> Thin web server (v1.2.11 codename Bat-Shit Crazy) #=> >> Maximum connections set to 1024 #=> >> Listening on 0.0.0.0:4567, CTRL+C to stop #=> 127.0.0.1 - - [06/Jul/2011 06:48:25] "GET / HTTP/1.1" 200 12 0.0038 #=> curl http://localhost:4567 #=> Hello world!
  • 12.
    THE RUBY SOATOOLSET httparty - a party in your http A simple module that turns a class into a basic HTTP wrapper. require 'rubygems' require 'httparty' class Twitter include HTTParty base_uri 'search.twitter.com' format :json end Twitter.get('/search.json', :query => {:q => "#rubyonrails"}) ['results'].first['text'] #=> "Who is going to NYC on Rails tonight? http://dsgnr.us/qrdh21 #rubyonrails"
  • 13.
    NOW FOR SOMECODE...
  • 14.

Editor's Notes