← PracticeAdvancedCoordination

We Made the Endpoint 30x Faster and Broke the Database

Pull up the evidence one item at a time, commit to a diagnosis, and only then see the schedule that actually ran.

What was reported

Our dashboard endpoint used to take 6.2 seconds — a loop of 60 sequential awaits, one per widget. We changed the loop to Promise.all and it now takes 190ms. Everyone was delighted. Two days later, during Monday peak, the database started refusing connections, and three other services that share that database began timing out. Our endpoint is still fast. We have rolled forward, not back, because nobody wants to give up the 30x.
1// before: 6.2s
2// for (const w of widgets) results.push(await loadWidget(w))
3
4// after: 190ms
5const results = await Promise.all(widgets.map(w => loadWidget(w)))
6
7// loadWidget borrows a pooled connection and runs one query

Evidence

Nothing here is labelled as relevant. Some of it is not.

What is actually happening?