Add GraphQL API for batch user queries to reduce N+1 problems
Feature Request: GraphQL API
Problem
Our REST API has N+1 query problems when clients need related data:
// ❌ Current: N+1 queries (1 + 10 users = 11 queries)
const recommendations = await fetch('/api/recommendations?limit=10');
for (const rec of recommendations) {
const user = await fetch(`/api/users/${rec.userId}`); // N queries
}
Solution
Implement GraphQL API with DataLoader pattern:
query GetRecommendationsWithUsers {
recommendations(limit: 10) {
id
score
user {
id
name
avatar
}
}
}
Benefits:
- Single query instead of N+1
- DataLoader batching (10 user queries → 1 batch query)
- p99 latency: Expected 412ms → 180ms
Implementation Plan
- Add
graphql-pythondependency - Create schema with User and Recommendation types
- Implement DataLoader for user batching
- Add GraphQL endpoint
/graphql - Migrate iOS app to use GraphQL
Related
- Blocks: #21 (closed) (p99 latency optimization)
- Related: acme-corp/mobile-section/ios-devs/ios-app#12 (closed) (iOS performance)
Edited by Administrator