Skip to main content
Full Stack Radio

104: Jonathan Reinink - Pushing More Work to the Database

61 min episode · 2 min read
·

Episode

61 min

Read time

2 min

Topics

Productivity, Software Development, Science & Discovery

AI-Generated Summary

Key Takeaways

  • N+1 vs Memory Problems: Loading 100 users with eager-loaded login records creates 10,000 Eloquent model instances consuming massive memory. Each model initialization adds milliseconds that compound into 200+ millisecond delays, worse than running multiple queries for performance-critical applications.
  • Subquery SELECT Pattern: Use SELECT sub in Laravel to add dynamic columns like last login date directly in the main query. Returns 200 total records for 100 users instead of 10,000, avoiding both N+1 queries and memory bloat while maintaining two-query efficiency.
  • WHERE NOT EXISTS Optimization: Database stops searching immediately after finding one matching record in WHERE NOT EXISTS subqueries. Reverse logic to check if conflicts exist rather than gathering all possibilities, dramatically reducing query execution time for eligibility and availability checks across large datasets.
  • R-Rule Caching Strategy: Cache time-based rules only when triggered by user actions, not time passage. Convert recurring availability rules into 365 daily records per teacher per school year, regenerating only when schedules change or administrators modify school year dates for real-time performance.
  • Database-Specific Features: Postgres offers native date range comparison and overlap detection unavailable in MySQL. Abstracting databases to remain database-agnostic sacrifices performance gains from specialized features like range operators, extensions, and optimized functions built into specific database engines over decades.

What It Covers

Jonathan Reinink explains how pushing database queries instead of PHP logic reduced page loads from 30 seconds to milliseconds by using Postgres subqueries, date ranges, and WHERE NOT EXISTS clauses in Laravel Eloquent applications.

Key Questions Answered

  • N+1 vs Memory Problems: Loading 100 users with eager-loaded login records creates 10,000 Eloquent model instances consuming massive memory. Each model initialization adds milliseconds that compound into 200+ millisecond delays, worse than running multiple queries for performance-critical applications.
  • Subquery SELECT Pattern: Use SELECT sub in Laravel to add dynamic columns like last login date directly in the main query. Returns 200 total records for 100 users instead of 10,000, avoiding both N+1 queries and memory bloat while maintaining two-query efficiency.
  • WHERE NOT EXISTS Optimization: Database stops searching immediately after finding one matching record in WHERE NOT EXISTS subqueries. Reverse logic to check if conflicts exist rather than gathering all possibilities, dramatically reducing query execution time for eligibility and availability checks across large datasets.
  • R-Rule Caching Strategy: Cache time-based rules only when triggered by user actions, not time passage. Convert recurring availability rules into 365 daily records per teacher per school year, regenerating only when schedules change or administrators modify school year dates for real-time performance.
  • Database-Specific Features: Postgres offers native date range comparison and overlap detection unavailable in MySQL. Abstracting databases to remain database-agnostic sacrifices performance gains from specialized features like range operators, extensions, and optimized functions built into specific database engines over decades.

Notable Moment

A school district substitute teacher system processed tens of thousands of real-time phone calls through Twilio each morning. Converting complex PHP eligibility logic checking credentials, blacklists, and availability into one Postgres query eliminated 30-second page loads and cache invalidation nightmares.

Know someone who'd find this useful?

Episode Transcript

In this episode of Fullstack Radio, I talked to Jonathan Renick about pushing more work to the database to speed up your application. This is Fullstack Radio episode one zero four. Before we get into the conversation with Jonathan today, I just wanted to quickly announce that a few days ago, Steve Shoger and I finally released refactoring UI, which is a huge package we put together that will give you everything you need to start making your projects look awesome without relying on the help of a professional designer. It includes a 218 page book, a set of video tutorials, a custom illustrated icon set, pre built professionally chosen color palettes and font recommendations, as well as a huge gallery of component and layout ideas to help you get any new design started on the right foot. Right now, it's available for 40% off. So if you haven't checked it out already, head over to refactoringui.com/book to learn more about it. Thanks. Now back to the show. Hey, everyone. Welcome to another episode of the Fullstack Radio podcast. I'm your host, Adam Wathan. And today, it's my pleasure to be welcoming back a recurring guest, Jonathan Renning. How's it going, dude? I am doing awesome. Thanks for having me back on, Adam. Awesome. So, a couple weeks ago, maybe a month or I don't know how long ago it was. Yeah. It was in November. Yeah. You you put up this article that was, basically talking about how to do some more advanced kind of database querying stuff and how to kind of make some of these little things that you need to do with like Eloquent and Laravel, for example, a lot more performant than they might be otherwise. And you also gave a talk that went into depth about a lot of this stuff at Laracon online, back in February, I think it was. Yep. So, I thought it'd be awesome to have you on the show to talk about some of this stuff because that's an area where I think, myself, like a lot of people, don't have a ton of skills and knowledge. Like, I know my way around the ORM really well. I can write SQL, you know, and get by. But when it comes to, like, really more sophisticated queries and doing stuff with sub selects and stuff that I don't even know how to write by hand, I think I have a lot to learn there. And I think there's a lot that, the listeners could could benefit from learning as well. So, yeah, so why don't you talk a little bit about just kinda your mentality when it comes to trying to solve problems like this? Because I know that a lot of people talk about, like, trying to make sure that your code is as decoupled from things like the database as possible. You know, you should be able to switch between MySQL or Mongo or some external API, you …

Get the full transcript (11,683 words) + summary by email — free

One-time email with the complete transcript and AI summary of this episode. No account needed.

One email, no spam. We’ll also show you what SignalCast does.

Browse all Full Stack Radio transcripts →

You just read a 3-minute summary of a 58-minute episode.

Get Full Stack Radio summarized like this every Monday — plus up to 2 more podcasts, free.

Pick Your Podcasts — Free

Keep Reading

Books, tools, and gear mentioned in this episode

SignalCast may earn commission on purchases via these links. As an Amazon Associate, SignalCast earns from qualifying purchases.

Books

Tools

  • A school district substitute teacher system processed tens of thousands of real-time phone calls through Twilio each morning.
  • SPONSORS: Odeer - https://odeer.app
  • SPONSORS: Rollbar - https://rollbar.com/fullstackradio

More from Full Stack Radio

We summarize every new episode. Want them in your inbox?

Similar Episodes

Related episodes from other podcasts

Explore Related Topics

This podcast is featured in Best Cybersecurity Podcasts (2026) — ranked and reviewed with AI summaries.

Read this week's Software Engineering Podcast Insights — cross-podcast analysis updated weekly.

You're clearly into Full Stack Radio.

Every Monday, we deliver AI summaries of the latest episodes from Full Stack Radio and 192+ other podcasts. Free for one show.

Start My Monday Digest

No credit card · Unsubscribe anytime