Book Image

Building Serverless Microservices in Python

By : Richard Takashi Freeman
Book Image

Building Serverless Microservices in Python

By: Richard Takashi Freeman

Overview of this book

Over the last few years, there has been a massive shift from monolithic architecture to microservices, thanks to their small and independent deployments that allow increased flexibility and agile delivery. Traditionally, virtual machines and containers were the principal mediums for deploying microservices, but they involved a lot of operational effort, configuration, and maintenance. More recently, serverless computing has gained popularity due to its built-in autoscaling abilities, reduced operational costs, and increased productivity. Building Serverless Microservices in Python begins by introducing you to serverless microservice structures. You will then learn how to create your first serverless data API and test your microservice. Moving on, you'll delve into data management and work with serverless patterns. Finally, the book introduces you to the importance of securing microservices. By the end of the book, you will have gained the skills you need to combine microservices with serverless computing, making their deployment much easier thanks to the cloud provider managing the servers and capacity planning.
Table of Contents (13 chapters)
Title Page
Dedication

Preface

As companies become more agile and reactive, they are moving away from large and complex monolithic architectures that are hard to scale, toward microservice architectures based around containers, which are more flexible and easier to deploy. For example, you could have a loosely coupled fleet of microservices, each with an Application Programming Interface (API) for each data source, integrating with a clustered NoSQL database such as Cassandra. In such modern microservice architectures, it is common to quickly iterate and regularly deploy microservices with a RESTful API for integrating with other systems such as visualizations, user interfaces, or even with other third parties.

However, there are many architectural, infrastructural, and developmental complexities to consider in the deployment, maintenance, and monitoring of such microservices when using containers. Additionally, you need to consider costs and the scalability of the API and data store, meaning that you typically need a DevOps team that sets up, monitors, and maintains the Continuous Integration/Continuous Deployment (CI/CD) pipelines, Kubernetes (https://kubernetes.io/) container-orchestration platform, and monitoring systems. Things are looking better recently, as AWS has announced Amazon Elastic Container Service (ECS) for Kubernetes (https://aws.amazon.com/eks/), but there is still a lot of custom integration that needs to be built by developers, and container configuration is required.

Back in 2014, AWS launched Lambda functions, a key component of serverless computing. They act as integration glue between services, where you only need to write the business logic code to respond to inbound events or HTTP requests. Using Lambda functions has become very popular as they are stateless, have built-in event source integration, and you only pay for the actual execution time. So, rather than using a fleet of microservices running on containers behind a load balancer, you can build a highly scalable serverless stack fully managed by AWS.

This book will provide you with a solid foundation that combines the best of both worlds: the flexibility of microservices, with the benefits of serverless computing, to maximize developer productivity. You will gain an appreciation for the power of deploying a full serverless stack, not only when you save money in terms of running costs, but also in terms of support maintenance and upgrading. This effectively allows your company to go to market a lot quicker with new products, and beat your competitors in the process with a much smaller team. You will also be able to create, test, and deploy a scalable, serverless microservice where the costs are paid per usage and not per running machine. In addition, this will allow you to autoscale based on the number of requests, while security is natively built in and supported by AWS.

We share our source code, configuration, and personal experiences of running serverless stacks in production at web scale since 2015. We guide you through concepts with practical examples as if you were being trained on the job. To give you a deeper intuition and understanding when starting your journey, we begin the serverless stack creation with the AWS Management Console, where most tasks are done using the user interface. We then switch to using the AWS Command Line Interface and Bash and Python scripts to automate the creation, testing, and deployment of your serverless stacks just as you would in a production environment for your organization. Now that we know what lies ahead, let's jump right into the book.