0
0
NestJSframework~8 mins

CRUD with Prisma in NestJS - Performance & Optimization

Choose your learning style9 modes available
Performance: CRUD with Prisma
MEDIUM IMPACT
This concept affects server response time and database query efficiency, impacting how fast the page can load or update data.
Fetching all records with Prisma in a NestJS app
NestJS
async findAll(page = 1, limit = 10) {
  return await this.prisma.user.findMany({
    skip: (page - 1) * limit,
    take: limit
  });
}
Limits data fetched per request, reducing server load and response time.
📈 Performance GainFaster response, lower memory use, better LCP
Fetching all records with Prisma in a NestJS app
NestJS
async findAll() {
  return await this.prisma.user.findMany();
}
Fetching all records without pagination can cause large data loads, increasing response time and memory use.
📉 Performance CostBlocks server response longer as data size grows, increasing LCP delay
Performance Comparison
PatternDatabase QueriesServer Response TimeNetwork PayloadVerdict
Fetch all without pagination1 large queryHigh due to large dataLarge JSON payload[X] Bad
Fetch with pagination1 small queryLow and predictableSmall JSON payload[OK] Good
Update with read then update2 queriesHigher latencyMinimal payload[X] Bad
Update with single query1 queryLower latencyMinimal payload[OK] Good
Delete with read then delete2 queriesHigher latencyMinimal payload[X] Bad
Delete with single query1 queryLower latencyMinimal payload[OK] Good
Rendering Pipeline
Prisma CRUD operations run on the server before the page renders. Slow queries delay server response, which delays the browser receiving data to paint the page.
Server Processing
Network Transfer
Browser Rendering
⚠️ BottleneckServer Processing due to database query time
Core Web Vital Affected
LCP
This concept affects server response time and database query efficiency, impacting how fast the page can load or update data.
Optimization Tips
1Limit data fetched with pagination to reduce server load and network payload.
2Use single queries for update and delete to minimize database round trips.
3Avoid fetching unnecessary data to improve server response and page load speed.
Performance Quiz - 3 Questions
Test your performance knowledge
What is a performance downside of fetching all records without pagination in Prisma?
AIt reduces server response time by fetching all data at once.
BIt can cause large data loads, increasing server response time and slowing page load.
CIt decreases network payload size.
DIt improves browser rendering speed.
DevTools: Network
How to check: Open DevTools, go to Network tab, perform CRUD action, and observe request timing and payload size.
What to look for: Look for long server response times or large JSON payloads indicating inefficient queries.