Python Serverless Microservices

Nilo Ney Coutinho Menezes

Abstract:
Microservices and serverless are hot topics in web development communities that when combined increase the potential for developers to make software faster and to host it much cheaper than traditional virtual private servers. This talk aims to present a minimal set of tools to start developing Serverless Microservices using Python. With the serverless framework configured for Python, developing a new microservice API becomes very easy. The framework provides a set of tools to pack Python dependencies and also deploys the required infrastructure to the cloud, enabling infrastructure as code since the start of the project. Although the serverless framework is used during this presentation, no other Python framework is required, making it as easy as possible to start with plain Python code.

Bio:
I’m a software architect that loves to program in Python and to design new software to run in the cloud. A professional computer programmer since the '90s, I have a BS (Data Processing) and MS (Informatics, computer networks) degrees from the Federal Univerisity of Amazonas (Brazil) and an incomplete PhD at the University of Mons (Belgium). I wrote a book about Python Programming for beginners, published in Portuguese and Spanish. I try to participate in the Brazilian Python community, especially in the North region of Brazil (9 states), trying to spread Python in the Amazon area.

4 Me gusta

Are there systems to deploy “semi-static” websites, like something you could achieve with a simple Flask site? Some community groups want to deploy some simple sites which are not 100% static and I think something like serverless, which often is almost free, could be a good option instead of having to deal with server management or containers.

What about “warming” periods? I heard something about lambdas needing some pre-loading, otherwise they don’t respond immediately. But I might be wrong.

Yes, you can combine static sites with lambda functions to create semi-automatic or sites that change very slowly. In AWS, you can deploy the static sites using S3 and Cloudfront as a CDN (Content Delivery Network). You can also include javascript in these pages to call Lambda functions.
There are also other options, like a site that can auto-rebuild itself. It works when the lambda updates the content of a page and triggers the rebuild of static files. This process is also very good when the pages don’t change a lot.
To really take profit of lambdas, IMHO, we need to leverage parallel requests, as we make when building a single page application in React or Angular. With parallel requests, the warmup time almost disappear and the site can be very dynamic.
Something I didn’t talk is that we can also use Lambda functions to implement websockets.

Regarding warming periods, they exist and depending on the required application responsiveness can be tricky. Nowadays, you have the option to set the number of functions to stay in a ready state. For large web sites, this option works very well. Most of the time, I don’t use any of these, as the system warms himself up as you start to use it. The warmup time in Python is around 1s for the first call + 200 ~ 500 ms per execution if you access a remote database. It is not very bad, but it also depended on how the user will see the app with these delays. The warmup only happens when a new instance is created. As AWS keep it running for a few minutes, the next call will be promptly answered. Python has one the best warmup times for lambda functions on AWS.