Zhorzh Alexandr Zhorzh Alexandr - 3 months ago 32
Python Question

How can i combine flask and nameko?

How can i combine Flask web application and Nameko microservices?

Let me give you some context. I have flask-based (http://flask.pocoo.org) web application. This application can execute long (5-10 minutes) tasks. I want to be able to write and attach additional modules to this application while it is still running. It is OK if I stop application while in development, but I cannot stop it in production.

I dont have any experience with Nameko (https://nameko.readthedocs.org), is it the best solution to my problem? And if so - can I mix Flask app and Nameko microservices?


Contributor to nameko here. I agree with nathancahill that celery is a good choice for this.

You absolutely can use nameko and Flask together. There’s a short example in a gist here: https://gist.github.com/mattbennett/4250ce5d56b36a99bc39

In that configuration though, you're covering the same ground that Celery was built for -- namely handling long-running tasks outside the request-response cycle. Frankly the example in the gist would be much better implemented exclusively as a nameko app (using the built-in http entrypoint), because it’s not using any of the more advanced web framework-like features that Flask gives you.

If you want to write microservices, even ones that are predominantly HTTP based, nameko provides some nice tooling for doing so. If you just want to add async processing to an existing webapp, celery would be the standard choice.