Member-only story
Building Microservices with Python , Part I
Currently I am working in my current job as a Software Engineer at HelloFresh on the DataWarehouse Team. I am working on data pipelines and building tools around our infrastructure, like Documentr.
By the way, we are hiring in those positions: Data Engineer and Backend Engineer.
But at the end, I am a Software Engineer interested in many different areas. This post it is going to be focus on Backend Development and how I am building microservices on a personal project I am working.
You can find all the code in this repo: https://github.com/ssola/python-flask-microservice
Purpose
Nowadays it is a common practice to work in smaller applications, sharing the responsibility among many different services. I believe it is critical to have some standard tools between the teams working solving those problems.
In my opinion a Microservices should have some basic features:
- Easy to start coding your logic, stop worrying about tools/patterns.
- Documentation, an essential feature to share how your service it is going to work. In this case, Swagger works pretty well.
- Serializing your input/output in a way shared among all applications. You need to chose a technology like Avro/Protobuf. This is mandatory to be sure all services are sharing the same entities.
- Events, probably your application it is going to generate events that can be consumed by others. For instance, in my project, every time a new room is inserted into the system, that piece of information is serialized with avro and spread among all the other services.
Stack and Patterns
In this basic setup we are going to include those packages:
- Flask (as a Framework)
- connexion (helpful tool to generate routes and Swagger docs)
- Flask-Injector (Dependency Injection package)
- Avro (or any data serialization package)
In this case, I chose Flask because I find it super useful to build small services without all the learning curve of Django. I just need something to help to do the routing and I will include whatever I need on it.
Connexion is a project from Zalando that adds a layer on top of Flask to help you building your RESTFul API in a…