What is the difference between WSGI and ASGI?
Answer
WSGI (Web Server Gateway Interface) is a synchronous Python standard for web servers and web applications to communicate. One request is handled at a time per process/thread — the server calls the WSGI application, waits for the response, then handles the next request. Flask and Django (by default) are WSGI frameworks. ASGI (Asynchronous Server Gateway Interface) is the modern async successor. It supports async handlers (async def) and long-lived connections like WebSockets and Server-Sent Events. Multiple requests can be handled concurrently in a single thread using Python's event loop. FastAPI and Django Channels are ASGI frameworks. Servers: WSGI — Gunicorn, uWSGI. ASGI — Uvicorn, Hypercorn, Daphne. For I/O-bound workloads (database queries, HTTP calls), ASGI with async handlers provides dramatically better concurrency than synchronous WSGI.