Premium video course

Eloquent Performance Patterns

Learn how to drastically improve the performance of your Laravel applications by pushing more work to the database, all while still using the Eloquent ORM.

Buy Now
πŸ‘ˆ Now available!
Get two free preview lessons!
In these lessons I show how using compound indexes can drastically speed up the ordering of multiple columns.

Performance issues suck. Customers are frustrated. Your servers are overloaded. Management is breathing down your neck.

You've already solved all your N+1 issues, added the necessary indexes, and you're even paying for the most expensive database server available. But despite all this, some things just feel impossible to build in a performant way.

  1. We can't paginate results in the database because they depend on authorization checks that happen in Laravel.
  2. We have to do some really complicated calculations on large data sets, which seems impossible without a real programming language like PHP.
  3. We can't sort results in the database, because we have to sort by values computed in our application.

So you invest months into different caching strategies to try and speed things up, but caching is hard. Every time you think you've solved a performance problem, you have a new caching problem to deal with instead.

I've been there and it sucks. So one day I decided “that's it, I'm going to figure out how to push all this work to the database if it kills me.” The results blew my mind.

By leveraging advanced database techniques, like sub queries, conditional aggregates, and aggressive use of scopes, pages that took 30+ seconds to load were now loading within 500ms!!

I've since spoken about Eloquent and database performance at both Laracon Online and Laracon US, and have written in-depth articles on the topic.

Eloquent Performance Patterns is a culmination of everything I've learned along my journey, distilled into a single course. We're going to dig deep into advanced real world problems. This isn't another Eloquent introduction course.

What you’ll learn πŸ‘‡

  • The three key metrics to better database performance
  • The incredible power of sub queries
  • When to use joins vs sub queries
  • Using sub queries to select related data
  • Using sub queries to build dynamic relationships
  • Using sub queries to order by related data
  • Calculating totals using conditional aggregates
  • Running authorization policies in the database
  • Building complex search filters
  • Extending the query builder using macros
  • Demystifying database indexes
  • Introducing complex queries without sacrificing Eloquent's API
  • Leveraging vendor-specific (MySQL, Postgres, etc.) features
  • Caching and database denormalization
  • How to safely write raw database queries
  • Configuring Laravel to make N+1 issues impossible
  • Extending Eloquent to support ordering with NULLS LAST and NULLS FIRST
  • Getting the distance between two geographic points
  • Filtering by geographic distance
  • Ordering by geographic distance
  • Querying records within a physical area using geospatial shapes
This is the course the Laravel community needed. Performance is always a hot topic, but most advice is surface level, micro-optimizations at best. Jonathan's approach to performance is next level, and you NEED to learn these techniques.
Adam Wathan
Author of Test-Driven Laravel
Jonathan Reinink is one of the top thinkers in the Laravel community about how to use and optimize databases. He’s a great guy, a clear and capable teacher, and really knows his stuff. I can’t think of anyone else I’d want to learn from more about database performance in Laravel.
Matt Stauffer
Author of Laravel: Up & Running

The lessons

Here's a complete list of all the lessons in the course. I've worked really hard to maintain a good pace in each lesson. I want to be respectful of your time...and that means keeping things moving. I use MySQL as the primary database in the lessons themselves. However, if you purchase the Premium Package, I include the source code for not only MySQL, but Postgres and SQLite (where possible) as well.
  • Measuring your database performance (5:12)
    MySQL
    Postgres
    SQLite
  • Minimizing memory usage by selecting only the required data (4:29)
    MySQL
    Postgres
    SQLite
  • Getting one record from has-many relationships (9:43)
    MySQL
    Postgres
    SQLite
  • Creating dynamic relationships using sub queries (6:09)
    MySQL
    Postgres
    SQLite
  • Calculating totals using conditional aggregates (4:21)
    MySQL
    Postgres
    SQLite
  • Optimizing circular relationships (4:25)
    MySQL
    Postgres
    SQLite
  • Setting up multi-column searching (4:06)
    MySQL
    Postgres
    SQLite
  • Getting LIKE to use an index (5:05)
    MySQL
    Postgres
    SQLite
  • Faster options than whereHas (3:55)
    MySQL
    Postgres
    SQLite
  • When it makes sense to run additional queries (3:07)
    MySQL
    Postgres
    SQLite
  • Using UNIONs to run queries independently (7:58)
    MySQL
    Postgres
    SQLite
  • Fuzzier searching using regular expressions (4:45)
    MySQL
    Postgres
  • Running authorization policies in the database (6:04)
    MySQL
    Postgres
    SQLite
  • Faster ordering using compound indexes (4:04)
    MySQL
    Postgres
    SQLite
  • Ordering by has-one relationships (1:37)
    MySQL
    Postgres
    SQLite
  • Ordering by belongs-to relationships (1:38)
    MySQL
    Postgres
    SQLite
  • Ordering by has-many relationships (4:21)
    MySQL
    Postgres
    SQLite
  • Ordering by belongs-to-many relationships (5:38)
    MySQL
    Postgres
    SQLite
  • Ordering with NULLs always last (7:36)
    MySQL
    Postgres
    SQLite
  • Ordering by custom algorithms (6:37)
    MySQL
    Postgres
    SQLite
  • Filtering and sorting anniversary dates (7:04)
    MySQL
    Postgres
    SQLite
  • Making N+1 issues impossible (3:23)
    MySQL
    Postgres
    SQLite
  • Premium Package only:

  • Ordering data for humans using natural sort (4:20)
    MySQL
    Postgres
  • Full text searching with rankings (5:06)
    MySQL
    Postgres
  • Getting the distance between geographic points (3:22)
    MySQL
    Postgres
  • Filtering by geographic distance (2:59)
    MySQL
    Postgres
  • Ordering by geographic distance (1:25)
    MySQL
    Postgres
  • Filtering by geospatial area (4:35)
    MySQL
    Postgres
Jonathan’s the real deal. In a sea of contrived examples, this dude delivers solid content born out of the real world. On top of that, he’s a clear thinker with a taste for simplicity, so his stuff’s in-line with the “Laravel spirit” and is easy to grok.
Caleb Porzio
Creator of Livewire
Reinink's approach to development is always grounded in simple and practical theory with a focus on developer experience. I've learned so much from following his work and this course is an absolute must-purchase for my own.
David Hemphill
Creator of Laravel Nova
Jonathan Reinink

About the author

Hey there! My name is Jonathan Reinink. I've been doing web development for roughly 20 years now, and have been working with Laravel since 2013. I am active in the open-source community, and have contributed numerous libraries, including Glide, Advanced Eloquent, Tailwind CSS, and more recently, Inertia.js. Outside of open-source, I own and operate a SaaS business called Church Social. You can learn more about me on my personal website.

Buy the course 🀟

Join over 2,300 developers who have already stepped up their database performance game!

Premium Package

  • Access to a total of 28 lessons
  • Includes 6 additional advanced lessons on natural sorting, full-text searching and geospatial queries
  • Full source code for all lessons, including MySQL, Postgres and SQLite versions (where possible)
  • Over two full hours of video content
  • Stream online or download videos
$
149
USD
Buying for your team? View the team pricing.

Essentials Package

  • Access to the first 22 lessons
  • Just under two hours of video content
  • Stream online or download videos
$
99
USD

FAQs