DEV Community

Discussion on: How to scale python server, for enterprise purposes?

Collapse
 
miniscruff profile image
miniscruff

First make sure your server can be scaled horizontally. That is, you can run multiple instances of the server and all will work without issue or speed reduction. Any occasionally overlooked step.

Then instead of running flask directly use a wsgi server such as gunicorn. If you are feeling up to the challenge you can try asynchronous frameworks like responder, starlette or bocadilla. Both sides are trying to solve the same problem of handling as many requests as quickly as possible.

Celery can be used for long running or not time sensitive background tasks like daily metrics and the like.

You may also need to look as database stuff like scaled postgres or using redis for faster reads. This will be much more dependent on your app and I would look at this last. But is worth keeping in mind as you scale up.

This will be enough to handle quite a number of users already, but for extra reliability and throughput I recommend some sort of load balancer. This comes in many flavors. From the simple nginx host to the mighty kubernetes cluster.

Whatever you choose be sure to always automate it, DevOps is invaluable at all sizes.

Collapse
 
perigk profile image
Periklis Gkolias

Thanks for the great tips. Are you suggesting, not to use celery for plain requests that for example write a few KB in the DB? Is ASGI(where bicadillo etc are based on) stable enough?

Collapse
 
miniscruff profile image
miniscruff • Edited

If that write to the DB if required before you can return a response to the user than yes. I would check out the new asynchronous database tools like tortoise or the one by the starlette guys. Regardless with enough workers it shouldn't slow down your service.

I would say they are pretty stable, i would look around before choosing one for long term. FastAPI and responder were my top 2.