Thinking Small
Big things, small packages, yadda yadda




Ben Scofield / @bscofield
RubyNation / 2 April 2011
Specialization
Resource Usage
Big vs. Small
Hey, That’s me!
THIS VPS rockS!
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
MONOLITH

          ADMIN       SEARCH   PAYMENTS



            API       PUBLIC     DATA



          REPORTS      HELP    CACHING


TWITTER
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
Like, WHOA
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
Hmmmm.
M1

ADMIN



  API



REPORTS
M1

ADMIN



  API



REPORTS

    Ow, Quit It!
Ow, Quit It!
 M1                 M2

ADMIN              SEARCH



  API              PUBLIC



REPORTS             HELP

    Ow, Quit It!
Ow, Quit It!
 M1                 M2                    M3

ADMIN              SEARCH             PAYMENTS



  API              PUBLIC                 DATA



REPORTS             HELP              CACHING

    Ow, Quit It!                   Ow, Quit It!
Shared Hosting,
   AIYEEEE!
ADMIN
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
Lame! Any
other reasonS?
Bye now!
Smaller Is Better
(bear with me)
Classes
Small classes are easier to:
design
build
test
debug
replace
reuse
understand
SOLID
SOLID
Single Responsibility Principle
SOLID
   Interface Segregation Principle
Demeter Principle
MVC
Applications
Small apps are easier to:
design
build
test
debug
scale
replace
reuse
purchase
Design
BDUF
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
LDUF
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
Mockable
Build
Build == Start
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
Ship It!
Baby Steps
Easy to Start,
Easy to Finish,
Motivating
red red green refactor
red green refactor
ASIDE:
$ rake test
.........F............
$ rake test
......................
Test
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA     API



REPORTS      HELP    CACHING
red green refactor
Debug
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA     API



REPORTS      HELP    CACHING
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA     API



REPORTS      HELP    CACHING
Scale
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
MONOLITH              M1

ADMIN       SEARCH   PAYMENTS   DATA



  API       PUBLIC



REPORTS      HELP    CACHING
MONOLITH                      M1

ADMIN       SEARCH   PAYMENTS          DATA



  API       PUBLIC
                                Ow, Quit It!

REPORTS      HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
ADMIN     SEARCH    PAYMENTS

                   DATA
                    DATA
                     DATA
                      DATA
  API     PUBLIC       DATA
                        DATA



REPORTS    HELP      CACHING
BL
                                               AT
                                                 AN
                                                    T
                                                    PL
                                                      UG
$ heroku addons:upgrade shared-database:20gb
or, you know, sharding and stuff
Replace
Hey, my search sucks.
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
Should I write this in   ?
Reuse
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
Purchase
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
Thanks for bearing with me:
But I’m already doing that!
How distinct are your functions?
Tests never lie
Code changes never lie
How do we do it?
You’re already doing it!
Caching
Payments
Search
Databases
The Past
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
ADMIN     SEARCH   PAYMENTS



  API     PUBLIC     DATA



REPORTS    HELP    CACHING
Integration Tests
Isolate
Hey, my search sucks.
MONOLITH

ADMIN       SEARCH   PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
SEARCH
# in the application
Article.where(['title LIKE ?', q])

Article.where(['tag_list LIKE ? OR title LIKE ?', q, q])

# ...
# in the application
Article.search(q)

Article.search(query, :include => [:tags])

# article.rb
class Article < ActiveRecord::Base
  def self.search(query, options = {})
    if options.empty?
      where(['title LIKE ?', query])
    else
      # ...
    end
  end
end
Integration Tests: pass
Replace
# Gemfile
gem 'texticle'

# article.rb
class Article < ActiveRecord::Base
  index 'title' do
    title
  end

 index 'full' do
   title
   tag_list
 end

 def self.search(query, options = {})
   if options.empty?
     search_title(query)
   else
     # ...
   end
 end

end
Integration Tests: pass
SEARCH



          MONOLITH

ADMIN                PAYMENTS



  API       PUBLIC     DATA



REPORTS      HELP    CACHING
Repeat!
THE FUTURE
Integration Tests
Plan for Modularity
Look for Opportunities
UG
             PL
         T
    AN
  AT
BL
API-Driven Design
API-Driven Design
HTTP and REST
Discoverability
API
ADMIN


      updates                 schema
PUT / POST / DELETE           what is editable?



                      DATA
SEARCH


 metadata / data
 what should we index?



 DATA
query
PUBLIC             SEARCH
         results
                    metadata / data
                    what should we index?



                    DATA
query
PUBLIC             SEARCH
         results
                    metadata / data
                    what should we index?



                    DATA
Mountable Apps
Think Small
Smaller Is Worse?
M1

ADMIN



  API



REPORTS
M1

ADMIN



  API



REPORTS
             Ow! ...
        Hey, that wasn’t
             so bad
M1

ADMIN



  API



REPORTS
             Ow! ...
        Hey, that wasn’t
             so bad
Latency
Reliability
Ben Scofield / @bscofield
http://spkr8.com/t/7028
http://benscofield.com
THANKS!

     Ben Scofield / @bscofield
     http://spkr8.com/t/7028
     http://benscofield.com

Thinking Small