Why are we using Springcloud?

Source: Internet
Author: User
Tags failover

    • 1
    • 2

Monolithic architecture
In the early stages of site development, the project faces relatively little traffic, and a single application can achieve the functionality we need to reduce the difficulty of development, deployment, and maintenance. The data Access framework (ORM), which is used for simple additions and deletions, is very important.

Vertical Application Architecture
As user access continues to increase, a single application needs to constantly increase the number of servers to cope with, while splitting a single application into multiple applications to handle efficiency improvements. This web framework (MVC), which is used to accelerate web front-end loading, plays a key role.
At this stage, the system is often divided into different levels, each of which has corresponding responsibilities, the UI layer is responsible for interacting with the user, the business logic layer is responsible for the specific business functions, the database layer is responsible for the data exchange and storage at the upper level.

在这一阶段我们最常使用到的开发框架就是Spring(业务逻辑层管理POJO)+Struts(web层前置服务控制)+Hibernate(数据库层持久化)。
    • 1
    • 2

Service-Structured architecture
With the continuous improvement of enterprise service volume, the deployment of MVC framework leads to more and more load of system, which can not meet the requirement of concurrency, and the transmission of data and messages between systems will be lost frequently. At this point we need to consider a service-oriented architecture (SOA). SOA represents a service-oriented architecture. The application is divided into different modules according to different responsibilities (similar to the Enterprise division of different divisions), and different modules interact with specific invocation protocol (RPC) and interfaces.
This allows the entire system to be divided into a number of individual component Services to complete the request, and when the traffic is too large to support by horizontally scaling the corresponding components, all the components interact to meet the overall business requirements.
The advantage of SOA service is that it can be distributed, combined, and used across the network for loosely coupled coarse-grained application components based on demand.
The service layer is the foundation of SOA and can be called directly by application, thus effectively controlling the human dependence of the software agent interaction in the system.
The service architecture is a loosely coupled architecture in which service splitting is the principle of high cohesion within the service and low coupling between services.

At this stage, you can use WebService or Dubbo to service governance.
Micro-Service Architecture
The microservices architecture is an extension of the SOA architecture, focusing primarily on the independence of the service individual and the smaller granularity of the separation. Compared to the SOA architecture, microservices have the following advantages:
MicroServices emphasize deeper component and service, each of which can have a separate running space, ensuring that each service component can be released as a separate product.
MicroServices have abandoned the cumbersome enterprise service bus of traditional SOA, and externally published an interface publishing form that emphasizes the use of the HTTP REST API.
The granularity of micro-service segmentation is large.
Understanding the evolution of the architecture, let's meet Spring Cloud.
Spring cloud comes from spring and is developed quickly with spring boot. Thanks to the large number of people who maintain and support the spring cloud community today, we believe Spring cloud will be well developed. And spring cloud is basically using the existing open source framework for integration, learning difficulty and deployment of the lower threshold for small and medium-sized enterprises, more easy to use and landing.
What issues does Spring cloud solve primarily?
1, for enterprise-level SOA framework, the decoupling between services and services is a huge problem, with the continuous increase of functional services, multi-service inter-invocation of frequent, call process like a messy yarn ball, it is easy to lead to reaching situation, often due to the process of service updates, No reasonable communication, resulting in loss of data.
At this point, service governance should be carried out, and the direct reliance between services will be transformed into service-to-service dependencies. The Spring Cloud Core component Eureka is a solution to this kind of problem.
Eureka
Eureka is a product of Netflix's open source offering service registration and discovery, which provides complete services registry and service discovery implementations. is one of the most important and core components of the spring cloud system.
With plain English, Eureka is a service center, all the services can be provided to register it here to manage, the other callers need to go to the registry to obtain, and then make the call, avoid the direct call between services, easy to follow the level of expansion, failover and so on. Such as:

Of course, the service center is such an important component one but hanging off will affect all services, so you need to build Eureka cluster to maintain high availability, the production of a minimum of two units recommended.
As the flow of the system continues to increase, a service needs to be scaled according to the situation, and the Eureka internally has the capability of balancing the load, and only needs to add the corresponding server instance.
What if an instance hangs during the run of the system? Eureka Content has a heartbeat detection mechanism, if an instance does not communicate within the specified time, it will automatically be eliminated, to avoid an instance hanging off and affect the service.
Therefore, the use of Eureka automatically has a registry, load balancing, failover functions.
Hystrix
In a microservices architecture, there are often multiple service layer calls, and the failure of the underlying service can lead to cascading failures that could result in an entire system being unavailable, a phenomenon known as service avalanche effect.
The service avalanche effect is a process in which the service consumer is not available and will not be usable due to the unavailability of the service provider.
As shown in: A as a service provider, B is a service consumer, C and D are service consumers of B. A unavailability causes the unavailability of B and will not be available as a snowball to C and D, the avalanche effect is formed.

In this case, the whole service is required to have the function of fault isolation, to avoid a service hanging off the impact of the global. The Hystrix component plays this role in spring Cloud.
Hystrix will immediately notify the caller of the call failure and prevent the caller from continuing to wait for the whole service to be affected if a service calls N-times without response. The Hystrix interval will check again for this service if service recovery will continue to serve.
Hystrix Dashboard and turbine
When the fuse occurs, it is necessary to respond quickly to solve the problem and avoid further spread of the fault, so the monitoring of the fuse becomes very important.
Fuse monitoring now has two tools: Hystrix-dashboard and turbine
Hystrix-dashboard is a real-time monitoring tool for Hystrix, through Hystrix dashboard we can visually see the request response time of each hystrix command, the request success rate and other data.
But using only Hystrix dashboard, you can only see the service information in a single app, which is obviously not enough.
We need a tool that allows us to summarize data from multiple services within the system and display it on the Hystrix dashboard, which is turbine.
The following are monitored:

To find out what metrics are monitored and how to monitor it, refer to this article: Fuse monitoring Hystrix dashboard and turbine
Configuration Center
With the increasing number of microservices, each micro-service has its own corresponding configuration file. In the development process has the test environment, the UAT environment, the production environment, therefore each micro-service also corresponds to at least three different environment configuration file.
So many configuration files, if you need to modify the configuration information of a public service, such as: cache, database, etc., will inevitably create confusion, this time you need to introduce another component of Spring Cloud: Spring Cloud Config.
Spring Cloud Config
Spring Cloud Config is a configuration management solution for distributed systems. It contains the client and server two parts, the server provides the configuration file storage, in the form of an interface to provide the contents of the configuration file, the client through the interface to obtain data, and based on this data to initialize their own applications.
In fact, the server side will all the configuration file service, need to configure the service instance of the file to the config server to obtain the corresponding data. All configuration files are consolidated to avoid configuration file fragmentation.
If the configuration file is changed during service run time, the service will not get the latest configuration information and need to solve this problem to introduce refresh. It can reload the configuration file during the run of the service.
When all the configuration files are stored in the configuration center, the configuration center becomes a very important component.
If a problem with the configuration center can result in catastrophic consequences, it is recommended that you cluster the configuration center in production to support high availability of the configuration center.
Spring Cloud Bus
The Refresh scheme above can solve the problem of overloading configuration information during the operation of a single microservices, but in real practice production, there may be more than N services that need to be updated for configuration.
If you rely on manual Refresh every time it will be a huge amount of work, then Spring Cloud presents another solution: Spring Cloud Bus.
Spring Cloud Bus connects the nodes of each distribution through a lightweight message broker. This is used for changes in broadcast status (such as configuration changes) or other message directives.
One of the core ideas of spring Cloud Bus is to extend the spring boot application through a distributed launcher, or to establish communication channels between one or more applications. The only way to implement this is to use the AMQP message agent as a channel.
Spring Cloud Bus is a lightweight communication component that can also be used in other similar scenarios. With Spring Cloud Bus, when we change the configuration file submission to the repository, it automatically triggers the refresh of the corresponding instance, with the following workflow:

Service Gateway
In MicroServices architecture mode, the number of instances of back-end services is generally dynamic, and it is difficult for clients to discover the access address information of dynamically changing service instances.
Therefore, in order to simplify the invocation logic of the front end in a microservices-based project, the API gateway is often introduced as a lightweight gateway, and the API gateway implements the relevant authentication logic to simplify the complexity of calls between internal services.

The technology that supports API Gateway's landing in the Spring cloud system is zuul. Spring Cloud Zuul Routing is an integral part of the microservices architecture, providing dynamic routing, monitoring, resiliency, security, and other edge services.
Zuul is a load balancer based on the JVM Routing and service side of Netflix.
Its specific role is service forwarding, receiving and forwarding all internal and external client calls. The use of Zuul can be used as a unified access portal for resources, but also can be done in the gateway to do some similar functions such as permission checking.
Link Tracking
As the service becomes more and more, the analysis of the call chain becomes more and more complex, such as the call relationship between services, the call chain corresponding to a request, the time spent between calls, and so on, which is a problem to monitor.
In practical use we need to monitor the metrics of communication between services and services, which will be the primary basis for our improved system architecture.
So distributed Link tracking becomes very important, and spring cloud provides a concrete solution: Spring Cloud Sleuth and Zipkin.

Spring Cloud Sleuth provides link tracking for calls between services. With sleuth, you can clearly understand what services a service request has gone through, and how long each service has taken to process. So that we can easily clarify the relationship between micro-service calls.
Zipkin is an open source project on Twitter that allows developers to collect monitoring data on Twitter's services and provide a query interface.
Summarize
Let's take a holistic look at how the various components of spring cloud work together:

We can see that the various components of spring cloud work together to support a complete micro-service architecture.
Among them, Eureka is responsible for the registration and discovery of the service, which connects the services well.
The hystrix is responsible for monitoring the call situation between services, successive failures for fuse protection.
Hystrix Dashboard,turbine is responsible for monitoring the hystrix of the fuse and giving a graphical display
Spring Cloud Config provides a unified configuration center service
When the configuration file changes, Spring Cloud Bus is responsible for notifying the services to get the latest configuration information
All external requests and services, we are through the Zuul to carry forward, play the role of the API Gateway
Finally, we use Sleuth+zipkin to record all the request data, so that we could perform the subsequent analysis.
Spring cloud has taken into account the features of most Internet company architectures since its inception, such as service discovery registration, Configuration center, message bus, load balancing, circuit breakers, data monitoring, and more.
These functions are provided in the form of plug-in, convenient for our system architecture evolution process, we can reasonably choose the components required for integration, so that the evolution of the architecture will be smoother and smoother.
Micro-service architecture is a trend, Spring cloud provides a standardized, all-in-one technical solution, meaning may be comparable to the current servlet specification is born, effectively promote the service side software system technology progress.

Why are we using Springcloud?

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.