Batching DB Requests with Promise.all
OPTIMIZATION TIP: Run Queries in Parallel
❌ Sequential — each waits for the previous to finish
const user = await getUser(id); // 100ms
const courses = await getCourses(id); // 100ms
const badges = await getBadges(id); // 100ms
// Total: ~300ms
✅ Parallel — all run at the same time
const [user, courses, badges] = await Promise.all([
getUser(id),
getCourses(id),
getBadges(id)
]);
// Total: ~100ms (3x faster!)
Note: Use this when queries are independent of each other.
Perfect for dashboard data loading!
#JavaScript #AsyncAwait #NodeJS