Reader small image

You're reading from  Practical Site Reliability Engineering

Product typeBook
Published inNov 2018
PublisherPackt
ISBN-139781788839563
Edition1st Edition
Right arrow
Authors (3):
Pethuru Raj Chelliah
Pethuru Raj Chelliah
author image
Pethuru Raj Chelliah

 Pethuru Raj Chelliah (PhD) works as the chief architect at the Site Reliability Engineering Center of Excellence, Reliance Jio Infocomm Ltd. (RJIL), Bangalore. Previously, he worked as a cloud infrastructure architect at the IBM Global Cloud Center of Excellence, IBM India, Bangalore, for four years. He also had an extended stint as a TOGAF-certified enterprise architecture consultant in Wipro Consulting services division and as a lead architect in the corporate research division of Robert Bosch, Bangalore. He has more than 17 years of IT industry experience.
Read more about Pethuru Raj Chelliah

Shreyash Naithani
Shreyash Naithani
author image
Shreyash Naithani

Shreyash Naithani is currently a site reliability engineer at Microsoft R&D. Prior to Microsoft, he worked with both start-ups and mid-level companies. He completed his PG Diploma from the Centre for Development of Advanced Computing, Bengaluru, India, and is a computer science graduate from Punjab Technical University, India. In a short span of time, he has had the opportunity to work as a DevOps engineer with Python/C#, and as a tools developer, site/service reliability engineer, and Unix system administrator. During his leisure time, he loves to travel and binge watch series.
Read more about Shreyash Naithani

Shailender Singh
Shailender Singh
author image
Shailender Singh

Shailender Singh is a principal site reliability engineer and a solution architect with around 11 year's IT experience who holds two master's degrees in IT and computer application. He has worked as a C developer on the Linux platform. He had exposure to almost all infrastructure technologies from hybrid to cloud-hosted environments. In the past, he has worked with companies including Mckinsey, HP, HCL, Revionics and Avalara and these days he tends to use AWS, K8s, Terraform, Packer, Jenkins, Ansible, and OpenShift.
Read more about Shailender Singh

View More author details
Right arrow

Chapter 2. Microservices Architecture and Containers

Microservices are changing the mentality of people who design software. In this chapter, we are going to cover various definitions, principles, deployment techniques, tools, and techniques related to microservices. We are also going to show deployments using tools and technologies that are widely available in the cloud era. We will be covering how to deploy Serverless containers, and we will also mention existing virtualization technology. We will then provide some examples regarding how to develop microservices using the Spring Framework.

In this chapter, we will learn about the following topics:

  • Introducing microservices
  • Microservices design principles
  • Different options for deploying microservices 
  • Microservices using the Spring Boot framework and the RESTful framework
  • Monitoring microservices 
  • Important information about microservices 

What are microservices?


Microservices are a software development style that has recently been developed to set up practices intended to increase the efficiency and speed of developing and managing software solutions so that they can be scaled easily. This set of practices is technology agnostic, which means that there is not one single programming language or technology to build microservices. In fact, you can build microservices with any programming language. It's more about applying a certain number of architectural patterns and principles to your program.

Microservice design principles


There are several different microservices design principles available. Different terms are likely to be used in different places. In this book, we will refer to the microservices design principles as follows:

  • High cohesion among services: A microservice should have one single focus and the sole responsibility for that action. It should not change as a result of other related services. Services should be easily rewritable so that we can achieve scalability, reliability, and flexibility. It should handle a single business function and domain-specific functionality.
  • Autonomous service: A service should independently handle its work without the help of any other services. It should not be tightly integrated with any other service; it should remain loosely coupled in nature. By autonomous, we mean that a microservice should not change because of the external components with which it interacts. Autonomous services honor contracts and interfaces. They should be stateless...

Deploying microservices


Let's start to think practically about microservice deployment. We are going to look at the latest container technologies and orchestrator tools that are dominating the microservice market. First, we will list the availability of tools and options and then we will look at an example to show you how things can be deployed in the microservice model.

Microservices can be deployed on the following platforms:

  • Container platforms: These include technologies such as Docker, rkt, AWS ECS, and AWS EKS.
  • Code as a function: We can deploy bare functions written in supported programming languages on AWS Lambda-like platforms. These platforms will run that configured code and store the result on an S3-like bucket or a supported database on a cloud vendor platform. Alternatively, the code might trigger a further configured action. It can be called through AWS API Gateways, a similar service available on Microsoft Azure, or over Google's Cloud Platform (GCP).
  • Virtual platforms: These...

Practical examples of microservice deployment


In this section, we're going to look at some relevant examples using the latest technologies. This will give you an easy reference guide to consult when implementing your own deployment strategy.

A container platform deployment example with Kubernetes

In the following Kubernetes YAML configuration, we will define various Kubernetes keywords related to deployment. One important variable is container: image. Here, we are referring to an existing Docker container image that Kubernetes will use to create a container under pod deployment. This container image should already be customized to suit your requirements. The kubectl command will read this configuration and start your container as appropriate. It will start three replica pods with the same container image and it will use the matchLables value to replace the specific container inside the three newly created pods. The keyword replica indicates that a specific value has been used to create pods...

Microservices using Spring Boot and the RESTful framework


The code bases of different companies often grow exponentially and increase in complexity. In a monolithic process, we have multiple independent development teams. These teams are not actually that independent at all; they simultaneously work on the same code bases and change the same sections of code. It is tough for new developers to contribute to the business, and the development process is slow. Because of this, we have seen a gradual shift toward microservices.

The following diagram shows the microservice container, the business logic image container, the data access layer container, and, in total, a working model of a microservice-based distributed model:

The Spring Framework is an enterprise Java framework that lets us write enterprise Java applications. Spring Boot is the way in which we can bootstrap, or quickly start, a simple Spring application. We can also build more complex applications quickly using Spring Boot. It allows...

Jersey Framework


Jersey is an open source framework developed by Oracle. It is the official reference implementation of JAX-RS API, which is very similar to Apache CFX. On the server side, Jersey provides a servlet implementation that scans through the predefined classes we define to identified the restful resources. In the web.xml file, which is the deployment file for web applications, we can configure either the restful servlet or the jersey servlet.

Jersey provides the implementation of the client library, which is fully compliant with the JAX-RS API. It also provides several tools for security such as authorization or bean validation. Furthermore, it allows us to integrate testing for container deployments. The current version of Jersey is 2.27. You can learn more about Jersey by going to its official website at http://jersey.java.net.

For Spring integration, we have to add the jersey-spring4 dependency, as follows:

<dependency>
<groupId>org.glassfish.jersey.ext</groupId...

Representational State Transfer (REST)


This is used for the purpose of data communication across web APIs. The REST API works pretty much in the same way as a website: you make a call from the client to the server and get a HTTP response back. REST uses HTTP methods to interact with the client and the server. REST allows a variety of data formats such as JSON or XML. It is generally faster and uses less bandwidth. It is also easy to integrate with other applications.

Commonly used HTTP methods in REST APIs include the following:

  • GET: This is used for retrieving a data through APIs. It is a read-only method. It is safe to use duplicate GET methods.
  • PUT: This is used to change or update a data using APIs. It is a write method, and we can use duplicate PUT methods.
  • POST: This is used to create or insert data. It is a write method.
  • DELETE: This is used to remove a particular piece of data.

Any web service that uses a REST architecture is called a RESTful API or a REST API. 

Let's take an example of...

Important facts about microservices


Let's take a look at the following facts, which can give us a clearer picture of microservices.

Microservices in the current market

There are multiple reasons why, at this moment, people are starting to focus more on microservices architecture than monolithic architecture and even service-oriented architecture (SOA). This is because microservices have the following advantages:

  • The ability to respond to change quickly
  • Domain-driven design
  • The availability of automated test tools
  • The availability of release and deployment tools
  • The availability of on-demand hosting technology
  • The availability of on-line cloud services
  • The ability to embrace new technology
  • Reliability
  • The availability of asynchronous communication technology
  • The availability of simpler server-side and client-side technology

When to stop designing microservices

Designing microservices can often feel more like an art than a science. There is lots of general advice available in the domain, but at times this...

Summary


In this chapter, we have tried to cover almost everything to do with microservices, including how to design and implement them. We can design microservices according to our product specification, and we can pick different design principles, deployment technologies, languages, and techniques for our own products. We have looked at various examples using the Spring RESTful framework. Be confident and consult the guidelines mentioned in this chapter; these will make your application easy to manage, scale, and automate.

In the next Chapter 3, Microservice Resiliency Patterns, we will learn about its various approaches, best practices, optimization techniques, patterns, and algorithms, which have been recommended by subject matter experts (SMEs).

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Practical Site Reliability Engineering
Published in: Nov 2018Publisher: PacktISBN-13: 9781788839563
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Authors (3)

author image
Pethuru Raj Chelliah

 Pethuru Raj Chelliah (PhD) works as the chief architect at the Site Reliability Engineering Center of Excellence, Reliance Jio Infocomm Ltd. (RJIL), Bangalore. Previously, he worked as a cloud infrastructure architect at the IBM Global Cloud Center of Excellence, IBM India, Bangalore, for four years. He also had an extended stint as a TOGAF-certified enterprise architecture consultant in Wipro Consulting services division and as a lead architect in the corporate research division of Robert Bosch, Bangalore. He has more than 17 years of IT industry experience.
Read more about Pethuru Raj Chelliah

author image
Shreyash Naithani

Shreyash Naithani is currently a site reliability engineer at Microsoft R&D. Prior to Microsoft, he worked with both start-ups and mid-level companies. He completed his PG Diploma from the Centre for Development of Advanced Computing, Bengaluru, India, and is a computer science graduate from Punjab Technical University, India. In a short span of time, he has had the opportunity to work as a DevOps engineer with Python/C#, and as a tools developer, site/service reliability engineer, and Unix system administrator. During his leisure time, he loves to travel and binge watch series.
Read more about Shreyash Naithani

author image
Shailender Singh

Shailender Singh is a principal site reliability engineer and a solution architect with around 11 year's IT experience who holds two master's degrees in IT and computer application. He has worked as a C developer on the Linux platform. He had exposure to almost all infrastructure technologies from hybrid to cloud-hosted environments. In the past, he has worked with companies including Mckinsey, HP, HCL, Revionics and Avalara and these days he tends to use AWS, K8s, Terraform, Packer, Jenkins, Ansible, and OpenShift.
Read more about Shailender Singh