104: Jonathan Reinink - Pushing More Work to the Database
Episode
61 min
Read time
2 min
Topics
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.
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 — FreeKeep Reading
More from Full Stack Radio
153: DHH – Omarchy and Designing Your Own OS on Arch Linux
Aug 21 · 76 min
Equity
How Lucra raised $20M as an eSports play when every VC only wants AI
May 20
More from Full Stack Radio
152: Ben Orenstein - How to Stand Out When Applying for a Job at a Small Company
Jan 28 · 47 min
Marketing School
How To Send 1 Million Emails For $100/Month
May 20
More from Full Stack Radio
We summarize every new episode. Want them in your inbox?
153: DHH – Omarchy and Designing Your Own OS on Arch Linux
152: Ben Orenstein - How to Stand Out When Applying for a Job at a Small Company
151: DHH – Building HEY with Hotwire
150: Secret Screencasting Tips & Behind the Scenes of Tailwind CSS 2.0
149: Choosing a Payment Processor, Radical Icons & W3C Hype
Similar Episodes
Related episodes from other podcasts
Equity
May 20
How Lucra raised $20M as an eSports play when every VC only wants AI
Marketing School
May 20
How To Send 1 Million Emails For $100/Month
Morning Brew Daily
May 20
Google Search Gets AI Makeover & Pizza Hut’s Retro Revival
Syntax
May 20
1006: Can AI Make Good Design?
Citeline Podcasts
May 20
Redefine Modern Biotech Through Smarter Boards, Stronger ROI, and China's Rise
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 up to 3 shows.
Start My Monday DigestNo credit card · Unsubscribe anytime