Skip to content

Commit

Permalink
docs: Dataloaders text correction
Browse files Browse the repository at this point in the history
  • Loading branch information
mschipperheyn committed Dec 23, 2024
1 parent 7d596b2 commit b7adf4b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/docs/guides/developer-guide/dataloaders/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ showtoc: true

## N+1 problem

Imagine a cart with 20 items. Your database pool is configured to 15: enough to handle most sccenario's. Your implementation requires you to perform an `async` calculation `isSubscription` for each cart item that require one or more queries to be executed each time it executes. It works fine for a cart with 10 items. But with more than 15 items, suddenly the cart takes 20 seconds to load.
Imagine a cart with 20 items. Your database pool is configured to 15: enough to handle most sccenario's. Your implementation requires you to perform an `async` calculation `isSubscription` for each cart item whih executes one or more queries each time it is called. It works fine for a cart with 10 items. But with more than 15 items, suddenly the cart takes 20 seconds to load.

The reason: the N+1 problem. Your cart is firing of 20 or more queries almost at the same time and is overwhelming your database pool. With 15 queries active in the pool, the next one has to wait until a slot becomes available in the pool, adding **significantly** to the query time.
The reason: the N+1 problem. Your cart is firing of 20 or more queries almost at the same time and is overwhelming your database pool. With 15 queries active in the pool, the next one has to wait until a slot becomes available in the pool, adding **significantly** to the GraphQL request.

And even if you don't overwhelm your database pool, executing 10 queries to get 10 items is like going to the McDonald's drive-in to get 10 hamburgers and getting in line 10 times to get 1 hamburger at a time. It's not efficient.

## The solution: dataloaders

Expand Down

0 comments on commit b7adf4b

Please sign in to comment.