Mode: micro Services Architecture

Pattern: Microservice Architecture

Context

You are developing server-side enterprise applications. It must support a variety of clients, including desktop browser, mobile browser and native mobile applications. The application also may open API for third-party use. It can also be integrated via Web services or message broker with other applications. By application to execute business logic processing request (HTTP request and message); accessing the database; exchange messages with other systems; and returns HTML / JSON / XML response. The presence of different functional areas corresponding to application logic components.

problem

What deployment architecture of the application is?

focus point

  • There is a group of developers in the development of applications
  • New team members must quickly improve work efficiency
  • Applications must be easy to understand and modify
  • You want to continue to deploy practical application
  • You must run multiple applications instances on multiple computers in order to meet the scalability and availability requirements
  • You want to take advantage of emerging technologies (frameworks, programming languages, etc.)

solution

A definition of the architecture, the applications are built as a set of loosely coupled collaboration services. This method corresponds to the Y axis Scale Cube. Each service is:

  • High degree of maintainability and testability -
  • Fast, frequent development and deployment of loosely coupled with other services
  • Enables teams to work independently most of the time, while other services will not be affected by the change, it will not affect other services can be deployed independently
  • It enables teams to deploy their services without having to coordinate with other team to develop a small team 
  • By avoiding high communications person in charge of a large team is essential to increase productivity

Other service using HTTP / REST protocol isochronous or asynchronous AMQP protocol. Independently of one another can be developed and deployed services. Each service has its own database, to be separated from the other services. Use Saga mode to maintain data consistency between services

Learn more about the nature of the service, read this article .

example

Fictitious e-commerce applications

Let's say you're building an e-commerce application, the application receives an order from a customer, verification and inventory of available credit, and shipping them. The application consists of several components, including the realization of StoreFrontUI user interface, as well as for checking credit, some of the back-end inventory and shipping orders for maintenance services. The application contains a set of services.

Code examples

Chris Richardson developed micro-services examples . These examples on Github illustrate various aspects of micro-services architecture.

The impact

advantage

This solution has many advantages:

  • Support large complex applications continuous delivery and deployment.
    • Improved maintainability - each service are relatively small, and therefore easier to understand and change
    • Better testability - testing services smaller, faster
    • Better deployability - service can be deployed independently
    • It enables you to organize multiple autonomous development work around the team. Each (the so-called two pizza) and has a team responsible for one or more services. Each team can be independent of all the other teams develop, test, deploy and expand their services.
  • Each micro-services are relatively small:
    • Easier for developers to understand
    • IDE can improve developer productivity faster
    • Applications start faster, which makes a higher developer productivity, and accelerate the speed of deployment
  • Improved fault isolation. For example, if there is a memory leak in the service, it will only affect the service. Other services will continue to process the request. In contrast, a single-chip architecture improper behavior of the component may cause the entire system to crash.
  • Eliminate any long-term commitment to the technology stack. In the development of new services, you can select the new technology stack. Similarly, when significant changes to existing services, you can use the new technology stack rewrite it.

defect

This solution has many drawbacks:

  • Developers must deal with to create additional complexity of distributed systems:
    • Developers must implement cross-service communication mechanism and handle partial failure
    • Request implement across multiple services more difficult
    • The interaction between the test services more difficult
    • Request implement across multiple services requires careful coordination between teams
    • Developer Tools / IDE for building a single application, it does not provide explicit support for the development of distributed applications.
  • Deployment complexity. In production, there are still operational complexity by a number of different services consisting of system deployment and management.
  • Increased memory consumption. Alternatively the N micro-service architecture application instance using monolithic NxM service instance. If each of the services are running on the JVM own (or equivalent server), which is usually isolated instances necessary, it will produce overhead views M M times running. In addition, if each service runs in its own VM on (eg EC2 instances), as in the case of Netflix, the cost is even higher.

problem

You have to solve many problems.
 

When to use micro-service architecture?
 

Use of this approach is a challenge to decide when to use it. In the development of the first version of the application, you typically do not experience problems solved by this method. In addition, the use of well-designed, distributed architecture will slow down the speed of development. For start-up companies, this could be a major problem, which is usually the biggest challenge is how to quickly develop business models and applications that are included. Use Y axis split may cause rapid iterations even more difficult. However, later, when the challenge is how to expand and you need to use functional decomposition, tangled dependencies may make it difficult for you the whole application into a set of services.

How application into service?
 

Another challenge is to decide how the system is divided into micro-services. This is an art, but there are a number of strategies can help:

Ideally, each service should be only a small part of the responsibility. (Uncle) Bob Martin comes to a single responsibility principle (SRP) design course. SRP will define the responsibilities of the class as a reason to change, and declare the class should only be a reason to change. SRP will apply to service design also makes sense.

Another analogy is designed to help service design Unix utility. Unix provides a number of utilities, such as grep, cat and find. Each utility is done one thing, usually very good, and you can use shell scripts in conjunction with other utilities to perform complex tasks.

How to maintain data consistency?

In order to ensure loose coupling, each service has its own database. Maintaining data consistency between services is a challenge, because distributed transactions is not an option / Phase 2 many applications submitted. Applications must use Saga mode. Service publishing event when its data changes. Other services use this event to update its data. There are several ways to reliably update the data and publishing events, including events procurement and transaction log tailing.

How to implement the query?

Another challenge is to realize the need to retrieve data from multiple services have queries.

  • A combination of API and command responsibility queries isolation (CQRS) mode.

Associated infrastructure mode

There are many patterns associated with micro-service mode. Single-chip micro-architecture service architecture alternatives. Other models to solve the problem in the application of micro-services architecture will encounter.
 

Known users

Most large sites, including Netflix, Amazon and eBay, including a single-chip architecture from the development of micro-services architecture.
Netflix is a very popular video streaming service, is responsible for up to 30% of Internet traffic, a large-scale, service-oriented architecture. They deal with every day video streams API from 800 different devices over one billion call. Each API call will be called back-end services to an average of six times.
Amazon.com initially two-tier structure. In order to expand, they migrate to the architecture composed of hundreds of back-end services-oriented services. There are several application calls these services, including the realization of applications Amazon.com Web sites and Web services API. Amazon.com's application calls 100-150 service to get the data used to build Web pages.
Ebay.com auction sites also evolved from a service-oriented architecture monolithic architecture. Application layer composed of a plurality of separate application components. Each application business logic specific functional areas, such as buying or selling. Each application uses the X-axis is divided, some applications (e.g., search using the Z-axis division). Ebay.com also X, Y and Z combination patterns scaled to the database layer.
The use of micro-services architecture company There are many other examples.

example

Chris Richardson has examples of microservices-based applications.

See my Code Freeze 2018 keynote, which provides a good introduction to the microservice architecture.

Guess you like

Origin www.cnblogs.com/paxlyf/p/11278228.html