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

A Healthy Monolith

A Healthy Monolith

Supporting an overgrown monstrous project, a so-called Monolith that was shaped according to the tenets of the "Rails way", is a usual problem for our community. Many developers blame Rails for the fact that it allows, and even promotes, this way of project building, and that there are no tools available out of the box to make this growth healthier. I'll tell you how Evil Martians live with their own Monolith and demonstrate the that the Monolith is not in fact a problem — it's an opportunity

Nikolay Sverchkov

June 10, 2018
Tweet

More Decks by Nikolay Sverchkov

Other Decks in Programming

Transcript

  1. Monolithic
    Problems

    View Slide

  2. View Slide

  3. EVIL MARTIANS

    View Slide

  4. EVIL MARTIANS

    View Slide

  5. Nikolay Sverchkov
    @ssnickolay
    Math
    Elixir

    View Slide

  6. My name is potato

    View Slide

  7. What is a Monolith?

    View Slide

  8. https://en.wikipedia.org/wiki/Monolithic_application

    View Slide

  9. Monolithic
    Application
    is
    one git repo
    with 99%
    code base
    of project

    View Slide

  10. What is a Huge
    Monolith?

    View Slide

  11. How I can
    understand
    my Monolith
    is Huge
    or no?

    View Slide

  12. Let’s Estimate it!

    View Slide

  13. Monolith Estimation:
    by commits count

    View Slide

  14. Monolith Estimation:
    by commits count

    View Slide

  15. Cons:
    Strategy: merge or rebase?
    Monolith Estimation:
    by commits count

    View Slide

  16. Cons:
    Strategy: merge or rebase?
    Atomic commits or one commit per
    feature (Pull request)?
    Monolith Estimation:
    by commits count

    View Slide

  17. View Slide

  18. View Slide

  19. Monolith Estimation:
    by count lines of code

    View Slide

  20. View Slide

  21. Monolith Estimation:
    by count lines of code
    Pros:
    Amount of commits does not influence
    on count of code lines

    View Slide

  22. Monolith Estimation:
    by count lines of code
    Pros:
    Amount of commits does not influence
    on count of code lines
    Cons:
    There is no connection to REAL
    production

    View Slide

  23. View Slide

  24. What is it in real and what
    it seems to be

    View Slide

  25. Monolith Estimation:
    by DataBase size?

    View Slide

  26. View Slide

  27. What does
    "Large Database”
    mean?

    View Slide

  28. The size of the database for a regular
    web application can be considered as
    “Web Big Data” when the backup of this
    database cannot be restored to the
    developer computer.
    Funny Law
    of “Web BigData”

    View Slide

  29. View Slide

  30. Huge
    Monolith:
    A lot of commits +
    A lot of code lines +
    Deep Production

    View Slide

  31. Your Project Team

    View Slide

  32. Rails Project Architecture
    Shark Head

    View Slide

  33. Rails Project Architecture
    Shark Head
    Elephant Body
    +

    View Slide

  34. Rails Project Architecture
    Shark Head
    Elephant Body
    +
    Tiger and Rhino
    Legs
    +

    View Slide

  35. Rails Project Architecture
    Shark Head
    Elephant Body
    +
    Tiger and Rhino
    Legs
    +
    AND
    BLASTERS

    View Slide

  36. View Slide

  37. EVIL MARTIANS

    View Slide

  38. View Slide

  39. cloc —exclude-
    dir=log,node_modules,
    public,tmp,vendor,lurker,
    .idea ./
    https://github.com/
    AlDanial/cloc

    View Slide

  40. -------------------------------------------------------------------------------
    Language files blank comment code
    -------------------------------------------------------------------------------
    Ruby 3671 30458 3106 145366
    JSX 571 5759 43 52618
    YAML 182 90 20 33753
    JavaScript 492 3247 144 22763
    ERB 617 1569 58 18599
    Sass 480 3552 194 18024
    CoffeeScript 150 874 92 5227
    ……
    ……
    -------------------------------------------------------------------------------
    SUM: 6231 52012 7778 306167
    -------------------------------------------------------------------------------
    Fountain. 30/05/2018
    25.5k commits
    SUM: 306,167 LOC

    View Slide

  41. Is it big enough?

    View Slide

  42. Is it big enough?

    View Slide

  43. View Slide

  44. View Slide

  45. View Slide

  46. View Slide

  47. View Slide

  48. Shopify 30/05/2018
    ? commits
    SUM: ? LOC

    View Slide

  49. --------------------------------------------------------------------------------
    Language files blank comment code
    --------------------------------------------------------------------------------
    Ruby 13995 271122 19124 1290867
    YAML 1791 8962 1166 559395
    JSON 332 77 0 303475
    Sass 484 39191 4968 185032
    ERB 2584 7208 83 111490
    JavaScript 1065 22635 5956 109023
    CoffeeScript 667 12130 1003 45734
    SQL 4 14 0 28300
    TypeScript 455 3794 190 23939
    liquid 64 4391 28 21809
    ……
    ……
    --------------------------------------------------------------------------------
    SUM: 21742 376631 38507 2705978
    --------------------------------------------------------------------------------
    Shopify 30/05/2018
    306k commits
    SUM: 2.7M LOC

    View Slide

  50. Teaser for @isleofruby
    @eljojo

    View Slide

  51. Monolithic Project
    Health Level

    View Slide

  52. Monolith Health Levels
    Healthy

    View Slide

  53. Monolith Health Levels
    Normal
    Healthy

    View Slide

  54. Monolith Health Levels
    Normal
    Healthy
    Legacy

    View Slide

  55. Monolith Health Levels
    Normal
    Healthy
    Legacy

    View Slide

  56. Normal
    • Rails 4
    Healthy
    • Rails 5+
    • Rails 4 -> Rails 5 in process
    Legacy
    • Rails 3 and lower
    Monolith Healthy Level:
    by Rails version

    View Slide

  57. Normal
    • 2.3+
    Healthy
    • Last stable
    Legacy
    • 1.9* - What wrong with you, guys? >_<
    Monolith Healthy Level:
    by Ruby version

    View Slide

  58. Why we should update
    Ruby?

    View Slide

  59. Because yield_self is
    powerful feature?

    View Slide

  60. Security Vulnerabilities

    View Slide

  61. Healthy
    • Use bundler-audit
    Legacy
    • Don’t use bundler-audit
    Monolith Healthy Level:
    by gems version

    View Slide

  62. All Evil Martians projects
    use “bundler-audit”

    View Slide

  63. All Evil Martians projects
    use “bundler-audit”
    and “nsp check”

    View Slide

  64. Monolith Healthy Level:
    by Architecture

    View Slide

  65. Healthy
    • It is easy to make changes
    • You have permanent refactor for an old
    code
    Legacy
    • You use Rails way (sorry, DHH)
    • You have a bunch of different patterns
    Monolith Healthy Level:
    by Architecture

    View Slide

  66. Houston, we have a
    problem (c)

    View Slide

  67. Problem = 

    Cause + Solution

    View Slide

  68. Solution
    Cause
    I need to use
    some
    framework…
    e.g. Trailblazer!
    Rails MVC is
    sucks

    View Slide

  69. #TODO
    My opinion about
    Trailblaizer

    View Slide

  70. View Slide

  71. View Slide

  72. View Slide

  73. View Slide

  74. Saint P NickConf

    View Slide

  75. Solution
    Cause
    Rails MVC is
    sucks
    Use MCC!
    M - Model
    C - Cells
    C - Controller

    View Slide

  76. class UsersController < ApplicationController
    def show
    user = User.find(params[:id])
    render_app_cell(Users::Cell::Show, user: user)
    end
    end
    MC(ells)C Example

    View Slide

  77. class UsersController < ApplicationController
    def show
    user = User.find(params[:id])
    render_app_cell(Users::Cell::Show, user: user)
    end
    end
    class ApplicationController < ActionController::Base
    def render_app_cell(*args)
    render html: cell(*args), layout: 'application'
    end
    end
    MC(ells)C Example

    View Slide

  78. HANAMI

    View Slide

  79. Talk about Elixir at the
    Ruby Conference

    View Slide

  80. Solution
    Cause
    I can use ROM!
    ActiveRecord
    is sucks

    View Slide

  81. I

    View Slide

  82. I
    ROM

    View Slide

  83. Talk twice about Elixir at the
    Ruby Conference
    ROM.rb ~ Ecto

    View Slide

  84. Solution
    Cause
    I can use ROM!
    If you can work
    with complex
    solutions
    ActiveRecord
    is sucks

    View Slide

  85. Solution
    Cause
    Microservices!
    Monolithic
    architecture
    It’s all sucks

    View Slide

  86. Monolithic







    Microservices
    vs

    View Slide

  87. Monolithic







    Microservices
    !=

    View Slide

  88. Monolithic







    Microservices
    >

    View Slide

  89. Monolithic




    Microservices
    >


    View Slide

  90. Solution
    Cause
    Microservices!
    Good choice!
    Monolithic
    architecture
    It’s all sucks

    View Slide

  91. And Last but not to least

    View Slide

  92. Opportunity for what?

    View Slide

  93. View Slide

  94. https://
    github.com/
    palkan/
    test-prof

    View Slide

  95. https://github.com/palkan/
    clowne

    View Slide

  96. https://github.com/marshall-
    lee/sidekiq-postpone

    View Slide

  97. https://github.com/marshall-
    lee/sidekiq-postpone

    View Slide

  98. Blood Contracts

    View Slide

  99. Next: Blood Contracts
    @ssnickolay

    View Slide