Menu

Concurrent calls with asyncio: timeouts and graceful degradation
📰

Concurrent calls with asyncio: timeouts and graceful degradation

DEV Community: fastapi·Eduardo Teixeira·10 days ago
#P8YtxGsP
Long article (1042 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.