Django and DRF · senior
Async views in Django: what they change and what stays synchronous
Async views help when one request waits on several slow I/O calls. The ORM and drivers underneath are still synchronous, so async does not make simple CRUD faster.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Async helps when a request waits on several slow calls at once (three partner APIs with httpx.AsyncClient and asyncio.gather), for long polling, streaming and server-sent events. It does not speed up CPU-heavy views or simple CRUD.
- You need an ASGI server for the benefit. Under WSGI an async view runs in a one-off event loop per request.
- The ORM has async methods (aget, acreate, async for), but the ORM and drivers still run synchronously and hand the work to a thread with sync_to_async.
- Calling the sync ORM directly in an async view raises SynchronousOnlyOperation.
- Transactions do not work in async mode: put the transactional code in a sync function and call it with sync_to_async.
- thread_sensitive=True (the default) runs sync code in one thread, because database connections must stay in the thread that opened them.
- A sync middleware between the server and an async view means a switch to a thread and back on every request.
- DRF has no native async views; teams use plain async Django views, adrf or Django Ninja for async APIs.
The red pen
Common traps: mistake → fix
Mistake: Changing all views to async def makes the API faster
Fix: it helps only with concurrent waiting.
Mistake: The async ORM is fully async
Fix: it runs sync code in a thread underneath.
Mistake: Async views under WSGI give concurrency
Fix: they need ASGI.
Easy to hard
Questions interviewers ask, easy to hard
- If we change all views to async def, will our API get faster?
- What in Django is still synchronous?
- What is SynchronousOnlyOperation?
- How do you use a transaction in an async view?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.