meta_pixel
Tapesearch Logo
Log in
Syntax - Tasty Web Development Treats

Hasty Treat - What is the n+1 problem?

Syntax - Tasty Web Development Treats

Wes Bos

Tech News, News, Technology

4.9 • 1.2K Ratings

🗓️ 29 March 2021

⏱️ 20 minutes

🧾️ Download transcript

Summary

In this Hasty Treat, Scott and Wes talk about a common problem you’ll encounter in your development career — the n+1 problem. Hasura - Sponsor With Hasura, you can get a fully managed, production-ready GraphQL API as a service to help you build modern apps faster. You can get started for free in 30 seconds, or if you want to try out the Standard tier for zero cost, use the code “TryHasura” at this link: hasura.info. We’ve also got an amazing selection of GraphQL tutorials at hasura.io/learn. Sentry - Sponsor If you want to know what’s happening with your code, track errors and monitor performance with Sentry. Sentry’s Application Monitoring platform helps developers see performance issues, fix errors faster, and optimize their code health. Cut your time on error resolution from hours to minutes. It works with any language and integrates with dozens of other services. Syntax listeners new to Sentry can get two months for free by visiting Sentry.io and using the coupon code TASTYTREAT during sign up. Show Notes 05:00 - What is the n+1 problem? The N+1 problem can happen in any language but is especially prevalent in GraphQL because it’s so easy to query relationships. 09:33 - The solution The solution to the n+1 problem is to batch the queries. As you loop over each podcast, keep an array of host IDs to lookup. Once you have looped over the podcasts, make a single query to the database with your large array of podcast host Ids. 11:11 - Should you care? Sometimes no: its often fine to do multiple DB Calls Facebook DataLoader Mercurious Many ORMs take care of this for you These then break it down into my appropriate SQL MongoDB Ruby: eager loading Laravel ORM does it Aggregation pipelines Prisma N+1: https://www.youtube.com/watch?v=7oMfBGEdwsc&vl=en Mongoose Populate Apollo Studio Tweet us your tasty treats! Scott’s Instagram LevelUpTutorials Instagram Wes’ Instagram Wes’ Twitter Wes’ Facebook Scott’s Twitter Make sure to include @SyntaxFM in your tweets

Transcript

Click on a timestamp to play from that location

0:00.0

Monday Monday Monday open wide dev fans get ready to stuff your face with Javascript CSS node module barbecue tips

0:09.0

Get work flow break dancing soft skills web development the hastiest the crazy as the tastiest web development

0:16.0

Treats coming in hot. Here is Wes Barakuda boss and Scott El Toro Lungo Tolinsky

0:26.0

Welcome to syntax in this Monday hasty treat. We're gonna be talking all about a common question that is typically seen in things like

0:36.0

Interviews or perhaps you just hit general thing you're gonna run into at some point in your development career

0:42.0

And it involves with the amount of times that you need to hit to load data. And this is called the n plus one

0:50.0

I don't know if it's called the n plus one, but it is an n plus one issue

0:55.0

And we're gonna be talking all about what the heck that is or why it might be relevant to you when you might come across it

1:01.0

And what are there some of the solutions here that are out there?

1:04.0

My name is Scott Tolinsky may full stack developer Denver color out on with me as always is Wes boss

1:09.0

Hey everybody. I'm excited to talk about this specific n plus one problem

1:15.0

I am excited to talk about it because it's not one of my favorite things in the whole world and it's definitely one of those traps

1:21.0

That's really easy to get into especially in graphql

1:25.0

And it's exceedingly easy to just drop yourself into an n plus one issue and then have to learn about it

1:32.0

And there's not a ton of resources out there. It's like oh, oh, yeah, this thing that I might not even know going on is happening

1:38.0

Oh, guess I got to figure it out

1:40.0

All right, this episode is sponsored by a couple of great companies. It is sponsored by hasura as well as century

1:48.0

Now hasura is really really cool. Now what it is is it's a data service that basically allows you instant access to get jamming on a database

2:00.0

And it opens up all sorts of API crud operations for you just out of the box

2:07.0

So let's say if you wanted to get started with a graphql api

2:12.0

It doesn't want to have to think about a database

2:14.0

You didn't want to have to think about any of those layers you could just create a hasura instance which uses postgres

...

Please login to see the full transcript.

Disclaimer: The podcast and artwork embedded on this page are from Wes Bos, and are the property of its owner and not affiliated with or endorsed by Tapesearch.

Generated transcripts are the property of Wes Bos and are distributed freely under the Fair Use doctrine. Transcripts generated by Tapesearch are not guaranteed to be accurate.

Copyright © Tapesearch 2026.