Introduction to Microservices

Tram Ho

The concept

What is Spring Boot?

Spring Boot is a framework built on top of Spring Framework and designed to make Spring application development faster and simplify configuration. It provides developers with a new approach to developing Spring web applications quickly, without having to spend a lot of time configuring or arranging complex dependencies. Spring Boot provides many convenient features like auto-configuration, embedded web server, starter dependencies and actuator to make Spring application development and deployment simpler.

What is Spring Cloud?

Spring Cloud is a framework developed on the Spring platform to make building distributed applications easier. It provides features and tools to solve complex problems such as distribution, scalability, load balancing, resiliency, monitoring, and configuration management. Spring Cloud also supports open technologies like Netflix OSS (Open Source Software) and cloud solutions like Eureka, Ribbon, Hystrix, Zuul, Config Server, and many more. Using Spring Cloud makes deploying distributed applications simpler and easier to manage.

What are microservices?

There are many different definitions of Microservices and you may be confused as to which one is correct and which one is optimal. The following definition will incorporate the most common Microservices concepts.

A microservice is a technical approach that focuses on decomposing an application into single-function modules with well-defined interfaces , implemented and independently operated by small teams (Small Teams) that manage the entire service lifecycle (Entire Lifecycle) .

Microservices help speed up development by minimizing communication and coordination among team members, while reducing the scope and risk of change .

What is decomposing?

Decomposing in the context of microservices means decomposing the application into single functional modules. That is, instead of having one large application, we will split it into many smaller applications, each of which has a clear function and serves a specific need of the large application. This separation makes application development and maintenance easier and increases system flexibility.

For example:

What is Single-function?

Single-function is the term in Microservices architecture, which specifies that each microservice should contain only one fixed function, performing a specific task of the system. This separates the different functions of the application and makes the development and maintenance of microservices simpler.

What are well-defined interfaces?

Well-defined interfaces are interfaces that are well defined and provide rules for how other components of the system can interact with them. These interfaces help ensure compatibility and scalability in distributed systems, because different components can communicate with each other through predefined interfaces without knowing the details. inside each other.

What is Independent?

In the context of microservices, independent is often understood as services that can operate completely independently of each other, without being dependent on other services. In other words, services can be deployed and operated independently, and do not need to constantly work together to perform a certain function. This reduces dependencies between services and makes the system easier to scale and maintain.

For example:

Assume that we need to implement a standalone microservice to calculate VAT values ​​for sales products. We will create a new Spring Boot application with a REST endpoint to calculate VAT for a product.

First, we will create an interface to define the methods needed to calculate the VAT value:

Then we’ll create an implementation of this interface:

Finally, we will create a REST controller to handle the request and return the result of the VAT calculation:

Thus, we have created a standalone microservice in Java that uses Spring Boot to calculate VAT values ​​for sales products.

What are Small Teams?

  • We divide the work and group the services. Each group focuses on a specific service, they do not need to know about the internal workings of other groups.
  • These teams can work efficiently, communicate easily, and each service can be deployed quickly as soon as it’s ready.

What is Entire Lifecycle?

  • The team is responsible for the entire lifecycle of the service; from coding, testing, development, deployment, debugging and maintenance.
  • In a traditional application, we might have one team responsible for coding, and another team responsible for implementation. However, in microservices architecture, this is not true.

What is Minimizing Communication?

  • Minimizing communication doesn’t mean team members don’t care about each other. This means that only necessary communication between the pods should be through the interface each service provides.
  • Teams need to agree on an external interface so that communication between services is clearly defined.

What is The scope and risk of change?

  • Services should be changed without damaging other services. And as long as we don’t change the external interface there should be no problem for other services.
  • As a result of the changes, the versions of the services are updated independently and there is no relationship between them.

Monolithic Vs Microservices

  • The choice between the two methods depends on the context and complexity of the application.
  • Indeed, microservices solve the problems that come up in large applications when it comes to scalability, management, but it is not always the optimal solution.
  • It is important to remember that microservices can be used in the wrong context, leading to increased effort and cost, and even project failure.
  • Most problems in Microservices are inherited from having individual components.
  • For example, communication between methods in monolithic is much faster than asynchronous communication in services, which makes it slower, difficult to debug, and must be secure.
  • And certainly, there will be extra effort for operations related to operation, deployment, scaling, configuration, monitoring and testing as each service is independent.
  • Therefore, we need a skilled DevOps team to handle the complexity associated with deployment and automation.

Reference article: https://medium.com/omarelgabrys-blog/microservices-with-spring-boot-intro-to-microservices-part-1-c0d24cd422c3

So we are done with the introduction to Microservices

Thank you for reading! If you find the article useful, please click (upvote), so that I can be motivated to make more good articles.

Share the news now

Source : Viblo