Architecture design of solving data consistency problem in Distributed system

Source: Internet
Author: User
Tags string format wrapper

Http://blog.sina.com.cn/s/blog_77e858f80100xvy7.html



When considering the design of the system architecture, not only the technical implementation, but also the business considerations, design for business considerations, will let us make a more reasonable choice in technology.

In this paper, we discuss the architecture design of how to combine restful with MQ (message middleware) and solve transactional integrity/data consistency problem in distributed system based on business considerations.

first, the final consistency plan for business considerations

Let's take two examples here.

1, Alipay's "WS Transaction standard" attempt:

Alipay has tried the WS transaction standard in their distributed system to solve the problem of transactional integrity, but after actually testing it, it was found that the cost was too high. To complete a transaction, to ensure transactional integrity, the interaction of more than 20 messages, of which only 1 are business messages, and others are protocol messages between the systems. This causes the client to respond too slowly and the customer cannot afford this performance.

2. The ultimate consistency scheme of ebay architects:

Architects from ebay have given them solutions based on their best practices. is about data consistency, such as how their distributed storage maintains data consistency. This paper discusses the paradox between "real-time consistency" and "strict transaction", and they adopt a local real-time consistent and globally consistent solution. Here it is necessary to discern from the business which operations are to be relaxed (not allowed in a transaction) and which operations must be atomic. Now that the entire architecture of ebay is based on "final consistency", Alipay is also inspired by this design approach to solve the "client response" and "server-side data consistent" contradiction.

Therefore, considering the system architecture design, not only to consider the technology, but also to consider business factors, business considerations for the system design, will let us make a more reasonable choice in technology. Based on business considerations, it facilitates the prioritization of transactions and facilitates optimal trade-offs in architectural design. In general, the integrity of the transaction (or data consistency) of a bank or security system has an absolute priority, and it requires an absolutely strict real-time guarantee. The communication system has a complex accounting transaction in which the priority level of transactional integrity (or data consistency) is not even high on Alipay and ebay. If they also believe that local real-time consistency and overall consistency can meet the requirements of the business, then nature in the communication system also has its feasibility.

second, restful and MQ technology application scenario analysis

The RESTful technology architecture is generally a set of resource services that are open to clients . In distributed system, there are both client-server interaction and server-server interaction. For example, the XCAP protocol is a standard restful interface that provides services for clients to manipulate XML documents remotely, while "operations management systems" invoke other business system interfaces to manage the services and permissions that users can assign, as well as information interactions between servers. The former is of course suitable for restful technical interfaces, which individuals prefer asynchronous, message-based communication. Because the client and server are usually across the Internet, and the server and server may be located in a local area network, and may even be placed in the same room.

We know that the technical architecture of restful style is usually communicated through JSON or XML, in short, through the encapsulation of "string format". Interactive information through the character format is easy to use, because the process of encapsulation, parsing, and transformation makes it more natural to pay a price in performance, if it is between the server at the bottom of the same kind of protocol between the data interaction performance is much higher. Here, incidentally, the performance order of information interactions in different scenarios, sorted from fast to slow:

1, the information interaction between the same process;

2, the same machine two processes between the information interaction;

3, two distribution of the information between the machine interaction.

Because HTTP is a wrapper on top of the TCP/IP protocol, WebService is a wrapper over the HTTP protocol, based on the more efficient characteristics of the information interaction between lower-level protocols, from fast to slow ordering:

1, the information interaction based on TCP/IP protocol;

2, based on the HTTP protocol information interaction;

3, based on the WebService protocol information interaction.

In addition, because the "operational management system" is directly interacting with other systems, such as operations to open certain services to a particular user, it is necessary to invoke the " fine-grained " interface of the business systems that provide these services separately. Once the new service is added, it will inevitably affect the modification of the Operation management system. We say there is a principle in distributed systems where possible to design " coarse-grained " interfaces to reduce network interaction between systems. If the information is interacted between the operations management system and other business systems by "message middleware", then:

1, the Operation management system can design service-oriented " coarse-grained " interface, open several services only need to encapsulate several types of data, one-time transfer to MQ. Adding services only adds a single data type;

2, MQ can guarantee that the message will eventually be received and processed. Because MQ can implement the Event-driven mechanism based on "subscription-notification", the business system can receive messages from MQ in real time as long as it registers itself in MQ. Even if a system or network exception occurs, the message is persisted by the MQ middleware, and once the business system is restored, the message is immediately sent to the business system, which is obviously much more efficient than scanning the database at every interval of time.

Iii. MQ and eventual consistency MQ Message Queuing technology is a technique for exchanging information among distributed applications. Message Queuing can reside in memory or on disk, and queues store messages until they are read by the application. With Message Queuing, applications can execute independently-they do not need to know each other's location, or wait for the receiving program to receive this message before proceeding. It provides a loosely coupled approach to distributed applications implemented asynchronously, in applications that perform a variety of functions, such as requiring services, exchanging information, or asynchronous processing.

In distributed system, especially in the distributed system of different languages, if there is no message middleware to complete the information exchange, the application developer must write the corresponding language application to send and receive the information in order to transfer the data efficiently , and there is no standard method for exchanging information. Each application must be programmed to communicate with one or more applications in multiple platforms and in different environments.

If the system can adopt the data " local real-time consistent, global final consistent " scheme, you can choose not to support the transaction of MQ middleware, because it can guarantee that: even in the case of system anomalies, network anomalies, and other special circumstances, the message will be persisted, when the system recovers, the message will be processed immediately, That will eventually be treated, that is, ultimately, consistent. MQ performance and throughput rates that do not require transactional support will be high.

in a word, individuals tend to provide services to clients with restful, MQ services are introduced between servers, asynchronous, message-based information interaction is established, and transaction problems are solved based on the principle of local real-time data consistency and global eventual consistency.

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.