What is micro-services? Why do you use a micro service?

Foreword

In recent years micro is the fire service, we are building micro-services, like to talk about micro-point services related to technology, it seemed not so mainstream.

In recent years, many companies an insight into the team and close friends are trying to change the micro-services, but many teams did not actually step on the micro-pit service experience, and even forced many teams to service micro-micro-away service, final written in a large distributed single application, after the transformation of the system is neither rapid expansion of micro-services, flexible release characteristics, but also to the original monomer applications lost facilitate the development, deployment, easy feature (split in more than one project, the development and deployment of complex degrees have increased), I have to say is not worth the candle.

On the personal experience and participate in reconstruction and construction of several large projects micro services. I would like to share practical experience as a practitioner on the micro-services with you to help you understand the advantages and disadvantages of micro-services, which can be combined to make their business more appropriate choice, as the three themes of this article, for example:

  1. What is micro-services? Why use micro-services?
  2. Micro-services to solve any problem, and the introduction of what is the problem?
  3. The use of micro-services should be what principles to follow? What kind of situation you should not use micro service?

(PS: If you use because too many on the market for micro tutorial services framework tools, so Benpian just a general overview on the micro-service articles, does not involve the installation and use of a variety of tutorials micro-services framework, we are only talking about micro services of the design model and the advantages and disadvantages of scenarios for applications)

One: What is micro service? Why use micro-services?

What is micro-services? (Familiar to students can skip)

Simple example: military news to see the students should know that an aircraft carrier combat capability, although very strong, but too obvious weakness is the defense is poor, single-ship aircraft carrier rarely act alone, usually carrier battle groups is the main military force you can understand a single aircraft carrier applications of monomer (defense poor, poor mobility), the aircraft carrier battle group (scheduling complex, high maintenance costs) understood as micro-services.

Most developers experience and developed over single application, whether it is traditional Servlet + JSP, or SSM, or now SpringBoot, they are the single application, so long with us monomers application have any drawbacks? We are faced with a problem, lead us to abandon the single application turning microstructure service architecture? Personal summarizes the main issues are as follows:

  • High deployment costs (either modify one line of code, or 10 lines of code, the full amount must be replaced)
  • Changes in high-impact, high-risk (no matter how small code changes, the costs are the same)
  • Because of the high cost, high risk, resulting in the deployment of low frequency (can not be quickly delivered to customer needs)

Of course, such as the inability to meet the rapid expansion, elastic stretch, unable to adapt to cloud the issue and other environmental characteristics, but we will not go into all that, the above problems are micro-architecture service problems to be solved, as to specifically how to solve, let's talk later put back

Two: micro-services to solve any problem, and the introduction of what is the problem?

Let's take a look at the micro-services can bring us what? Micro-service architecture features:

  • Issued for a specific service, is small, low risk, low cost
  • Frequent release version, rapid delivery requirements
  • Low-cost expansion, resilient and elastic, to adapt to the cloud environment

We know that a simple idea, that nothing is perfect, everything has two sides, gains will lose, then select the service in the settlement of micro-fast response and elastically stretchable problems at the same time, it brings us what is the problem? Personal summarized as follows:

  • The complexity of distributed systems
  • Deployment, testing and monitoring costs
  • CAP distributed transactions and related issues

System original monomer to tens to hundreds of different projects, for example, include generating club dependencies between services, service how opened, the internal interface specification, data transfer and so on, especially in split service need team familiar with the business processes, know how to choose, to ensure that the split of granularity services in line with the basic principles of "high cohesion, low coupling", but also on the development of business and the company's vision, but also to persuade team members to work hard, and actively involved in striking a balance among the parties.

For distributed systems, deployment, testing and monitoring middleware to need a lot of support, but also to maintain the middleware itself, the original single application is very simple affairs issues, go to the distributed environment becomes very complex, distributed a transaction is a simple retry + compensation mechanism, or strong consistency methods such as the use of two-phase commit protocol to solve, we must depend familiar business scenarios coupled with repeated weighing the same problems also weighed on the CAP, including the model, in short micro-services technology stack on the team's overall level of overall demand higher

 

Three: What services should follow the principle of using a micro?

An old saying: moving troops and horses, forage first. The construction of micro-services need to establish long-term planning, not write like that built CMS database tables, and then began to work, so in all likelihood fail. Before we want to micro-services reform, architect to do advance planning, we have divided into three steps here, the early stage, stage design, stage technology

Early stage, generally to do the following things:

  • And full multi-party communication, organization and ensure that they meet customer needs, and to be recognized
  • And team communication, let teammate (development / test / operation and maintenance) to understand and actively involved
  • And business communication, planning and on-line version of the specified time

The design phase, Sam Newman reference book "micro-service design" , a single micro-services must meet the following conditions, consistent with the basic requirements of micro-services:

  • Standard REST-style interfaces (based on HTTP and JSON format)
  • Independent deployment, avoid sharing the database (because the database to avoid affecting the entire distributed system)
  • High cohesion on business, reducing dependence (and services from the design to avoid too large or too small)

A large distributed system requires a strong infrastructure to support and which services related to infrastructure micro?

  • CI / CD and Automation (published by distributed systems is almost impossible to manually)
  • Virtualization technology (micro to ensure that services run isolated from the environment, is to use the current industry mainstream Docker containers)
  • Log aggregation, monitoring full link (height analyze and diagnose problems observed)

Said so much, then what kind of situation, your team is not suitable for the construction of micro-services? (Do not pigeon-holing)

  1. The development team does not have autonomy, organization development team very much limit (Refer to  Conway's Law )
  2. Team is not familiar with the business, does not recognize the border service, reasonable Split (refer to DDD Domain Driven Design )

 

 

to sum up

Micro-service design is actually very early design ideas, because with the rise of virtualization technology, micro-services can achieve low cost, so it became popular and rise.

Micro-deep connotation services, including automation, decentralization, independence and so on, details of which can not be clearly outlined by article, we are doing when technology selection or program, as much as possible to understand the technology itself and the origins of the characteristics of our business, be a better choice. Personal knowledge is limited, do not like do not spray for micro-services you what a different view of it? Welcome to the discussion and exchange messages

Guess you like

Origin www.cnblogs.com/xiao2shiqi/p/11297809.html