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
- get the milk , sugar , coffee powder
- turn on the stove
- warm the milk
- add sugar and coffee powder
pore it in coup
get the lemon, sugar, water, ice cubes and salt
cut the lemon and squeeze into the coup
add sugar, water, ice cubes and salt
pore it in the coup
this is what the step will follow by the wsgi but in the case of asgi
- get the milk , sugar , coffee powder
- turn on the stove
warm the milk
get the lemon, sugar, water, ice cubes and salt
cut the lemon and squeeze into the coup
add sugar, water, ice cubes and salt
pore it in the coup
add sugar and coffee powder
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)