Skip to main content
Alvin QuachFull Stack Developer
HomeProjectsExperienceBlog
HomeProjectsExperienceBlog
alvinquach

Full Stack Developer building systems that respect complexity.

Open to opportunities

AQ

Projects

  • All Projects
  • Hoparc Physical Therapy
  • OpportunIQ
  • Hoop Almanac
  • SculptQL

Knowledge

  • Blog
  • Experience
  • Interview Prep

Connect

  • Contact
  • LinkedIn
  • GitHub
  • X

Resources

  • Resume
© 2026All rights reserved.
Back to Blogs
Bug Fix
Depth: ●●○○○

N+1 Query Bug in GraphQL Resolvers

How I discovered and fixed an N+1 query problem that was causing 50+ database queries per request.

Published August 30, 20241 min readImportance: ★★★★☆
PostgreSQL
Performance
API Design
Share:

Discovery

API responses were taking 2+ seconds. Logging revealed 50-100 database queries per request. Each workout was triggering a separate query to fetch its exercises.

Root Cause

GraphQL resolver for 'exercises' field was fetching exercises one workout at a time. With 50 workouts in a plan, that's 50 separate queries.

The Fix

Implemented DataLoader to batch and cache database queries. All exercises now fetched in a single query with WHERE workout_id IN (...). Response time dropped to 150ms.