Gateways to the Web

rajath cs
2 min readJun 21, 2021

A gateway interface is a mode in which the web application interacts with the external world.

Two most talked about Gateway Interfaces are:

  • WSGI — Web Server Gateway Interface

Guicorn is one good example of WSGI server. In WSGI, requests between the client are handled sequentially. Frameworks like Django and Flask are WSGI-based.

  • ASGI — Asynchronous Server Gateway Interface

Uvicorn is one good example of ASGI server. In ASGI, requests between the client are handled concurrently. Frameworks FastAPI and Starlette are purely ASGI based.

Understanding in Layman terms

Let's understand WSGI and ASGI with daily work.

Let's say you are trying to make coffee and an omelet. If you were a WSGI, below are the steps you’d take:

  • Take milk out of the fridge.
  • Take Tea powder and Sugar
  • Warm the milk
  • Add tea powder to milk
  • Add sugar and stir.

You will now jump on to making an omelet.

  • Get eggs
  • Light the stove and pour oil and heat the stove for a while.
  • Pour egg and make an omelet.

If you were an ASGI, you would instead take the below approach to finish making an omelet and a tea:

  • Take milk out of the fridge.
  • Take Tea powder and Sugar
  • Warm the milk
  • While the milk is boiling in low flame:
  • Get eggs
  • Light the stove and pour oil and heat the stove for a while.
  • Pour egg and make an omelet.
  • By now, as we observe that the milk is boiled:
  • Add tea powder to milk
  • Add sugar and stir.

In effect, what happens internally in ASGI based web interactions is — the application understands which request process takes more time, and based on this it moves on to the next API call. This is technically termed as concurrent processing.

Final Thoughts

The three main advantages of ASGI over WSGI are that it can handle:

  • more I/O operations
  • more request per minute
  • more load

The future of web application development and backend API interaction is driven by how many requests can be handled in a single thread pool. Thus, handling and managing asynchronous calls will only become much efficient and easier. Both Django and Flask communities today are actively building parallelizing modules to improvising asynchronous calls.

Stay tuned for my next article on a demo example of FastAPI. Happy Coding!!!

--

--