Micro service is a recent hot, more and more companies began to put the previous monomer architecture to micro service architecture transition, the market, for understand the micro service talent demand is growing, learn micro service, is the program to promote salary, down with high shuai rich, marry baifumei, the necessary skills to the peak of life… But what are microservices? What specific skills should micro service master?

Concept of * * * *

Microservices are an architectural solution for building applications. Unlike more traditional monolithic solutions, microservices architectures can break applications into multiple core functions. Each function is called a service and can be built and deployed separately, which means that the services do not affect each other when they work (and fail).

What is a singleton scheme? Take a simple online mall as an example, the single scheme structure is shown as follows:

! [](https://pic1.zhimg.com/v2-fa9c328e233eaddb5ce5f550b2a385f0_b.png)

For a software application, all functions of the application are usually developed and packaged together. Of course, some large applications may use load balancing in deployment, but they still belong to the singleton scheme in architecture, so deployment will result in:

1. Bloated code and long application startup time

2. Poor application fault tolerance, a small function of the program error may lead to the end of the whole system;

3. Poor scalability, affecting the whole body.

4. Development collaboration is difficult, which is actually related to coupling (so the idea of high cohesion and low coupling should be implemented)

A simple example of what the microservices architecture pattern is:

! [](https://pic1.zhimg.com/v2-1e2d24a34bfe1a5289c325d789f81374_b.png)

Microservice means that each core function of an application can run independently. In this way, even if a function fails, it will not lead to the end of all functions. The emergence of micro-services is because the original single application architecture can no longer meet the technical requirements of current Internet products.

Advantages of microservices architecture

1. Micro-services can greatly improve daily work efficiency through distributed deployment. You can also develop multiple microservices in parallel. This means that more developers can work on the same application at the same time, leading to shorter development times

2. These independent services do not affect each other as long as they are built correctly. This means that, unlike the monolithic application model, the failure of one service does not bring the entire application down, making the project more stable.

3. Because of the use of multi-language apis, developers are free to choose the most appropriate language and technology for the functionality they need to implement. This can really get the most out of things.

4. With high scalability, it can be easily expanded as the project needs and technologies are updated

Nine features of microservices

Everyone’s ideas are different. Due to the influence of various factors such as environment, resources and requirements, there will be almost no identical architecture design in the design and implementation of a large system architecture. This is especially true for micro service architecture, due to the micro service architecture is only a suggestion, not hard and fast rules, architects often according to their own understanding and the actual situation to design, and development in the process of development and perfect, just like the object-oriented design patterns, micro service, there are also nine characteristics, through the study of the 9 big features, It has guiding significance for architecture design.

** I. Service componentization: **

In micro service architecture, we need to modular decomposition of service, service is a process of components, it via HTTP communication protocols such as collaboration, rather than the traditional way as insert type components work together, each service is independent development, deployment, can effectively avoid a service changes cause the redeployment of the whole system.

Ii. Organize the team according to business:

Different approaches to team segmentation are required when implementing microservices architectures. Because each service is implemented on a wide stack or full stack for a particular business, ji is responsible for persistent storage of data, as well as various cross-disciplinary functions such as user interface definition. Therefore, in the face of large projects, it is recommended to split the micro-service team according to the method of business lines. On the one hand, it can effectively reduce the internal friction caused by the internal modification of the service, and on the other hand, the team boundary can become clearer.

** 3. The attitude of making products: **

In the microservices architecture team, each small team should be responsible for the entire lifecycle of the product in the way it is built, rather than delivering to test, operation and maintenance as in traditional project development

** iv. Intelligent endpoints and dumb pipes: **

Since each service is not in the same process, the communication mode between components has changed, and the original in-process method call has become RPC call, which will lead to cumbersome communication between micro-services and make the system performance worse, so we need coarse-grained communication protocol:

In microservices architecture, two service invocation methods are commonly used:

(1) Use HTTP RESTful API or lightweight message sending protocol to realize the triggering of message delivery and service invocation.

(2) By passing messages over a lightweight message bus, intermediates such as RabbitMQ that provide reliable asynchronous exchange.

A binary message sending protocol, such as Protobuf, may also be used in cases where there is a strong emphasis on performance

** v. Decentralized governance: **

By using lightweight contract definition interfaces throughout the microservices architecture, we make the specific technology platform of the service itself less sensitive, so that the components of the entire microservices architecture system can choose different technology platforms for different business characteristics.

** VI. Decentralized management data: **

During implementation of the service architecture, hope each service yourself to manage the database, this is the decentralization of data management, although the data management of decentralized make data management more detailed, for data storage and achieve the optimal performance, but different database instance, data consistency and became one of the problems to be solved in the micro service architecture, Distributed transaction itself is very difficult to implement, so in the microservice architecture, we emphasize more on “no transaction” calls between services, while data consistency only requires that the data in the final processing state is consistent.

** vii. Infrastructure automation: **

In microservices architecture, it is important to build a continuous delivery platform from the beginning to support the entire implementation process;

Error design: **

In a microservice architecture, it must be designed to quickly detect the source of the failure and automatically recover the service as much as possible, and it is often desirable to implement monitoring and logging components in each service. For example: service status, circuit breaker status, throughput, network delay and other key data dashboard.

9. Evolutionary design :**

In fact, through the above learning, we can find that to implement a perfect microservice architecture, there are many things to consider and the cost is quite high. For some inexperienced teams, it is easy to pay more than the cost of single architecture application.

Therefore, in many cases, architects build systems in an evolutionary manner, meaning that a good architecture is not designed, but evolved. In the initial stage, it is generally designed and implemented with a single architecture. On the one hand, the initial volume of the system is not too large, and the construction and maintenance costs are not high. On the other hand, the core business in the early stage usually doesn’t change dramatically in the later stage. With the development of the system or the needs of the business, the architect will microservice some contents that are often changed or have effect for a period of time, and gradually split out the changeable modules in the original single system, and the stable modules with little change form a core microservice existing in the whole architecture.

Challenges posed by microservices

Before implementing microservices, it is important to know that the fragmentation of microservices raises a number of issues and challenges that would not otherwise be present in a single application:

(1) The new height of ** operation and maintenance **. In the microservice architecture, due to the disassembly of the system, the number of processes that the operation and maintenance personnel need to maintain increases greatly, which requires the operation and maintenance personnel to have certain development ability to arrange the operation and maintenance process and make them run automatically.

(2) ** interface consistency **. Although we split the services, the dependency on business logic is not eliminated, just from code dependency in a single application to communication dependency between microservices. This allows the developer to make minor changes to the original interface, and the corresponding interactor needs to coordinate the changes to publish to ensure that the interface is called correctly. This means better interface and version management, or strict on/off principles.

(3) ** Distributed complexity **. Since the split microservices are independently deployed and run in their own processes, they can only cooperate through communication, so the problems of distributed environment are important factors to be considered in the design of microservices architecture, such as network delay, distributed transactions, and asynchronous messages.

Although there are many disadvantages in microservices architecture, as you know, there are always two sides. The key is how to choose between them. When you think that agile development and automated deployment are important issues for you to consider in microservices architecture, then it is a good choice to choose microservices architecture.

Microservices need to master the technology

Light theory is nothing, the most important or need to be able to write out, master micro services we need to master what technology and framework?

Nowadays, there are numerous frameworks in the programming world. When we are solving a problem and choosing a framework, we often fall into the difficulty of choosing which one to use. The emergence of Spring Cloud can solve such a problem. It takes advantage of the development convenience of Spring Boot to subtly simplify the development of distributed system infrastructure, such as service discovery registry, configuration center, message bus, load balancing, circuit breakers, data monitoring, etc., which can be started and deployed with one click using Spring Boot’s development style. Instead of reinventing the wheel, Spring Cloud simply combines mature, proven service frameworks developed by various companies and encapsulates them in Spring Boot style, eliminating complex configuration and implementation principles. Finally, a simple and easy to understand, easy to deploy and easy to maintain distributed system development kit was set aside for developers.

** Introduction to Spring Cloud **

Spring Cloud is a micro-service architecture development tool based on Spring Boot. It provides a simple development mode for configuration management, service governance, circuit breaker, intelligent routing, micro-agent, control bus, global lock, decision campaign, distributed session and cluster state management operations in micro-service architecture.

Spring Cloud contains a number of sub-projects, as follows:

(1) Spring Cloud Config: configuration management, supporting the use of Git to store configuration content, which can be used to realize the external storage of application configuration, and support client configuration information refresh, encryption/decryption configuration content, etc.

(2) Spring Cloud Netflix: This is the core component of Spring Cloud, which integrates multiple Netflix OSS open source suites:

  • Eureka: Service governance component, including the implementation of service registry, service registration and service discovery mechanism;
  • Hystrix: Fault tolerant management component that implements circuit breaker mode to help with delays in service dependencies and provide strong fault tolerance for faults;
  • Ribbon: Client-side load balancing service invocation component;
  • Feign: Declarative service invocation components based on the Ribbon and Hystrix;
  • Zuul: gateway component that provides intelligent routing and access filtering functions.
  • Archaius: Externalizes configuration components.
(3) Spring Cloud Bus: event and message Bus, which is used to propagate state changes or events in the cluster to trigger subsequent processing, such as dynamic refreshing of configuration information;

(4) Spring Cloud Cluster: implementation of election algorithm and general mode for Zookeeper, Redis, Hazelcast and Consul;

(5) Spring Cloud Cloudfoundry: Integration support with Pivotal Cloudfoundry; (6) Spring Cloud Consul: Service discovery and configuration management tool;

(7) Spring Cloud Stream: a consumer microservice implemented via Redis, RabbitMQ, or Kafka that sends and receives messages via a simple declarative model;

(8) Spring Cloud AWS: components for simplifying the integration of Amazon Web Services;

(9) Spring Cloud Security: Security toolkit, providing Repeaters for OAuth2 client requests in Zuul proxy;

(10) Spring Cloud Sleuth: Distributed service tracking implementation of Spring Cloud application, which can perfectly integrate Zipkin;

(11) Spring Cloud Zookeeper: Service discovery and configuration management component based on Zookeeper;

(12) Spring Cloud Starters: the basic component of Spring Cloud, which is the basic dependency module based on Spring Boot style project;

(13) Spring Cloud CLI: Spring Boot CLI plug-in for quickly creating Spring Cloud applications in Groovy.

In addition to Spring Cloud, there are many excellent open source frameworks that are worth studying.

  1. **Tars**
Tars is an open source project that summarizes the practice achievements of TAF (Total Application Framework) used internally by Tencent for many years. High-performance RPC development framework based on Tars service and Tars protocol, and supporting integrated service governance platform, helps individuals or enterprises to quickly build their own stable and reliable distributed applications in the way of micro services. The core is that it supports PHP,JAVA,GO,C++ and other languages, no matter what backend language you do, you can learn.

Git address:

https://github.com/TarsCloud/Tars​

**2.Dubbo**

The earliest open source RPC framework in China was developed by Alibaba and opened source at the end of 2011, but it only supports Java language.

Official Address:

dubbo.apache.org

3.gRPC

Originally developed by Google, it is a language-neutral, platform-neutral, open source remote procedure Call (RPC) system.

Website:

grpc.io

Of course, there is no end to technology, such as Baidu’s Disconf, 360’s QConf, Taobao’s Diamond, Dangdang’s Elastik-Job, jd’s Hydra, etc., all worth learning.

** There is no perfect technology, only the most suitable, find their own way, choose their own direction is the most important