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

Evolution of Rails application architecture: 14...

Evolution of Rails application architecture: 14 years in production

The story about the architecture of famous and biggest Rails projects such as Shopify, Basecamp and Cookpad.

Nikolay Sverchkov

October 07, 2018
Tweet

More Decks by Nikolay Sverchkov

Other Decks in Programming

Transcript

  1. 34TH BY POPULATION CITY IN RUSSIA THE THIRD AMONG THE

    CITIES THAT ARE NOT THE CENTRES OF THE SUBJECTS OF FEDERATIONS
  2. POPULAR GEMS Devise СanCan Will paginate Paperclip Capistrano Friendly Id

    SimleForm 2 Jan 2010 14 Dec 2009 2 Mar 2008 19 Mar 2008 24 Dec 2006 (2009) 26 Aug 2008 6 Feb 2010
  3. 2014. CHICAGO Where did the OO go? Views should be

    objects too! REFLECTION ON CODE
  4. 2014. CHICAGO •Ultra Light and Maintainable Rails Wiz… •Domain Driven

    Design and Hexagonal … •Where did the OO go? Views should … •Modeling on the Right Side of the Brain •Make an Event of It •Service Oriented Authenication •Concerns, Decorators, Presenters… •Reading Code Good •Rails as an SOA Client •Refactoring Towards Component… •Authorization in a Service-Oriented … •What is REST? Why is it Part of the … •Service Extraction at Groupon Scale REFLECTION ON CODE
  5. -------------------------------------------------------------------------------- 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
  6. КОМПАНИИ ОТКАЗЫВАЮТСЯ ОТ МОНОЛИТА НА РЕЛЬСАХ ПОТОМУ ЧТО РЕЛЬСЫ НЕ

    ПРЕДЛАГАЮТ ХОРОШИХ СПОСОБОВ ОРГАНИЗАЦИИ КОДА НА БОЛЬШОЙ КОДОВОЙ БАЗЕ
  7. COMPONENT BASED ARCHITECTURE ├── Gemfile ├── Gemfile.lock ├── README.md ├──

    components │ ├── component_a │ │ ├── │ │ ├── │ │ ├── │ │ ├── │ │ └── │ ├── component_b │ │ ├── │ │ ├── │ │ ├── │ │ ├── │ │ └── │ └── component_c │ │ ├── │ │ ├── │ │ ├── │ │ ├── │ │ └── ├── lib ├── test └── etc...
  8. COMPONENT BASED ARCHITECTURE ├── Gemfile ├── Gemfile.lock ├── README.md ├──

    components │ ├── component_a │ │ ├── README.md │ │ ├── app │ │ ├── component.yml │ │ ├── lib │ │ └── test │ ├── component_b │ │ ├── README.md │ │ ├── app │ │ ├── component.yml │ │ ├── lib │ │ └── test │ └── component_c │ │ ├── README.md │ │ ├── app │ │ ├── component.yml │ │ ├── lib │ │ └── test ├── lib ├── test └── etc...
  9. НАДО ПОНИМАТЬ, ЧТО ЛЕГАСИ МНОГО И ЕЩЕ НЕ ВСЕ ПЕРЕЕХАЛИ

    НА ENTRY POINTS. МЫ СЧИТАЕМ НЕКИЙ SCORE КАЖДОГО КОМПОНЕНТА И ОЦЕНИВАЕМ КАКИЕ ИЗ НИХ БОЛЕЕ ЛЕГАСИ ЧЕМ ОСТАЛЬНЫЕ
  10. THE FIRST BASECAMP WAS STARTED BACK IN 2004, BASECAMP 2

    WAS STARTED IN 2011, AND BC3 IN 2014
  11. STARTING A WHOLE NEW CODEBASE ALLOWS TO USE NEW, BETTER

    WAYS TO STRUCTURE OUR CODE, BASED ON THINGS WE’VE LEARNT BUILDING PREVIOUS ITERATIONS
  12. WE ALSO CREATE AN ENTIRELY NEW ARCHITECTURE, DATABASE MODEL, AND

    MORE WITH EACH ITERATION, AGAIN BASED ON WHAT WE’VE LEARNT
  13. THE PROS FOR OUR CUSTOMERS ARE THAT THEY CAN CONTINUE

    TO USE APPS THEY RELY ON UNTIL ‘THE END OF THE INTERNET’; THEY NEVER HAVE TO UPGRADE TO A NEW VERSION IF THE EXISTING VERSION WORKS FOR THEM
  14. WE DO HAVE AN INDEPENDENT SECURITY/ AUTHORISATION APP SHARED ACROSS

    ALL OUR PRODUCTS, AS WELL AS A BILLING AND ACCOUNT MANAGEMENT APP
  15. SOME REASONS MIGHT BE IF THE CODEBASE FEELS IT’S NO

    LONGER FUN TO WORK ON, IF THERE ARE NEW TECHNOLOGIES WE WANT TO COMPLETELY BASE A NEW VERSION AROUND
  16. DO YOU REALLY USE ONLY MVC AND PATTERNS BASED ON

    RAILS (E.G. SERIALIZERS)? WITHOUT ANY OTHER DESIGN PATTERNS LIKE SERVICE OBJECT, PRESENTER, FORM OBJECT AND ETC.
  17. MARTIN FOWLER DO YOU REALLY USE ONLY MVC AND PATTERNS

    BASED ON RAILS (E.G. SERIALIZERS)? WITHOUT ANY OTHER DESIGN PATTERNS LIKE SERVICE OBJECT, PRESENTER, FORM OBJECT AND ETC.
  18. WE TRY TO USE LIGHTWEIGHT CONTROLLERS, SIMPLE MODELS, AND BASIC

    PATTERNS. BUT IT’S NOT POSSIBLE TO IMPLEMENT EVERYTHING WE’D LIKE TO IN THIS WAY
  19. WE ALSO HAVE PRESENTERS, SOME CO- ORDINATING MODELS, AND EVEN

    A FEW TRANSACTION- LIKE OBJECTS FOR COMPLEX THINGS LIKE MOVES AND COPIES
  20. BC3

  21. BC3

  22. Matz (the creator of Ruby), Koichi and Mame (full-time Ruby

    committers at Cookpad) Cookpad Ruby Hack Challenge 2018
  23. IN COOKPAD GLOBAL WE HAVE A MONOLITH AND SEVERAL OTHER

    APPLICATIONS THAT COMMUNICATE BETWEEN, BUT I WOULDN’T CALL THEM MICRO SERVICES
  24. WE HAVE CREATED A FEW APPS AS SERVICES THAT WE

    HAVE MERGE INTO OUR MONOLITH AFTER WE’VE SEEN THAT IT INTRODUCED MORE PROBLEMS THAN THE ONES IT FIXED
  25. WE’RE STARTING TO BUILD A BUNCH OF DISTRIBUTED SERVICES RELYING

    ON EVENT SOURCING BECAUSE IT MAKES OUR LIVES EASIER
  26. WE’RE STARTING TO BUILD A BUNCH OF DISTRIBUTED SERVICES RELYING

    ON EVENT SOURCING BECAUSE IT MAKES OUR LIVES EASIER Events? Great!
  27. Takamichi Yoshikawa Cat allergy [Ex] Software engineer COOKPAD Inc. Sunao

    Hogelog Software engineer di クックパッド
  28. WE USED SYMLINKS AT FIRST. WE EXTRACTED "SHARED" CODES TO

    A DIRECTORY, AND ALL RAILS APPLICATIONS REFERS IT VIA SYMLINK
  29. GOT A PROBLEM WITH SHARED CODE - DIFFICULT TO DO

    CHANGES, DIFFICULT TO COORDINATE COMMANDS, DIFFICULT TO TRACK DEPENDENCIES AND APPS HAD MONKEY PATCHING OF SHARED LOGIC
  30. -------------------------------------------------------------------------------- Language files blank comment code -------------------------------------------------------------------------------- Ruby 1778 34618

    4380 171259 Sass 817 17876 449 110313 Haml 3273 10047 649 83502 YAML 37 450 313 33705 CoffeeScript 296 2246 329 11993 JavaScript 95 832 409 5560 ERB 225 814 51 5293 C 1 86 10 635 Bourne Shell 6 78 77 289 Bourne Again Shell 10 34 0 157 builder 2 4 0 86 Markdown 3 25 0 46 Perl 2 12 0 38 Ruby HTML 1 0 0 12 CSS 1 0 0 1 -------------------------------------------------------------------------------- SUM: 6547 67122 6667 422889 -------------------------------------------------------------------------------- COOKPAD 27/09/2018 THE MOST HUGE APP SUM: 422K LOC