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?


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