Large Web site Architecture (4) asynchronous communication in distributed

Source: Internet
Author: User
Tags message queue split rabbitmq

We know that in object oriented programming, always think of various ways to achieve the decoupling of the code, so that the various personnel in the project to face their familiar business development, so that the operation of the industry has specialized, such as everyone is very familiar with the three-tier architecture, MVC,MVP and MVVM mode, so that the front-end design focused on the production of HTML, Let the backend developer focus more on the writing of business logic, and see that we are doing this to maximize the scalability and maintainability of the system, does our large Web site follow this pattern as well?

One: Layering and partitioning

1: Layering

For tiering, we may be very familiar with the data access layer, the business logic layer, the cache layer, the application layer, layer by layer focus on their own business, and then set up their own clusters as needed, separate deployment, and from the system to achieve scalability and maintenance.

2: Split

If the front is transverse cutting, the split is longitudinal cutting, we can cut the whole business of the site into a lot of small business, such as the blog Park navigation bar, we can think of a separate site, with their respective level two domain name, the establishment of their own clusters to achieve system expansion, of course, this size can be large and small.

If you say that these subsites do not exist to invoke each other, then we add modules or modify the module will basically not affect other modules, which is also our ultimate goal to do extensibility, now since all do decoupling, the following goal is to do how to communicate, communication can be divided into "synchronous" and "asynchronous", This article mainly discusses the asynchronous operation, in the distributed system to do "asynchronous operation", of course, the powerful message queue.

Two: Message Queuing

After using Message Queuing in a distributed system, our producers return immediately after they have dumped the data in the message queue, and no matter which consumer is consuming it, you can see that Message Queuing has the following three advantages.

1. Speed up the website accordingly

I just said that, too. The application layer directly to the message queue and then directly back to the caller, so that the processing of complex business logic and then synchronized into the database after the return caused by the response delay, in many Web sites, users submit orders is so processed, the application layer to generate an order number, The order is dropped to the message queue, then directly to the order Success page, at this time the back-end consumer to the order has not been processed, because there will be more data operations, such as inventory reduction, database synchronization and so on, and users want to see the order details, you need to click the "Order Number" to enter the Order Details page, This process is also due to the timeliness of Message Queuing, so you need to get the site designer to improve and support.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/web/Skills/

2. Availability of the system

Since it is asynchronous operation, it caused the producers do not know the existence of consumers, and in turn consumers do not know the existence of producers, if the consumer hangs will not affect the producers, producers will also be the same as normal to Message Queuing messages, when the consumer return to normality will continue to consume Message Queuing, The performance of the system may be that email or SMS delay received, will not cause too much impact on the system.

3. Concurrent Cutting Peak

Since it is a large web site can not avoid high concurrent read and write operations, a typical example is the second kill, this high concurrent write operation, if all of a sudden influx into the database inside, will cause the pressure of the database is very large, resulting in the client's access delay, is not hanging also easily caused by the deadlock in the database to create a lot of supernatural events, encountered this yiyongerru situation, we must be linearized operation, at the code level we can use the lock mechanism to serialize, in the distributed we use "message queue" to serialize, Moreover, the dynamic flood control of message queues can be controlled by logic operation.

On the choice of message queues, Microsoft has its own MSMQ, but in a large web site, our message queues also need to cluster, and want to run in memory, and support the serialization of the hard drive, while in the "scalability" and "reliability" on the good, so recommend that you use open source RABBITMQ, URL: http://www.rabbitmq.com/But many companies have their own development of the message queue, such as Ctrip Cmessage, Taobao Metaq.

Author: cnblogs Line code Agriculture

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.