Book Image

Cloud Native Python

By : Manish Sethi
Book Image

Cloud Native Python

By: Manish Sethi

Overview of this book

Businesses today are evolving so rapidly that having their own infrastructure to support their expansion is not feasible. As a result, they have been resorting to the elasticity of the cloud to provide a platform to build and deploy their highly scalable applications. This book will be the one stop for you to learn all about building cloud-native architectures in Python. It will begin by introducing you to cloud-native architecture and will help break it down for you. Then you’ll learn how to build microservices in Python using REST APIs in an event driven approach and you will build the web layer. Next, you’ll learn about Interacting data services and building Web views with React, after which we will take a detailed look at application security and performance. Then, you’ll also learn how to Dockerize your services. And finally, you’ll learn how to deploy the application on the AWS and Azure platforms. We will end the book by discussing some concepts and techniques around troubleshooting problems that might occur with your applications after you’ve deployed them. This book will teach you how to craft applications that are built as small standard units, using all the proven best practices and avoiding the usual traps. It's a practical book: we're going to build everything using Python 3 and its amazing tooling ecosystem. The book will take you on a journey, the destination of which, is the creation of a complete Python application based on microservices over the cloud platform
Table of Contents (14 chapters)
6
Creating UIs to Scale with Flux

The cloud native concepts

Cloud native is structuring teams, culture, and technology to utilize automation and architectures to manage complexity and unlock velocity.

The cloud native concept goes beyond the technologies with which it is associated. We need to understand how companies, teams, and people are successful in order to understand where our industry is going.

Currently, companies such as Facebook and Netflix have dedicated a large amount of resources working towards cloud native techniques. Even now, small and more flexible companies have realized the value of these techniques.
With feedback from the proven practices of cloud native, the following are some of the advantages that come to light:

  • Result-oriented and team satisfaction: The cloud native approach shows the way to break a large problem into smaller ones, which allows each team to focus on the individual part.

  • Grunt work: Automation reduces the repetitive manual tasks that cause operations pain, and reduces the downtime. This makes your system more productive, and it gives more efficient outcomes.

  • Reliable and efficient application infrastructure: Automation brings more control over deployment in different environments--whether it is development, stage, or production--and also handles unexpected events or failures. Building automation not only helps normal deployment, but it also makes deployment easy when it comes to a disaster recovery situation.

  • Insights over application: The tools built around cloud native applications provide more insights into applications, which make them easy to debug, troubleshoot, and audit.

  • Efficient and reliable security: In every application, the main concern is toward its security, and making sure that it is accessible via required channels with authentication. The cloud native approach provides different ways for the developer to ensure the security of the application.

  • Cost-effective system: The cloud approach to managing and deploying your application enables efficient usage of resources, which also includes application release and, hence, makes the system cost effective by reducing the wastage of resources.

Cloud native - what it means and why it matters?

Cloud native is a broad term which makes use of different techniques, such as infrastructure automation, developing middleware, and backing services, which are basically a part of your application delivery cycle. The cloud native approach includes frequent software releases that are bug-free and stable, and can scale the application as per the business requirement.

Using the cloud native approach, you will be able to achieve your goal toward application building in a systematic manner.

The cloud native approach is much better than the legacy virtualization-oriented orchestration, which needs a lot of effort to build an environment suitable for development, and then, a far more different one for the software delivery process. An ideal cloud native architecture should have automation and composition functionalities, which work on your behalf. These automation techniques should also be able to manage and deploy your application across different platforms and provide you with results.

There are a couple of other operation factors that your cloud native architecture should be able to identify, such as steady logging, monitoring application and infrastructure in order to make sure the application is up and running.

The cloud native approach really helps developers build their application across different platforms using tools such as Docker, which is lightweight and easy to create and destroy.

The cloud native runtimes

Containers are the best solutions for how to get software to run reliably when moved from one computing environment to another. This could be from one developer machine to the stage environment into production, and perhaps from a physical machine to a virtual machine in a private or public cloud. Kubernetes has become synonymous with container services, and is getting popular nowadays.

With the rise of cloud native frameworks and an increase in the applications built around it, the attributes of container orchestration have received more attention and usage. Here is what you need from a container runtime:

  • Managing container state and high availability: Be sure to maintain the state (such as create and destroy) of containers, specifically in production, as they are very important from a business perspective, and should be able to scale as well, based on business needs
  • Cost analysis and realization: Containers give you control over resource management as per your business budget, and can reduce costs to a large extent
  • Isolated environment: Each process that runs within a container should remain isolated within that container
  • Load balancing across clusters: Application traffic, which is basically handled by a cluster of containers, should be redirected equally within the containers, which will increase the applications response and maintain high availability
  • Debugging and disaster recovery: Since we are dealing with the production system here, we need to make sure we have the right tools to monitor the health of the application, and to take the necessary action to avoid downtime and provide high availability

Cloud native architecture

The cloud native architecture is similar to any application architecture that we create for a legacy system, but in the cloud native application architecture, we should consider a few characteristics, such as a twelve-factor application (collection of patterns for app development), microservices (decomposition of a monolithic business system into independent deployable services), self-service agile infrastructure (self-service platform), API-based collaboration (interaction between services via API), and antifragility (self-realizing and strengthening the application).

First, let's discuss what is microservices all about?

Microservices is a broader term that breaks large applications into smaller modules to get them developed and make them mature enough for release. This approach not only helps to manage each module efficiently, but it also identifies the issue at the lower level itself. The following are some of the key aspects of microservices:

  • User-friendly interfaces: Microservices enable a clear separation between microservices. Versioning of microservices enables more control over APIs, and it also provides more freedom for both the consumers and producers of these services.
  • Deployment and management of APIs across the platform: Since each microservice is a separate entity, it is possible to update a single microservice without making changes to the others. Also, it is easier to roll back changes for a microservice. This means the artifacts that are deployed for microservices should be compatible in terms of API and data schemas. These APIs must be tested across different platforms, and the test results should be shared across different teams, that is, operation, developers, and so on, to maintain a centralized control system.
  • Flexibility in application: Microservices that are developed should be capable of handling the request and must respond back, irrespective of the kind of request, which could be a bad input or an invalid request. Also, your microservice should be able to deal with an unexpected load request and respond appropriately. All of these microservices should be tested independently, as well as with integration.
  • Distribution of microservices: It's better to split the services into small chunks of services so that they can be tracked and developed individually and combined to form a microservice. This technique makes microservices development more efficient and stable in manner.

The following diagram shows a cloud native application's high-level architecture:

The application architecture should ideally start with two or three service, try to expand it with further versions. It is very important to understand application architecture, as it may need to integrate with different components of the system, and it is possible that a separate team manages those components when it comes to large organizations. Versioning in microservices is vital, as it identifies the supported method during the specified phase of development.

Are microservices a new concept?

Microservices has been in the industry for a very long time now. It is another way of creating a distinction between the different components of a large system. Microservices work in a similar fashion, where they act as a link between the different services, and handle the flow of data for a particular transaction based on the type of requests.

The following diagram depicts the architecture of microservices:

Why is Python the best choice for cloud native microservices development?

Why do I choose Python, and recommend it to as many people as possible? Well, it comes down to the reasons explained in the upcoming subsections.

Readability

Python is highly expressive and an easy-to-learn programming language. Even an amateur can easily discover the different functionalities and scope of Python. Unlike other programming languages, such as Java, which focus more on parenthesis, brackets, commas, and colons, Python let's you spend more time on programming and less time on debugging the syntax.

Libraries and community

Python's broad range of libraries is very portable over different platforms, such as Unix, Windows, or OS X. These libraries can be easily extended based on your application/program requirement. There is a huge community that works on building these libraries and this makes it the best fit for business use cases.

As far as the Python community is concerned, the Python User Group (PUG) is a community that works on the community-based development model to increase the popularity of Python around the globe. These group members give talks on Python-based frameworks, which help us build large systems.

Interactive mode

The Python interactive mode helps you debug and test a snippet of code, which can later be added as a part of the main program.

Scalable

Python provides better structure and concept, such as modules, to maintain large programs in a more systematic manner than any other scripting language, such as shell scripting.