Search code examples
pythonmicroservicespython-3.7

Python high load capable microservice architecture


I wanted to ask you about microservices in Python. As of writing this, i got pretty good with writing well structured flask-restful APIs and I wanted to go and learn about microservices in python.

Right now I have read up quite a lot of info regarding this and even searched online to find examples for this (1 example here) but I am not really sure exactly where to start as I don't want to invest too much time in a inefficient pattern.

So I wanted to know if anyone know any courses with examples for Python on building high load services. My only hints so far as asyncio and aiohttp for request handling and i'm not sure if using a message broker (such as zeromq or rabbitmq) would be a good idea as from what I read, it adds request lag.

Any advice would be great.

PS: The current pattern I'm stuck on is the API Gateway pattern and I would also want to know if it is a good direction as a start.


Solution

  • There are plenty of microservice frameworks in Python that can handle high load and get you a long way towards following best practices.

    Try for example pymacaron (http://pymacaron.com/). Pymacaron is basically a flask app whose endpoints are auto-spawn from a swagger specification. To write a pymacaron microservice, you mostly have to:

    (1) write a swagger specification for your api (which is always a good starting point, whatever language you are using). Your swagger file describes the get/post/etc calls of your api and which objects (json dicts) they get and return, but also which python method in your code that implement the endpoint.

    (2) and implement your endpoints' methods.

    Once you have done that, you get loads of things for free: you can package your code as a docker container, deploy it to amazon beanstalk, start asynchronous tasks from within your api calls, or get the api documentation with no extra work.

    Here is an example of an helloworld api implemented with pymacaron: https://github.com/pymacaron/pymacaron-helloworld