Async & Concurrency
Code Review: Promise Concurrency Exhaustion
mediumCode ReviewJS / TS
Problem Statement
Review the following batch notification dispatcher. Identify why firing thousands of HTTP requests with unrestricted `Promise.all()` leads to socket exhaustion, memory spikes, and API rate limit bans. Refactor with controlled concurrency.
Code under review
JAVASCRIPT• handler.js
Pairlet Snippet
// Batch newsletter dispatcher
async function dispatchBulkNotifications(subscribers, message) {
console.log(`Starting dispatch to ${subscribers.length} subscribers...`);
const results = await Promise.all(
subscribers.map(sub =>
sendEmailViaSendgrid(sub.email, message.subject, message.body)
)
);
return { dispatched: results.length };
}
Read only. Write down what you would flag below, then compare with the reference notes.
JavaScript & TypeScript versions included
Run this as a live interviewPractice solo
Write down what you would flag in this code, then compare it with the reference notes.
Write your findings first, then check yourself against the notes.