What is ‘WSGI’ & ‘ASGI’? — Exploring their Key Differences
Short & precise description of the 2 Python web server interfaces, their framework differences & use cases.
Before we understand WSGI & ASGI, please note that — Web frameworks such as Flask & Django can be used with either WSGI or ASGI, but by default, they don’t have inbuilt support for asynchronous programming.
To use Flask with ASGI, you will need to use a third-party library such as gunicorn
whereas for Django, you will need a library such as uvicorn
.
WSGI
WSGI stands for Web Server Gateway Interface. A ‘WSGI’ is a type of interface that sits between the server and the client. This interface dictates the method of data exchange between the client & the server.
WSGI is older & is very widely used by a lot of companies & applications. Some examples are —
- Spotify
- Airbnb
Key points about WSGI —
- Synchronous: WSGI is synchronous in nature, meaning that an application will need to process the current request before accepting a new one. This leads to a longer processing time when handling multiple requests at once. (This can, however, be mitigated to an extent with the help of workers!)
- No Asynchronous Programming Support: WSGI does not provide in-built support for asynchronous programming which can be a problem if one is used to writing asynchronous code.
- Widely Adopted: WSGI has one big advantage over ASGI, which is its wide adoption. WSGI is a mature server interface and has seen usage across many major platforms & applications.
ASGI
ASGI stands for Asynchronous Gateway Interface. An ‘ASGI’ is again, a type of interface that sits between the server and the client. This interface dictates the method of data exchange between the client & the server.
Unlike WSGI, ASGI is not very old & is also very widely used by a lot of websites & applications. Some applications & technologies that use ASGI—
- Discord
- Twitch
- Next.js
Key points about ASGI —
- Asynchronous: ASGI is asynchronous in nature, meaning that an application doesn’t need to process one request before accepting a new one. It can accept multiple requests at the same time & work on them parallelly. This leads to a shorter processing time when handling multiple requests at once.
- Asynchronous Programming Support: An Asynchronous interface supports & encourages an asynchronous programming paradigm.
- Less Adopted: ASGI might have a small drawback compared to WSGI, which is its lower adoption rate.
This was a short summary of what is WSGI & ASGI & what are their key attributes. I know the post was very short, hence there will be a follow-up article on why you should switch to an ASGI framework, so stay tuned & thanks for reading! 🖤
Check out these other awesome posts —
In Plain English
Thank you for being a part of our community! Before you go:
- Be sure to clap and follow the writer! 👏
- You can find even more content at PlainEnglish.io 🚀
- Sign up for our free weekly newsletter. 🗞️
- Follow us on Twitter, LinkedIn, YouTube, and Discord.