Why ASGI is Replacing WSGI in Django
Tags: python, webdev, beginners, django
Published: 2020-01-19 05:27:50

# Introduction
![undraw success factors fay0][1]

When I first learnt about how to deploy my Django website. I took the easy route which was deploying it on Heroku. 

There's literally tons of tutorial on how the process of deploying it work. Heck, there was even a book about the benefits of deploying Django using Heroku.

Soon in my own work, I needed to deploy my own Django project. It was working well for a bundled development grade web server. I thought to myself, why not find a better way on a production-grade web server. Instead of just a miserable default web server that is not production-grade.

My journey in searching on deploying Django started for me. Which if you look at multiple tutorial references they still suggest the use of Heroku or Digital Ocean.

# What is WSGI?
![undraw researching 22gp][2]

WSGI stands for [Web Server Gateway Interface][3]. It is essentially the standard that talks about how Python web applications are deployed. 

WSGI servers were there to help standardise the deployment process among various frameworks even till this day. Which the popular choice was Flask and Django. 

Now there is a ton of choices to select in deploying Django through WSGI. The traditional route was using [mob_wsgi][4] that is an additional module for the [Apache][5] web server where PHP & Java uses it to deploy their web applications.

The others are more towards specific niches or purposes like if you had a small project. I would choose [uWSGI][6], due to it's all in one nature. Which bundles static file asset hosting, caching, SSL connections, reverse proxy & task queuing.

The other popular choice was having [Gunicorn][7] for flask applications to be bundled together to deploy it with [Nginx][8].

# ASGI Replaces WSGI for the Future
![undraw success factors fay0][9]

WSGI server has served an important purpose to make deployment of web applications easy for a web framework like Flask or Django as part of backend infrastructure instead of a full-stack solution due to the raise of frontend web framework like Angular, React and Vue.

The problem comes down to its relevancy where **asynchronous** requests are becoming the norm in Javascript land. New technologies like [HTTP/2][10] or [Websockets][11] is being used as part of front-end development. 

Therefore it is expected that in the future for web development **asynchronous** requests are considered the norm. Instead of being replaced by other backend technologies like ExpressJS, Laerval or Go.

# The World with ASGI
![undraw completed steps yurw][12]

Moving forward, I am excited about how ASGI can help a lot in the Python community. 

In the use of **async** & **await** capabilities, **web sockets** and **http/2** to make it faster and to remain relevant as the backend of choice for Django moving forward.

To me, Django might leak into the realms of microservices. Which [Zappa][13] took a different approach by integrating with AWS related. Please **donate** to the project if you had gain value from it to keep the project alive and well.

ASGI will be used more often and hopefully allows anyone to break the dependency of [Celery][14]. Which can be a pain to set up and maintain when developing in Django with it.

# Conclusion
![undraw online everywhere cd90][15]

Wow, that's a lot of things I wrote about ASGI. Moving forward if you don't require an asynchronous request, WebSockets & HTTP/2. It won't put much of a dent to you as a Django developer. 

Instead, I would use WSGI servers like uWSGI or Gunicorn to help in my deployment. If I'm going for a customised approach to deploying my web applications on a server.

I had heard great things about cloud providers like AWS, Azure and Google Cloud. Besides that, I am thinking of playing around with [Digital Ocean][16] for their [Hatch][17] program for Startups and [Linode][18] that was recommended by [Chris Hawkes][19].

In future articles, I'm thinking of playing around with various deployment options in the cloud. Since it feels like a growing trend to deploy it on these cloud providers.

If you like this article **sign up** for my [Adventurer's Newsletter](https://maxongzb.activehosted.com/f/1) for a weekly update in the area of **Python**, **Startup** and **Web Development**.

You can also **follow** me to get the **latest** update of my article on **Dev**

The original post was on [Why ASGI is Replacing WSGI in Django - Reading Time: 3 Mins](https://www.maxongzb.com/why-asgi-is-replacing-wsgi-in-django-reading-time-3-mins/) and cover image by [timJ on Unsplash](https://unsplash.com/photos/gM6k0JmHIBE)


# Reference
* [Web Server Gateway Interface][3]
* [An Introduction to ASGI,  Asynchronous Server Gateway Interface][20]
* [How to Deploy with ASGI][21]
* [How to Use Django with Daphne][22]
* [How to Use Django with Uvicorn][23]
* [A Single File Async Django Application][24]
* [Hello ASGI][25]
* [Django Channels][26]
* [Django 3.0 begins its async-capable journey with ASGI
](https://jaxenter.com/django-3-0-165173.html)
* [The ASGI Revolution is Upon Us][27]
* [mob_wsgi][4]
* [uWSGI][6]
* [Gunicorn][7] 
* [Nginx][8]
* [HTTP/2][10]
* [Websockets][11] 
* [Zappa][13]
* [Celery][14]
* [Digital Ocean][16]
* [Hatch][17]
* [Linode][18]
* [Chris Hawkes][19]
* [Undraw][28]


[1]: //images.ctfassets.net/ly2f59p4unnn/6ZkOExre0y8BreyJLB0YAY/b57863d79c8bd000213956a6bcd16087/undraw_success_factors_fay0.png
[2]: //images.ctfassets.net/ly2f59p4unnn/5jCoR2UC8AQ57D2N4PzJLr/f57e0d256597ec207fa260a313ec344e/undraw_researching_22gp.png
[3]: https://wsgi.readthedocs.io/en/latest/what.html
[4]: https://modwsgi.readthedocs.io/en/develop/
[5]: https://httpd.apache.org/
[6]: https://lincolnloop.com/blog/uwsgi-swiss-army-knife/
[7]: https://gunicorn.org/
[8]: https://www.nginx.com/
[9]: //images.ctfassets.net/ly2f59p4unnn/1V6YtJx2ujCXuvh3p8KGnN/9df8203d4cf49994c5505ec554bb3859/undraw_success_factors_fay0.png
[10]: https://developers.google.com/web/fundamentals/performance/http2
[11]: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API
[12]: //images.ctfassets.net/ly2f59p4unnn/7qzqRKENQjcdGPXNons1cj/367155d7eca9cbc9f80596d87f7a1465/undraw_completed_steps_yurw.png
[13]: https://github.com/Miserlou/Zappa
[14]: http://www.celeryproject.org/
[15]: //images.ctfassets.net/ly2f59p4unnn/h40sdV9Vut3VmldGMVX9h/683ff457617e9921448dd3091b02f700/undraw_online_everywhere_cd90.png
[16]: https://www.digitalocean.com/
[17]: https://www.digitalocean.com/hatch/
[18]: https://www.linode.com/
[19]: https://www.youtube.com/channel/UCfV36TX5AejfAGIbtwTc7Zw
[20]: https://youtu.be/uRcnaI8Hnzg
[21]: https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
[22]: https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/daphne/
[23]: https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/uvicorn/
[24]: https://adamj.eu/tech/2019/09/14/a-single-file-async-django-app/
[25]: https://www.encode.io/articles/hello-asgi
[26]: https://github.com/django/channels
[27]: https://pythonbytes.fm/episodes/show/148/the-asgi-revolution-is-upon-us
[28]: https://undraw.co/illustrations