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

Taming Monoliths without Microservices - RubyConf AU 2019

Kelly Sutton
February 07, 2019

Taming Monoliths without Microservices - RubyConf AU 2019

Kelly Sutton

February 07, 2019
Tweet

More Decks by Kelly Sutton

Other Decks in Programming

Transcript

  1. TAMING MONOLITHS
    WITHOUT MICROSERVICES
    Kelly Sutton — Rubyconf AU 2019

    View Slide

  2. Overview
    I. About Me

    II. Breaking the Monolith

    III. Tactics

    IV. Wrap Up
    kellysutton.com

    View Slide

  3. Part I:

    About Me

    View Slide

  4. About Me

    View Slide

  5. About Greta

    View Slide

  6. About Greta

    View Slide

  7. About Greta

    View Slide

  8. About Greta

    View Slide

  9. But that’s not why we’re here
    kellysutton.com

    View Slide

  10. We’re here to talk about Rails
    projects that push the limits
    kellysutton.com

    View Slide

  11. kellysutton.com

    View Slide

  12. Time Geography
    Money People
    kellysutton.com

    View Slide

  13. Correctness > Performance
    kellysutton.com

    View Slide

  14. What goes wrong,
    when things get too big
    kellysutton.com

    View Slide

  15. Part II:

    Breaking the Monolith

    View Slide

  16. The Swamp
    kellysutton.com

    View Slide

  17. View Slide

  18. kellysutton.com

    View Slide

  19. kellysutton.com

    View Slide

  20. The Swamp
    Payroll
    HR
    Benefits
    Infra
    kellysutton.com

    View Slide

  21. “Let’s Extract a Service!”
    kellysutton.com

    View Slide

  22. Photo by Thomas Halfmann
    kellysutton.com

    View Slide

  23. The Swamp
    Payroll
    HR
    Benefits
    Infra
    kellysutton.com

    View Slide

  24. The Swamp
    Payroll
    HR
    Benefits
    Infra
    kellysutton.com

    View Slide

  25. The Swamp
    Payroll
    HR
    Benefits
    Infra
    HR v2
    kellysutton.com

    View Slide

  26. The Swamp
    Payroll
    HR
    Benefits
    Infra
    HR v2
    kellysutton.com

    View Slide

  27. The Swamp
    Payroll
    Old HR
    Benefits
    Infra
    HR v2
    kellysutton.com

    View Slide

  28. But there is a better way

    View Slide

  29. kellysutton.com

    View Slide

  30. Employee
    HR Payroll
    kellysutton.com

    View Slide

  31. Employee
    HR Payroll
    kellysutton.com

    View Slide

  32. Employee
    HR Payroll
    employee.last_name
    kellysutton.com

    View Slide

  33. HR Payroll
    kellysutton.com

    View Slide

  34. HR Payroll
    kellysutton.com

    View Slide

  35. HR Payroll
    Employee PayrollEmployee
    kellysutton.com

    View Slide

  36. HR Payroll
    Employee PayrollEmployee
    kellysutton.com

    View Slide

  37. HR Payroll
    Employee PayrollEmployee
    payroll_employee.last_name
    kellysutton.com

    View Slide

  38. HR Payroll
    kellysutton.com

    View Slide

  39. HR Payroll
    kellysutton.com

    View Slide

  40. Value Objects
    HR Payroll
    kellysutton.com

    View Slide

  41. Conceptual
    Compression

    View Slide

  42. Conceptual
    Expansion

    View Slide

  43. Part III:

    Tactics

    View Slide

  44. Recommendation #1

    Mind and Avoid Circular
    Dependencies
    kellysutton.com

    View Slide

  45. As your Rails code base grows,
    question bidirectional relationships
    kellysutton.com

    View Slide

  46. 1 # app/models/company.rb
    2 class Company < ApplicationRecord
    3 has_many :employees
    4 end
    5
    6 # app/models/employee.rb
    7 class Employee < ApplicationRecord
    8 belongs_to :company
    9 end
    kellysutton.com

    View Slide

  47. 1 # app/models/company.rb
    2 class Company < ApplicationRecord
    3 has_many :employees
    4 end
    5
    6 # app/models/employee.rb
    7 class Employee < ApplicationRecord
    8 belongs_to :company
    9 end
    Do we need this?
    kellysutton.com

    View Slide

  48. Company Employee
    kellysutton.com

    View Slide

  49. Company Employee
    kellysutton.com

    View Slide

  50. Recommendation #2

    Use Value Objects to
    Traverse Edges
    kellysutton.com

    View Slide

  51. 1 # app/services/company_signed_up.rb
    2 class CompanySignedUp
    3 def self.call(company)
    4 CompanyMailer.welcome_email(company)
    5 StatsTracker.company_signed_up(company)
    6 end
    7 end
    kellysutton.com

    View Slide

  52. 1 # app/services/company_signed_up.rb
    2 class CompanySignedUp
    3 def self.call(company)
    4 user_first_name = company.admin_first_name
    5 email = company.admin_email
    6
    7 CompanyMailer.welcome_email(email, user_first_name)
    8 StatsTracker.company_signed_up(company.id)
    9 end
    10 end
    kellysutton.com

    View Slide

  53. Recommendation #3

    Avoid Callbacks
    kellysutton.com

    View Slide

  54. 1 # app/models/company.rb
    2 class Company < ApplicationRecord
    3 after_create :send_update_email, if: :has_email?
    4
    5 private
    6
    7 def send_update_email
    8 CompanyMailer.welcome_email(self)
    9 end
    10 end
    kellysutton.com

    View Slide

  55. Company CompanyMailer
    kellysutton.com

    View Slide

  56. 1 # app/services/create_company.rb
    2 class CreateCompany
    3 def self.call(company_params)
    4 company = Company.create!(company_params)
    5
    6 CompanyMailer.welcome_email(company)
    7 end
    8 end
    kellysutton.com

    View Slide

  57. Company CompanyMailer
    CreateCompany
    kellysutton.com

    View Slide

  58. Recommendation #4

    Move slowly!
    kellysutton.com

    View Slide

  59. Part IV:

    Wrap Up
    kellysutton.com

    View Slide

  60. –Kent Beck
    “Make the hard change easy
    (this may be hard),
    then make the easy change.”
    kellysutton.com

    View Slide

  61. Thanks!
    Slides and more available at kellysutton.com

    View Slide

  62. References
    • Bernhardt, Gary. “Boundaries.” 2012.

    • Bernhardt, Gary. “Functional Core, Imperative Shell.” 2012.

    • Evans, Eric. “Domain-Driven Design: Tackling Complexity in the Heart of Software.” 2003.

    • Fowler, Martin, et al. “Refactoring: Improving the Design of Existing Code.” 1999.

    • Feathers, Michael. “Working Effectively with Legacy Code.” 2004.

    • Hickey, Rich. “Simple Made Easy.” 2011.

    • Hickey, Rich. “The Value of Values.” 2012.

    • Scott, James C. “Seeing Like a State.” 1999.

    • Searls, Justin. “My Preferred Method of TDD.” 2017

    • Spolsky, Joel. “Things You Should Never Do, Part I.” 2006.

    View Slide

  63. Special Thanks
    • Noa Elad

    • Matan Zruya

    • Sihui Huang

    • Natalie Wong

    • Karlo Hoa

    • Amelie Meyer-Robinson

    • Quentin Balin

    View Slide