DEV Community

Stephen BJ
Stephen BJ

Posted on

ASGI and WSGI

HI all,
welcome to an other interesting topic about the servers in python

lore: while i was interviewed interviewer ask me a question why did you chose fastapi instead of django and flask. i was stuck for few min because what i did before i pick the framework just google + GPT's and get the best framework for my project. (actually they told me why it was the best option also). i didn't pick up django because it has very big learning curve but it provide lots of functionalities like ORM, middleware , auth etc., out of the box.

Now, will see why exactly the major and important thing on selection of Fast vs Flask is ASGI ** and **WSGI

ASGI provide the asynchronous feature which WSGI is not offers (best of my knowledge ) my be it is debatable

lets take a process like Make coffee and lemon juice:

steps like

  1. get the milk , sugar , coffee powder
  2. turn on the stove
  3. warm the milk
  4. add sugar and coffee powder
  5. pore it in coup

  6. get the lemon, sugar, water, ice cubes and salt

  7. cut the lemon and squeeze into the coup

  8. add sugar, water, ice cubes and salt

  9. pore it in the coup

this is what the step will follow by the wsgi but in the case of asgi

  1. get the milk , sugar , coffee powder
  2. turn on the stove
  3. warm the milk

  4. get the lemon, sugar, water, ice cubes and salt

  5. cut the lemon and squeeze into the coup

  6. add sugar, water, ice cubes and salt

  7. pore it in the coup

  8. add sugar and coffee powder

  9. pore it in coup

this is how the asgi will do
now we may have question like ok it do only one request can handle at the time direct answer is no. in this place service worker play's an major role for example we may have multiple person doing this . but the problem is kitten size if the kitten fit only for one person we can add multiple people in it

in similar way WSGI can have multiple workers but the workers limit based on the CPU size like Number of core X 2 that is the max

Conclusion

WSGI is not bad. it's just done evolving.
ASGI is what the modern internet expects.

In platform terms:
WSGI = stable, predictable, capped
ASGI = scalable, concurrent, future-proof

in my term based on the context it is mater if the process has move cpu related one and not request intensive both will give the same result

Top comments (0)