What is meant by "Async out, Sync in".

Hello, I wanted to deploy my Django application using a ASGI web server. But I am not able to understand the statement that Django is “Asynchronous out, synchronous in”. Which, I think, means that the web server can handle requests asynchronously but Django will handle those requests synchronously. Then what is the point of doing all this.
I want to understand how everything is working inside.

Where’s this phrase come from?

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-asgi-django-app-with-postgres-nginx-and-uvicorn-on-ubuntu-20-04#:~:text=Django%20allows%20for%20an%20%E2%80%9Casync%20outside%2C%20sync%20inside%E2%80%9D%20mode%20that%20allows%20your%20code%20to%20be%20synchronous%20internally%2C%20while%20the%20ASGI%20server%20handles%20requests%20asynchronously.

The phrase is highlighted.

Django allows for an “async outside, sync inside” mode that allows your code to be synchronous internally, while the ASGI server handles requests asynchronously. By allowing the webserver to have an asynchronous callable, it can handle multiple incoming and outgoing events for each application. The Django application is still synchronous internally to allow for backward compatibility and to avoid the complexity of parallel computing. This also means that your Django app requires no changes to switch from WSGI to ASGI.

Both the WSGI and ASGI handlers that Django provides are able to process either synchronous or asynchronous views, so the particular protocol you use doesn’t matter for this.

In the case of this post, it means you can switch to ASGI without having to rewrite all your code.

The advantage of ASGI comes if you do have fully asynchronous code, and need to handle lots of (I/O bound) connections concurrently, without using a thread per-connection. (The usual example of this is websockets, although Django itself doesn’t support this, but similar things are possible with asynchronous HTTP views.)

Django’s async topic docs is probably the place to begin Asynchronous support | Django documentation | Django

1 Like