Guide to Quickly Understand The Microservice Architecture

Source: Internet
Author: User
Keywords microservices microservices architecture what is microservices architecture

What is Microservice?

Microservices is a software architecture style. It is based on small functional blocks focused on a single responsibility and function and uses a modular approach to combine complex large-scale applications. Each functional block uses a language-independent API set. to communicate with each other.

First of all, there is no official definition of microservices. If we want to directly describe microservices, it is difficult. We can understand what microservices are by comparing traditional WEB applications.

img

The core of traditional WEB application is divided into business logic, adapter and API or WEB interface accessed through UI. Business logic defines business processes, business rules, and domain entities. The adapter includes database access components, message components and access interfaces. The architecture diagram of a taxi software is as follows:

Although they also follow modular development, they will eventually be packaged and deployed as a monolithic application. For example, Java applications will be packaged as WAR and deployed on Tomcat or Jetty.


This monolithic application is more suitable for small projects, the advantages are:
  • Simple and direct development, centralized management
  • Basically will not repeat development
  • Functions are local, no distributed management overhead and call overhead

Of course, its shortcomings are also very obvious, especially for Internet companies:
  • Low development efficiency: all developers change the code in one project, submit the code and wait for each other, and the code conflict
  • Code maintenance is difficult: code functions are coupled together, newcomers do not know how to start
  • Inflexible deployment: long build time, any small changes must rebuild the entire project, this process is often very long
  • Low stability: a trivial problem that can cause the entire application to hang
  • Insufficient scalability: unable to meet business requirements under high concurrency

Therefore, the mainstream design now generally adopts microservice architecture. The idea is not to develop a huge monolithic application, but to decompose the application into small, interconnected microservices. A microservice performs a specific function, such as passenger management and order management. Each microservice has its own business logic and adapter. Some microservices also provide API interfaces for use by other microservices and application clients.

For example, the system described above can be broken down into:

img

Each business logic is decomposed into a microservice, and the microservices communicate through REST API. Some microservices also develop API interfaces to end users or clients. But under normal circumstances, these clients can not directly access the background microservices, but pass the request through the API Gateway. API Gateway is generally responsible for tasks such as service routing, load balancing, caching, access control, and authentication.

Advantages of microservices architecture

The microservice architecture has many important advantages. First, it solves the complexity problem. It decomposes the monolithic application into a set of services. Although the total amount of functions remains the same, the application has been broken down into manageable modules or services. These services define a clear RPC or message-driven API boundary. The microservice architecture strengthens the level of application modularity, which is difficult to achieve through a single code base. Therefore, microservice development is much faster and easier to understand and maintain.

Second, this architecture allows each service to be independently developed by a team focused on this service. As long as the service API contract is met, developers can freely choose the development technology. This means that developers can use new technologies to write or refactor services, because the service is relatively small, so this will not have much impact on the overall application.

Third, the microservice architecture allows each microservice to be deployed independently. Developers do not need to coordinate deployment of service upgrades or changes. These changes can be deployed immediately after the test passes. So the microservice architecture also makes CI/CD possible.

Finally, the microservices architecture allows each service to be independently extended. We only need to define constraints such as configuration, capacity, and number of instances that meet the service deployment requirements. For example, we can deploy CPU-intensive services on EC2 compute-optimized instances and in-memory database services on EC2 memory-optimized instances.
Disadvantages and challenges of microservice architecture
In fact, there are no silver bullets, and the microservice architecture will also bring us new problems and challenges. One of them is similar to its name. Microservices emphasizes service size, but in fact there is no uniform standard. According to what rules business logic should be divided into microservices, this is itself an empirical project. Some developers advocate building a microservice in 10-100 lines of code. Although the establishment of small services is advocated by the microservice architecture, it is important to remember that microservices are a means to achieve goals, not goals. The goal of microservices is to fully decompose applications to promote agile development and continuous integration deployment.

Another major disadvantage of microservices is the complexity brought about by the distributed nature of microservices. Developers need to implement call and communication between microservices based on RPC or messages, and this makes the discovery of services, tracking of service call chains, and quality issues very difficult.

Another challenge of microservices is the partitioned database system and distributed transactions. Business transactions that update multiple business entities are quite common. These types of transactions are very simple to implement in monolithic applications, because monolithic applications often have only one database. But under the microservices architecture, different services may have different databases. The constraints of the CAP principle make us have to abandon the traditional strong consistency and instead pursue the ultimate consistency, which is a challenge for developers.

The microservices architecture also brings great challenges to testing. The traditional monolithic WEB application only needs to test a single REST API, and testing a microservice requires starting all other services it depends on. This complexity cannot be underestimated.

Another big challenge for microservices is changes across multiple services. For example, in a traditional monolithic application, if three services A, B, and C need to be changed, A depends on B, and B depends on C. We only need to change the corresponding module and then deploy it once. But in the microservices architecture, we need to carefully plan and coordinate the change deployment of each service. We need to update C first, then B, and finally A.

Deploying applications based on microservices is also much more complicated. Monolithic applications can be easily deployed on a group of identical servers, and then the front end can use load balancing. Each application has the same basic service address, such as database and message queue. Microservices consist of a large number of different services. Each service may have its own configuration, number of application instances, and basic service addresses. Different configuration, deployment, expansion and monitoring components are required here. In addition, we also need a service discovery mechanism so that the service can discover the addresses of other services with which it communicates. Therefore, the successful deployment of microservice applications requires developers to have a better deployment strategy and a high degree of automation.

The above problems and challenges can be summarized as follows:
  • API Gateway
  • Calling between services
  • Service discovery
  • Service fault tolerance
  • Service deployment
  • Data call
img
Fortunately, there have been many microservice frameworks that can solve the above problems.

First generation microservices framework

Spring Cloud
  • Spring Cloud provides developers with tools to quickly build a common model of distributed systems (including configuration management, service discovery, fuses, intelligent routing, micro-agent, control bus, one-time token, global lock, leadership election, distributed Session, cluster status, etc.). The main items include:
  • Spring Cloud Config: Centralized external configuration management supported by Git repository. Configuration resources are directly mapped to the Spring Environment, but can be used by non-Spring applications if needed.
  • Spring Cloud Netflix: Integration with various Netflix OSS components (Eureka, Hystrix, Zuul, Archaius, etc.).
  • Spring Cloud Bus: An event bus used to connect services and service instances with distributed messaging. Used to propagate state changes (such as configuration change events) in the cluster.
  • Spring Cloud for Cloudfoundry: Integrate your application with Pivotal Cloudfoundry. Provide service discovery implementation, you can also easily achieve the protection of resources through SSO and OAuth 2, you can also create a Cloudfoundry service proxy.
  • Spring Cloud-Cloud Foundry Service Broker: Provides a starting point for building and managing a service broker for a service in Cloud Foundry.
  • Spring Cloud Cluster: Leader election and general state model (based on the abstraction and implementation of ZooKeeper, Redis, Hazelcast, Consul).
  • Spring Cloud Consul: combined with Hashicorp Consul's service discovery and configuration management
  • Spring Cloud Security: Provide support for load-balanced OAuth 2 sleep client and authentication header relay in Zuul proxy.
  • Spring Cloud Sleuth: Distributed tracking for Spring Cloud applications, compatible with Zipkin, HTrace, and log-based (eg ELK) tracking.
  • Spring Cloud Data Flow: Cloud local orchestration service for modern runtime composable microservice applications. The easy-to-use DSL, drag-and-drop GUI and REST-API together simplify the overall arrangement of microservice-based data pipelines.
  • Spring Cloud Stream: Lightweight event-driven microservice framework that can quickly build applications that can connect to external systems. A simple declarative model for sending and receiving messages between Spring Boot applications using Apache Kafka or RabbitMQ.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.