ruby on rails

A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

https://rubyonrails.org/

Starky and Hutch sessions

2024-12-23

Discussed on how the online identity engine works:

  • data models
  • CP2U
  • CR2U
    • using a patient sharing to tacke some tanker sharing issue
    • example on “patient account sharing”

Next steps:

  • reduce to bi-weekly, since I’m not currently practicing rails
  • revert back to usual sessions once we will tackle some projects that deal with the doctolib monolith

2024-12-16

Questions

Something custom to doctolib, and not rails.

ApplicationEvent

  • synchronous
  • based on ActiveSupport::Notification
    • should not be used for business event, but we mostly used for business event instead
    • each listener boostraped themselves and increase the boot time

ApplicationJob

  • custom to add observability
  • custom dashboard
  • resque dashboard exists but have too much power, so we introduced an abstraction layer

after_commit for outbox pattern. REACH handles appointment for engines/appointment_management/app/public/appointment_management/concerns/lifecycle.rb

Distributed transactions

  • not supported at doctolib
  • no 2 phase commit
  • saga pattern is being implemented in patient messaging

Minitest spec

  • can be confusing for people that were used with RSpec
    • RSpec has different steps: setup, teardown, before suite, after suite
    • Minitest does not have before suite. setup and before are always executed for each test it, not for the whole describe. To be validated.

Webserver

  • doctolib is not using puma, but pitchfork (created by Shopify)
    • puma is multi-threaded and we don’t know if our code is thread safe
    • puma optimized for throughput whereas unicorn (process based) is more optimized for latency
    • pitchfork is a fork of unicorn but with better memory safety
    • we want to leverage ruby YJIT to improve improvement performance (+8% on all endpoints)

Engine separation of concern

  • always give bulk API to clients can no longer leverage the ActiveRecord goodness

Suggestions for next sessions:

  • work together on pain points on ruby, some projects that are not prioritized
  • learn low level on ruby, GC, threads, fiber or rails
  • optimize some tests
  • read the online identity engine

2024-12-02

  • [-]side find a project to use rails 📅 2024-12-02
    • Cannot find a good project… No inspiration.

No need to spend personal time on checking my project. We can also check during the session.

Project candidate for learning rails:

  • something I will use personally

  • runnable locally

  • something that can use at least 2 or 3 rails feature

  • [-] RSS feeder

    • Database
      • RSS feed URLs
      • Read articles
    • Job
      • Automatically fetch RSS content
    • Not a complex project that would require a complex modeling, i.e. complex use of ActiveRecord.
  • [-] Accounting web application

    • Too much hassle because I would need to handle some tables in HTML…
  • [-] kubetailrb rails version

    • Nothing rails to use…
  • [-] jira wrapper

    • Too much hassle…
  • [-] parabol (retro) alternative

    • Too much hassle…
  • project with a SQLite for each client?

    • Synchronization tool?
    • Too much constraint (schema migration, no association between each client, not stats, …).
  • website for lego?

Questions

  • Controller safe_params controlled at which time?
  • AsyncPlatform is the doctolib abstraction layer between rails and ActiveJob.
    • Serialization performed in ActiveJob.
    • With ActiveJob, it’s enqueing the id of the model, not the whole model, even though we are using the model as the parameter. ActiveJob will ensure to call the DB to get the whole entity.
      • It’s to ensure we are not serializing the whole entity in Redis.
rails -> AsyncPlatform -> ActiveJob -> Resque -> Redis
  • Check classes that implements ApplicationJob for the work producer.

  • Think before using callbacks!

  • includes used for eager loading. To be used with references only if you need a filter on the other table.

    • rails decides whether to use 2 queries or one query with a JOIN.
  • If you need a LEFT JOIN, use left_join

  • To deal with N+1 problem use includes.

2024-11-18

Questions

disabled_joins for associations without using joins.

2024-11-07

Questions

class CreateBooks < ActiveRecord::Migration[7.2]
  • Like an alias.

  • see Dir[]

  • Foo.new { |f| ... end } purpose compared to “classic” imperative approach?

book = Book.new do |b|
  b.title = "Metaprogramming Ruby 2"
  b.author = "Paolo Perrotta"
end
# vs
book = Book.new
book.title = "Metaprogramming Ruby 2"
book.author = "Paolo Perrota"
  • It can be useful for constructor with mandatory arguments.
  • It’s also more performant in some situations:
def foobar
  # A is memory hungry
  a = A.new
  # do something with a
 
  # long method...
end
# a is only release here
 
# VS
 
def foobar
  A.new do |a|
    # do something with a
  end
  # A will be released
 
  # long method...
end

2024-10-28 - ice breaker

  • Session formats:
    • Duration: 1 hour per week, on Mondays, and we can shorten the session if it’s too long.
    • Read a section from Rails guides and check together in doctolib monolith code base to illustrate the principle.
      • Primary subjects to check out: model + controllers + active job
    • Also possible review together some code.
    • Progress status of the project kubetailrb.
      • This project will not highlight the features of rails’s ActiveRecord. Either find another project or find a way to use the ActiveRecord with kubetailrb.
    • Q&A

Questions

  • Are the ruby exercises from uniq are relevant or not?
    • Teck Wan Wong doesn’t know as he didn’t do the tutorials on uniq.
  • Does ruby on rails at doctolib differ a lot from the framework?
    • Tutorials on the internet can make me understand doctolib.
    • Use react + slim (for SEO) for frontend.
  • Concurrency in ruby?
  • We can install a gem with --user-install. What’s the difference without this flag? Is it useful if I’m using rbenv?
    • It should be most likely about precedence, i.e. ruby would take from the user installation directory before the installation directory.

Tips

  • Use bundle open ${gem_name} to open the source code of the gem.

Resources