“WSGI (Web Server Gateway Interface) is synchronous: each concurrent HTTP connection occupies an entire OS worker thread. ASGI (Asynchronous Server Gateway Interface) is asynchronous: a single Python process running an event loop (Uvicorn on uvloop) coordinates thousands of concurrent requests by suspending I/O waiting periods via standard async/await.”
Why traditional WSGI synchronous servers block threads, and how ASGI enables non-blocking async Python I/O.
# ASGI Application Function Contract
async def app(scope, receive, send):
assert scope['type'] == 'http'
await send({
'type': 'http.response.start',
'status': 200,
'headers': [[b'content-type', b'application/json']],
})
await send({
'type': 'http.response.body',
'body': b'{"status": "ok", "engine": "uvicorn"}',
})Uvicorn opens non-blocking socket listener via uvloop (libuv C binding)
Constructs ASGI scope dictionary containing request headers, client IP, and HTTP path
Calls application(scope, receive, send) asynchronously
Middleware intercepts and mutates scope/headers
Streams response bytes chunk-by-chunk through send({"type": "http.response.body"})
Running Uvicorn with uvloop delivers 300% higher HTTP request throughput than standard Python asyncio by utilizing libuv native C event polling.