BH Serna's "Fix n+1 queries on Rails" is a short, reasonably in-depth look at the n+1 problem commonly arising through indiscriminate use of ORMs such as Active Record. The nice thing about Serna's treatment is that it's well-suited for example implementation, as shown in this repo.
It's a well-understood problem, which all engineers using Rails (or Active Record) engineering should be well acquainted with. These are some excellent resources:
- https://evilmartians.com/chronicles/squash-n-plus-one-queries-early-with-n-plus-one-control-test-matchers-for-ruby-and-rails
- https://github.com/nepalez/rspec-sqlimit
- https://github.com/palkan/n_plus_one_control?tab=readme-ov-file
- https://github.com/charkost/prosopite/tree/main
- https://github.com/flyerhzm/bullet
- https://bhserna.com/5-ways-to-fix-the-latest-comment-n-1-problem.html