Sequential vs Parallel Operations
What you'll learn: How the difficulty of managing callbacks multiplies when you need to run async operations either one-after-another or all-at-once.
The Core Problem
When working with callbacks, you face two common patterns: sequential operations (do A, then B, then C) and parallel operations (start A, B, and C all at once, then wait for all to finish). Both are surprisingly difficult with callbacks alone.
Sequential Operations
Sequential async operations require nesting callbacks inside each other, creating the "callback hell" pyramid:
fetchUser(userId, function(err, user) {
if (err) return handleError(err);
fetchOrders(user.id, function(err, orders) {
if (err) return handleError(err);
fetchOrderDetails(orders[0].id, function(err, details) {
if (err) return handleError(err);
// Finally have all data
console.log(details);
});
});
});
Each step must wait for the previous one, and error handling is repeated at every level.
Parallel Operations
Running multiple callbacks in parallel and coordinating their completion is even harder. You must manually track which operations have finished:
let completed = 0;
const results = {};
fetchUser(userId, function(err, user) {
if (err) return handleError(err);
results.user = user;
if (++completed === 3) doSomething(results);
});
fetchSettings(function(err, settings) {
if (err) return handleError(err);
results.settings = settings;
if (++completed === 3) doSomething(results);
});
fetchProducts(function(err, products) {
if (err) return handleError(err);
results.products = products;
if (++completed === 3) doSomething(results);
});
You're manually implementing synchronization logic with counters and shared state—tedious and error-prone.
Key Takeaway: Callbacks make coordinating multiple async operations—whether sequential or parallel—verbose and difficult to maintain, requiring manual tracking of state and repetitive error handling at every step.