This post was originally published in Portuguese on my blog: Chamadas concorrentes com asyncio, timeout e degradação graciosa .
You know that screen that needs data from three different services? Customer profile, recent orders, recommendations. The most common way to write it is to call one after the other with await , and the result is that the screen takes the sum of all the calls. Worse: when the recommendations service chokes, the whole screen chokes with it, even though nobody cares that much about recommendations.
In this post I show a small aggregator that solves both problems: it calls everything at the same time with asyncio.TaskGroup , puts a timeout on each call, and decides what is required and what can be left out.
The core idea
The business rule is simple. The customer profile is required: without it there's no dashboard.…