Skip to content

Async Internals in FastAPI: What Actually Happens When You await #420

@SamIeer

Description

@SamIeer

Talk title

Async Internals in FastAPI: What Actually Happens When You await

Short talk description

Most FastAPI developers write async def and trust that things work — but what's actually happening under the hood? This talk goes past the surface to explain how Python's event loop, coroutines, and Starlette work together to handle concurrent requests on a single thread. Using a real production app (Commudio, an AI communication coach) as the running example, we'll cover what await really means at runtime, why blocking the event loop silently kills performance, and when to use asyncio.gather() vs BackgroundTasks. By the end, you'll be able to reason about async behaviour — not just use it.

Long talk description

When I deployed Commudio — an AI speech coach I built with FastAPI — 15 users hit the transcription endpoint simultaneously. No crashes, no queue pile-up. They were all processed concurrently without a single thread being spawned. The reason: Python's async model. But most developers I've spoken to don't fully understand why it works — or more importantly, why it sometimes silently doesn't.

This talk tears open the abstraction. We start with the most common misconception: that async/await is related to threading. It isn't. async/await is cooperative multitasking on one thread — your code voluntarily yields control by writing await, and the event loop uses that window to run other coroutines.

From there, we look at how FastAPI's runtime stack actually works: your route function sits on top of Starlette, which speaks ASGI, which is served by Uvicorn, all of which runs on Python's asyncio event loop. Every incoming HTTP request becomes a coroutine. This isn't an implementation detail — it's the architecture.

We then cover two practical patterns with direct code examples: asyncio.gather() for when you need concurrent results from multiple coroutines, and FastAPI's BackgroundTasks for fire-and-forget workloads where the client shouldn't have to wait. Both patterns are drawn from Commudio's real production architecture.

Finally, we cover the #1 silent bug: blocking the event loop with synchronous code inside an async def route. time.sleep, standard file I/O, and synchronous HTTP clients all freeze the entire thread — affecting every concurrent request. We'll see non-blocking alternatives for each.

The talk is grounded in a real shipped project and uses one running example throughout, making abstract concepts concrete. It's aimed at developers who already use FastAPI or asyncio but want to actually understand what's happening — not just that it works.

What format do you have in mind?

Talk (20-25 minutes + Q&A)

Talk outline / Agenda

• The hook — a real production story: 15 users, zero threads (2 min)
• What async/await actually is: coroutines, the event loop, cooperative multitasking (3 min)
• How FastAPI's runtime stack works: asyncio → uvicorn → Starlette → your route (4 min)
• Real patterns from production: asyncio.gather() vs BackgroundTasks (3 min)
• The #1 silent bug: blocking the event loop with sync code inside async def (2 min)
• Key takeaways and closing hook (1 min)
• Q&A (5 min)

Key takeaways

• Understanding of how Python's asyncio event loop works and why async ≠ threads
• Practical knowledge of when and how to use asyncio.gather() vs FastAPI BackgroundTasks
• Understanding of how FastAPI, Starlette, Uvicorn, and asyncio form a layered async runtime
• Common pitfall to avoid: blocking the event loop with synchronous I/O inside async def routes
• Resources and next steps for going deeper into asyncio and ASGI internals

What domain would you say your talk falls under?

Core Python

Duration (including Q&A)

25 minutes (20 for the talk & 5 Q|A)

Prerequisites and preparation

• Basic Python knowledge (functions, decorators, basic syntax)
• Some familiarity with FastAPI or any Python web framework is helpful but not required
• No prior knowledge of asyncio or async programming is assumed
• No laptop or setup needed; this is a conceptual + code-reading talk, not a hands-on workshop

Resources and references

• Python asyncio docs: https://docs.python.org/3/library/asyncio.html
• FastAPI async explanation: https://fastapi.tiangolo.com/async/
• Real Python — Async IO in Python: https://realpython.com/async-io-python/
• Starlette source (FastAPI is built on this): https://github.com/encode/starlette
• Commudio (the project used as the running example): https://github.com/SamIeer/Commudio

Link to slides/demos (if available)

No response

Twitter/X handle (optional)

@SameerChau45139

LinkedIn profile (optional)

https://www.linkedin.com/in/sameer-chauhan-363298269/

Profile picture URL (optional)

No response

Speaker bio

I’m Sameer Chauhan, a Python developer from Delhi currently interning at the Airtel , where I work on data automation workflows. I was also selected for Google Summer of Code'25 under OpenSUSE for a project focused on MLOps systems, where I worked on ML reproducibility and traffic prediction pipelines.

My most relevant project for this talk is Commudio — an AI communication coach I built end-to-end using FastAPI, Whisper, the Groq API, PostgreSQL, and Docker. The async backend architecture I’ll discuss is what enables Commudio to handle concurrent audio uploads reliably in production.

Beyond development, I actively write about AI, async systems, and automation, with 20+ technical articles published, including several in AI-focused Medium publications.

This is my first public talk, and I’m excited to share lessons I had to learn the hard way in building scalable async systems. Fun fact: I built Commudio partly to improve my own communication skills — so giving this talk feels like a full-circle moment.

Availability

23/05/2025 (PyDelhi May Meetup)

Accessibility & special requirements

No response

Speaker checklist

  • I have read and understood the PyDelhi guidelines for submitting proposals and giving talks
  • I have read and acknowledged the PyDelhi accessibility guidelines and will ensure my presentation materials (slides, videos, demos) follow these recommendations
  • I will make my talk accessible to all attendees and will proactively ask for any accommodations or special requirements I might need
  • I agree to share slides, code snippets, and other materials used during the talk with the community
  • I will follow PyDelhi's Code of Conduct and maintain a welcoming, inclusive environment throughout my participation
  • I understand that PyDelhi meetups are community-centric events focused on learning, knowledge sharing, and networking, and I will respect this ethos by not using this platform for self-promotion or hiring pitches during my presentation, unless explicitly invited to do so by means of a sponsorship or similar arrangement
  • If the talk is recorded by the PyDelhi team, I grant permission to release the video on PyDelhi's YouTube channel under the CC-BY-4.0 license, or a different license of my choosing if I am specifying it in my proposal or with the materials I share

Additional comments

This is my first talk at any meetup. I would genuinely appreciate any feedback on the proposal or the talk structure before the event — happy to do a dry run or get reviewed.
One small request: if there's a mentor or experienced speaker who could give me 10 minutes of feedback beforehand, that would mean a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting response from authorThis proposal needs a response from the author in order for a decision to be made on its schedulingproposalWish to present at PyDelhi? This label gets added when the "Talk Proposal" option is chosen.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions