Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tale of a Rewrite: Lessons Learned Rewriting Ranger

Jess Martin
December 05, 2012

Tale of a Rewrite: Lessons Learned Rewriting Ranger

"Build one to throw away. You will anyway." -Fred Brooks
Few of us are brave enough to follow this advice. And yet sometimes we have to start over to move forward. With Ranger, we faced that decision. This talk discusses the rationale for the rewrite and certain key considerations we had to make during the migration.

Jess Martin

December 05, 2012
Tweet

More Decks by Jess Martin

Other Decks in Technology

Transcript

  1. Tale of a Rewrite
    Jess Martin

    View Slide

  2. About Me

    View Slide

  3. View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. He has told you, O man, what is good;
    And what does the LORD require of you but to do justice,
    and to love kindness, and to walk humbly with your God.
    - Micah 6:8

    View Slide

  8. View Slide

  9. Let’s talk tech...

    View Slide

  10. View Slide

  11. View Slide

  12. Business
    Does the rewrite significantly benefit profitability?

    View Slide

  13. Server  Costs 200.00% 400.00% 800.00% 1600.00%
    URLs  to  Monitor 500 1000 2000 4000 8000
    URLs  Per  Box 25 25 25 25 25
    Servers  Needed 20 40 80 160 320
    Monthly  Cost $799.00 $1,598.00 $3,196.00 $6,392.00 $12,784.00
    Annual  Cost $9,588.00 $19,176.00 $38,352.00 $76,704.00 $153,408.00
    Pricing  Models
    Cost  per  URL  per  month $1.60 $1.60 $1.60 $1.60 $1.60
    Price  per  URL  per  month $3.00 $3.00 $3.00 $3.00 $3.00
    Margin  per  URL  per  month $1.40 $1.40 $1.40 $1.40 $1.40
    Gross  Margin 87.73% 87.73% 87.73% 87.73% 87.73%
    Monthly  Gross  Profit $701.00 $1,402.00 $2,804.00 $5,608.00 $11,216.00
    Monthly  Gross  Revenue $1,500.00 $3,000.00 $6,000.00 $12,000.00 $24,000.00
    Annual  Profit $8,412.00 $16,824.00 $33,648.00 $67,296.00 $134,592
    URLs Per Box 25
    URLs to Monitor 500
    Cost Per Server $39.95
    Price Per URL $3.00
    Spreadsheets!

    View Slide

  14. The best developers understand the benefit to
    the business of the code they are writing.
    Assertion #1

    View Slide

  15. Architecture
    Can you scale (and understand) the system’s architecture?

    View Slide

  16. Start at the whiteboard
    Ranger Architecture Diagram
    Rails App
    Server
    Users
    Apps
    Dependencies
    Watchers
    Postgres
    (stored in Postgres for now)
    Dependency Statuses
    every 1 minute
    check dependencies
    write new status
    if needed, enqueue email
    Recon.Perform
    API
    Heroku
    User URLs being checked
    Email Queue
    (resque)
    Redis
    PostMark
    Emails
    User Terminal in App Repo
    User Browser
    Under
    Development
    curl
    heroku-ranger
    User App
    heroku addons:add ranger
    heroku addons:remove ranger
    heroku ranger
    heroku ranger dependencies:add
    heroku ranger watchers:add
    provision/deprovision

    View Slide

  17. Research with spikes
    require 'typhoeus'
    require 'json'
    api_key = "81a11b50-fd5d-012f-2d86-705681b14663"
    # Create a hydra instance
    hydra = Typhoeus::Hydra.new(:max_concurrency => 5)
    hydra.disable_memoization
    # Get a batch of dependencies to check
    response = Typhoeus::Request.get("http://localhost:3000/missions/next.json?internal_api_key=#{api_key}")
    puts response.body
    exit unless (response.code == 200) && (response.body != "null")
    dependencies = JSON.parse(response.body)
    # Queue the HTTP requests
    checks = dependencies.collect do |dependency|
    request = Typhoeus::Request.new(dependency["url"], :timeout => 5000)
    hydra.queue request
    {:id => dependency["id"], :request => request}
    end
    # Run the HTTP requests
    hydra.run
    # Build the results hash
    results = []
    checks.each do |check|
    response = check[:request].response
    result = {
    :id => check[:id],
    :code => response.code,
    :time => response.time,
    :curl_return_code => response.curl_return_code,
    :curl_error_message => response.curl_error_message
    }

    View Slide

  18. Developers need to understand the overall
    architecture in order to make smart decisions
    at the code level.
    Assertion #2

    View Slide

  19. Reliability
    Are you confident in the reliability of the rewrite?

    View Slide

  20. TDD, duh.

    View Slide

  21. One test to rule them all
    Ranger 1.0 Ranger 2.0

    View Slide

  22. Staging First

    View Slide

  23. Migration
    Will you be able to move everything to the new system?

    View Slide

  24. The three biggest risks in web development are:
    billing, reporting, and migration.
    - Jason Rudolph

    View Slide

  25. 50 active users.
    No downtime allowed.
    Checking uptime every 5 minutes.
    So, 5 minute window to make the move.

    View Slide

  26. So...

    View Slide

  27. It worked.

    View Slide

  28. View Slide

  29. Questions?

    View Slide