What is the difference between WSGI and ASGI, and why did the Python web ecosystem need a new standard?
Answer
WSGI (Web Server Gateway Interface) is the older standard interface between a synchronous Python web application and a web server: it processes exactly one request at a time per worker thread or process and has no native concept of asynchronous code, WebSockets, or long-lived connections. ASGI (Asynchronous Server Gateway Interface) extends the same idea to support `async`/`await`-based applications, letting a single worker handle many concurrent connections cooperatively, including WebSockets and server-sent events, which WSGI's one-request-at-a-time synchronous model cannot express at all.
Strong answer includes
- WSGI is synchronous, one request per worker at a time, no native async or WebSockets
- ASGI extends the interface to support async/await and long-lived connections
- ASGI enables WebSockets and concurrent connections per worker, which WSGI cannot
Practical example
A WSGI-based Flask app needs a separate library and architecture to support WebSocket chat, while an ASGI-based FastAPI app can define a WebSocket route directly alongside its regular HTTP routes.