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

Experimenting in Production

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
Avatar for Gary Tou Gary Tou
November 15, 2023

Experimenting in Production

Together, we explore experimenting in production with Ruby on Rails. We learn about various techniques and how the `scientist` and `lab_tech` Ruby gems can help us achieve safe and scientifically-driven experimentation.

Avatar for Gary Tou

Gary Tou

November 15, 2023

Other Decks in Technology

Transcript

  1. 🏦 class BankAccount < ApplicationRecord has_many :transactions def balance transactions.reduce

    0 do |balance, transaction| balance + transaction.amount end end end class BankAccount < ApplicationRecord has_many :transactions def balance transactions.sum(:amount) end end @garyhtou
  2. class BankAccount < ApplicationRecord has_many :transactions def balance # this

    might give inaccurate results 💸 new_balance # calculation using `sum` end end class BankAccount < ApplicationRecord has_many :transactions def balance old_balance # calculation using `reduce` end end @garyhtou
  3. class BankAccount < ApplicationRecord has_many :transactions def balance if rand

    < 0.5 old_balance else new_balance end end end class BankAccount < ApplicationRecord has_many :transactions def balance old_balance # calculation using `reduce` end end A/B Testing @garyhtou
  4. Why not run both? class BankAccount < ApplicationRecord has_many :transactions

    def balance old_result = old_balance # calculation using `reduce` new_result = new_balance # calculation using `sum` if new_result != old_result puts "oh no! new method is wrong! 😰" end old_result end end @garyhtou
  5. 📊 Compare the old and new results 📒 Test odd

    edge cases with production data ✅ Return accurate results 🐌 CON: Decrease in performance Why you should run both
  6. github/scientist 🔬 A Ruby library for carefully refactoring critical paths

    RealGeeks/lab_tech Rails engine for using GitHub's 'Scientist' library with ActiveRecord + @garyhtou
  7. Scientist + Lab Tech class BankAccount < ApplicationRecord has_many :transactions

    def balance LabTech.science "my_balance_experiment" do |exp| exp.use { old_balance } exp.try { new_balance } end end end @garyhtou