What performance issue can arise from the following code pattern?
Promise.all([
fetch('/api/users').then(res => res.json()),
fetch('/api/products').then(res => res.json()),
fetch('/api/orders').then(res => res.json())
]).then(([users, products, orders]) => {
// Process data
});
This code pattern could potentially lead to a network waterfall if there are dependencies between requests, though Promise.all itself is actually designed to avoid this issue by running promises in parallel. The potential performance issue occurs if these API endpoints have dependencies on each other or if they compete for the same server resources. In cases where one API actually depends on the result of another, this parallel approach could cause unnecessary requests or errors. Additionally, some APIs might perform better when called sequentially due to server-side resource constraints. For truly independent requests, Promise.all is efficient as it allows all requests to execute concurrently and resolves when all are complete. However, if you need to control the order or handle different failure scenarios independently, consider alternative patterns or more granular promise handling.