Ruby Backend Engineering:   ,  
 


      backend-  Ruby on Rails.   Rails      CRUD-,        ,     .       , API-first , ,   PostgreSQL, ActiveRecord, , Redis, Elasticsearch, , Docker, AWS-, ,    .          :      ,   ,    .   ,    Ruby on Rails,          production-.    ,   senior-,  .





 

Ruby Backend Engineering:   ,  



Ruby Backend Engineering:   ,  



2025







          ,      HTML-                .      .   ,        ,   ,      .

   ,    - .          ,     .   .   :  ,  ,     .    ,      .

       ,     .    ,  ,    ,  .



   

  backend-  Ruby on Rails,        CRUD,       , ,     .         Ruby  open source   .

    .    : Ruby    , Rails   CRUD,    , API-first ,    .      : PostgreSQL  production, ActiveRecord    ,   , Redis, Elasticsearch,  .     production: Docker, AWS-, , , .      :  ,  ,  -,  , , open source.

    ,     :      production    .

   










    .        .            ,      .                     WorldSkills Russia   -.

         Ruby on Rails .  : CRM-  - ,  -  , -   .    ,  ,  .

 2020     ,       .          ,       ,     .        ,     Rails back + Rails front  Rails API + Nuxt,    ,        ,         .

    :     Ruby,  ,       middle+.       .



    

   ,    Ruby on Rails    : ,   ,      .  ,            production.  ,      senior-   ,        .

    ,      senior     .  ,    ,     ,   ,     .

     Ruby. ,      Ruby  Rails.    ,     .



   

         .     ,           .

            .      ,           .

          .        . Production-         .




 I.

Ruby  Rails    backend





 1. RUBY    





          Ruby,    .    ,   WorldSkills,       ,   ,    ,     .       .   ,   .

   :            .   ,     . Ruby     , ,   .         ,         ,    .

    ,  Ruby     .       (     ),          .  , , ,  ,    .     ,    ,   .




1.1.  Ruby     ,    


    : Ruby    ,     .      .  Ruby  ,   ,   .        ,      .

 ( ,  Ruby)       ,     ,    .    ,      ,    .     C  Java,     ,   ,     .  Ruby      ,   .

  . ,        ,     .      ,       .  Ruby   :



Application.where(user: user).active.created_after(30.days.ago)



        .   ,      (scopes)  ActiveRecord,     .          .    ,     .

   :     ,     .    .    ,           .

      ,     .     ,       : ,  ,  ,  ,  .          ,       ,     .

Ruby    ,         .              .    Ruby      . , ,            ,    ,      .

   .             .










Ruby   ,      ,   .   ,       .  ,       ,     .         ,      ,   .

   ,     ,       ,    .     ,    : CRM-  - ,  -,       . ,       ,        .




1.2.   Ruby: , ,    


 Ruby   .        ,    .   ,      ,        .

 42  Ruby     Integer.  hello    String.  MyService   ,   Class.  ,        ,   ,    .    : ,      ,   ,  Ruby  .

      ?     -:  ,  ,   .       ,   ,   .         .    -       . Ruby          .

  .   Ruby         (mixin)   .      :     ,      .          include,        .

        .   - :  ,      ,       ?  Ruby    .

   :             (, , ),        .   :    ,  ,  , .          ,    Auditable      . ,  ,     .












  Ruby   ,     (, , )  -     .   ,   .      ,       Ruby  .    ,      ,    .

 ,         .          :    ,     ,    .     -            ,       .                ,    .







     .      ,    - .  :   Ruby-,     ,       Ruby-?




1.3.  Ruby       Ruby-


         ,      Ruby,     .  ,  ,     -  .     .

  ?     ,         .     Ruby-     .   ,     ,   Ruby,      ,       .

 .    Java          :









    .   :    ,  ,   .  :  ,   ,  .     ,     ,    ,    .

    .           .       ,   (     )        .       .

 :      .     ,         .   :         ?           Ruby, ,    .







      ,  ,      .           .       ,   .




1.4. :    ,    


     ,       .     define_method, method_missing, class_eval   ,   Ruby .          production.     .   ,  .

    Ruby?           .      .      .        .   :            Rails.

 ActiveRecord.     User < ApplicationRecord,    find, where, create, update, destroy          . ActiveRecord        -   .      :        .

  ,    .       ,    .    ,   .       render_details       .    .     .      ,     ,        .












,   :  ,              .    : ,      ,  ,  ,   .  : ,        .

    monkey-patching         .  Rails   : 5.days.ago, 'hello'.titleize, [1,2,3].sum   ,  Rails   Integer, String, Array     .     Ruby- .     monkey-patching :     ,      .    Refinements, ,       .

     ,        .  ,    :   ,      ,     ?




1.5.   Ruby-,    


         ,   ,  ,     .   . ,   ,  :   ?   ?    ?      :   ,     .     ,     .

          .  ,         .   ,   .

 :   .    process_data,      ,   .    validate_and_persist_application,   .      .    ,    ,   ,    .

 :   .        ,      ,    .      (keyword arguments)        .

 :    . Ruby       (bang-: sort!  sort, upcase!  upcase).     ,        (persist!, complete!),   .             .







 ,    : fail fast.     ,      ,        .  ,            ,   -   ,       .

         :

def submit_application(user, params)      raise ArgumentError, '  ' unless user      raise InvalidStateError unless user.verified?      raise DuplicateApplicationError if user.has_pending_application?      #        end

 ,   :    ,     .    ,       .  -  (    )   ,   .         ,  ,  ,  .      ,   ,    ,   .




1.6.  ,   


Ruby  .  :         ,  ,    -,   .     ,          .

  .  Ruby     : if / unless,  ,  if,  case/when.   .           ,          ,          .

  Ruby     .      ,     .        ,   .

   .  ,          .  save_order   .      ,          ,       .










      ,   ,  ,  ,     ,    Ruby-.     .  ,      ,    .







Ruby  ,      .     ,     ,   ,   .  ,      ,      .

  ,     ,   ,    : Ruby   ,        .        , Ruby       .             ,       .

   Ruby     ,   :      ?                  ,      .      ,       .

     ,       . Rails    ,        :    ,   .    ,   ,          .




 2. RAILS   CRUD





       ,    Ruby on Rails,       : ,      .  :       .    :    Rails     2000-    ,  ,       ,        .

 .              Rails-,      .  ,       ,       ,          .   .

  , ,  Rails     ActiveRecord     .   ,      -.     ,             .




2.1.  Rails     ActiveRecord


  Rails-,         :  app/controllers, app/models, app/views.  MVC (Model-View-Controller)   .   ,      .    .

  ,             .    -.  ActiveRecord  ,      .   ,     .   :      .

  Rails    HTTP-,  ,  -   .    .      ,   ,           .

  . ActiveRecord-     : ,  , ,  .    .     ,    API,   -         - .

Rails   .        (before_save, after_create  ).   :     ,     .       :          ,      .

 Rails    MVC?   ,     ,   : jobs, mailers, channels, validators, formatters.  ,  Rails   ,     .










 ,  Rails   ,    MVC-,      .      ,     .




2.2. MVC   :     


   MVC  :   ,  ,  .       ,         .

  :        .  ?     (       ). ,       (,  ).      .   .    . ,    .

    ?               .    Application   ,     , ,   .      .

     Rails-  :        ?                   .              .







     .   Rails  ERB-        -.  Presenter  Decorator   :  -  ,         .     ,       ,   .

           .     ,      ,    .   ,     .




2.3. Service objects, form objects, query objects     


Service object  ,      Rails-.  :     - ( ,  ,  ),    ,      .

 service object  Rails  :







    . -,    call.  ,   service objects   . -,     bang-,     . -, ,   :   ,  .

        .  ,   ,           service object.         ,          .












Form object   .  Rails      .                 ?        ?   form object,  ,         .

Query object      .     ,    ,            query object.  ,        ,     .









 :       .     ,   . Service objects   ,        -,           .    .

    :    .    app/services,    ,  -   .      .




2.4.    ,      


  (callbacks)  Rails  ,     .    : before_validation, after_validation, before_save, after_save, before_create, after_create, after_commit, after_rollback     .  :   ,      ,   ,   .

  .   CRM-    ,           .   :







     ?   . :     Application.create!   - -,    .           .  ,     .

 :        .      Application.create!,       .   ,            .

 :       .    ,        .   ,    .










  ,      ? .    ,       : before_validation    ( ,   ), after_commit    ( after_commit,   after_create   ), before_create      .

 :                 , , .           ,     .

       : Rails API   ,     -    ,  .




2.5. Rails API    


        :     Rails back + Rails front (ERB-)   Rails API + Nuxt.            -  backend.

 ,  Rails    API?  ,     Rails.     JSON.   backend-     ,    :  -,   , .

     . Rails API    .       backend  frontend.     :     ,   .   :      .    :   ,   .







  Rails API + Nuxt    .  :   (    cross-origin ),     ,      .    : backend  , frontend     UI-,      .

Rails API      .    ,      .      ,   :     API?   UI?     ?




2.6.       


Rails   :        ,   .   .       ,    .     Rails,         - ,     ,    .

      Rails-?   (   ,  ,    ).   (     -   ).    ( ,    ,    ).          .

 ,    ,     . Service objects   . Form objects    . Query objects       .

    : . Rails   (convention over configuration).         service objects,    API,   -  ,   ,   ,   .     .







         .     .       . ,            ,       .

       Rails-    MVC.    ,        -,     .

Rails           ,    .     . ,   Rails       ,    ,       .

,    Rails       service objects, query objects, form objects,   API   ,     .   .         ,       .

   :    Rails   .      ,            .




 3.    RAILS-





       .     ,     - .   ,      .   ,      ,     .

     .     ,       .          , ,      .

  ,     ,   Rails-.   legacy     .  production-,   ,   .           API,     :       ,        .

   ,      Rails- ,      .    , ,    ,   ActiveRecord-   -.




3.1.      ,    


      .     ,            .           .    ,          .

    ,    . :           ,            .          Saga   .

 :  - ,     ,  ,  .       ,  ,    .

:  ,   .          .  :      ,  ,         .            .












  ,    .         ,      .      ,    .    ,    .

,   :          ,    .      ,       .







     ,    :        -.




3.2.   :     


 -       ,     .   :         ,         ,     ,     .        .   ,  ,   .

,      :      ?     -,        (  ,   Sidekiq,   )   .  :    . -         .      constraints,     .

  .          : , ,  , , .    ( -> ,   -> ),   ( -> ).        :









   ,   .          .             PostgreSQL  CHECK constraints,     .












         .     ,        .    (  ,   )       .




3.3. ,     


         -   .    .    .  , ,   .    ,   ,  ,   .

 Rails        AASM (Acts As State Machine)  Statesman. AASM   ,    ActiveRecord-. Statesman   ,    .          AASM:









   ?       .     . Guards    . After-     .









    ,    ,     : after-    ,    (,  ).    ,     .         . :        perform_later,       .




3.4.      


            .  :        ,       .    .

 Rails    ApplicationRecord.transaction {}.        ,   .    ,      .     ,     .

   ,   . : perform_later      ,        .     ,    ,    ,   .     after_commit .

: Rails      save!  create!.            .     PostgreSQL :    savepoint,        .

 :      .   -, HTTP-   API,              .      :           ,   .







   ,   ,      :     Rails-   -?




3.5.   ActiveRecord-   -


        Rails-.    (ActiveRecord)   ,  Rails    .    -   ,    :      ,  ,   .

 ,      ,      .  Application     ,    .  Procedure   ,     JSON API.  User       .

 ,   :  ActiveRecord-  ,      .  ,   (,   ),     (full_name = first_name + last_name),  .     service objects, domain objects      .

     :     (,  HTTP-).       .    ,       HTTP-.        .             .

     :         Bid (  ).     ,    .        .  , :       .       :   ,   ,      .       Bid,      -  .  :      BidEvaluationService.




3.6.   -  Rails-


-         .     :  ,  ,   ,  ,  .  :     .  :     .

    Rails?  ,   .

 :     ( ).          . :       .

 :   ,          :





           .       ,      ,           . ,       ,   .







  -        .          ,   .  -     ,           .

     .      ,     ,     .  ,   ,     ,       .

       .       ,      .    ,    .   ActiveRecord  -   ,    .

 ,          :       ,        .    ,         .    ,   -     ,    .

   API-first   ,     backend    ,    ,      .




 4. API-FIRST   RAILS





     API,       ,   JSON.   ,   . API     .    ,   ,   ,        .

       ,            Rails back + Rails front   Rails API + Nuxt.  API               :  ,  .   API     ,           .




  .


   .

   ,     (https://www.litres.ru/pages/biblio_book/?art=74016508)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


