Common Solutions for Scheduling and Delay Problems in Business Scenarios
This article begins with how to deal with scheduling and delay problems in workflow and information distribution. Then, it compares several common solutions in the industry, such as the direct multi-thread coding, Spring timed scheduling framework, large-scale distributed scheduling framework, and message scheduling based on message-oriented middleware (MOM). MOM provides user-friendly APIs, features easy calling, and has stable performance, and therefore MOM is recommended for resolving the aforementioned problems. This article also compares the pros and cons of ActiveMQ, RabbitMQ, and RocketMQ in these scenarios.
To help you understand how to use MOM, we will introduce three common scenarios and the solutions. We will also describe the advantages of scheduled messages for RocketMQ. The features of scheduled messages will be extensively updated in the near future. The new version of scheduled messages has been running stably in Alibaba for nearly two years and will be available in the public cloud soon.
The demand for scheduled and delayed processing is ubiquitous in the processes of information distribution and business. We often encounter problems such as, what are the elegant ways to handle expected events and distribute defined information at a certain point of time in the future, and how to design scenarios and business logic with demanding timeline requirements. After comparing several commonly used technical solutions, I summarized them as follows, and each of them has its own pros and cons:
MOM provides developer-friendly API design and supports agile development, allowing developers to efficiently integrate and develop APIs. It supports both “scheduled” and “delayed” scenarios, and provides high performance and availability for large-scale distributed business scenarios. On the whole, MOM is more convenient to use.
Do these features perform differently in different MOMs? First, let’s take a look at what features are required for an excellent scheduled or delayed MOM.
- It is lightweight, high-performance, and accurate to the second.
- It supports high availability.
- The scheduled time is sufficient, for example, 30 or 60 days.
- It supports the cancellation of scheduled messages and delayed tasks.
- It supports absolute and relative scheduling.
- It supports the storage of massive scheduled messages with high efficiency and accuracy.
According to the preceding analysis, let’s compare some popular MOM products in the industry. Among the current mainstream message systems, ActiveMQ, RabbitMQ, and RocketMQ can all provide scheduled message functions. However, the scheduling performance of ActiveMQ is about 300 transactions per second (TPS), which is only suitable for small-scale scenarios. RabbitMQ provides a scheduling plug-in with a performance of about 2,000 TPS. However, it does not support high availability and mass message accumulation.
The new version of RocketMQ scheduled message function incorporates the advantages of different major scheduled message components, and makes up for the limitations in the design of other components. Therefore, it supports more scheduled and delayed scenarios.
Let’s see how they perform in real-life scenarios. Let’s take a brief look at several typical scheduled and delayed scenarios, which are implemented by using RocketMQ scheduled messages.
- Scenario 1: During a flash sale for popular products, coupons are frozen when users use them to place orders. The frozen coupons can be restored by the mechanism of automatic recovery after timeout. The mechanism of automatic recovery after timeout is required for meeting requirements such as high precision, high availability, support for a large number of services, and support for long latency.
- Scenario 2: The take-out service is very time-sensitive. “Delivery timeout” counts down once a user places an order, ensuring that the take-out service proceeds in sequence. The delivery timeout mechanism must meet the requirements of high precision, high availability, and support for massive services.
- Scenario 3: After a schedule is set in DingTalk software, automatic user reminder is required when the scheduled time is reached. The schedule reminder of DingTalk requires high precision and long latency.
Now, let’s look at the concepts of scheduled messages and delayed messages in RocketMQ. Based on the user perspective and experience, messages can be divided into scheduled messages and delayed messages.
- Scheduled Message: The producer sends a message to the RocketMQ server, but intends the message to be postponed to a later time instead of being sent immediately to the consumer. See “Scenario 3” in the previous section for reference.
- Delayed Message: The producer sends a message to the RocketMQ server, but intends the message to be sent to the consumer after a period of time, that is, as a delayed message. See “Scenario 1” and “Scenario 2” in the previous section for reference.
For instructions, visit the official website
3) Advantages of RocketMQ Scheduled Messages
- High Performance and Availability
Message Queue for RocketMQ provides hierarchical delayed messages. It features high performance and accumulates messages without limits for high availability. It also supports scheduling within seconds to achieve highly precise mass storage.
- High Product Maturity
In various businesses and promotional scenarios in the Alibaba economy, RocketMQ scheduled messages have been widely used and have withstood numerous traffic peaks and stability tests. RocketMQ has become the stable scheduled message system that leads the industry.
- High Technology Community Activity
As a top-level Apache project, RocketMQ has built a complete technical ecosystem. With multi-language and multi-protocol support, its scheduled messages naturally inherit the advantages of top-level projects and feature a complete technical ecology.
- Professional Technical Support
Alibaba Cloud focuses on cloud computing, and RocketMQ continues to evolve along with the technical architecture of Alibaba Cloud. While providing technical facilities, our strong technical teams are also providing professional technical support for customers who are using RocketMQ.
4) Special Introduction
In the new version of the scheduled message function, the kernel layer architecture is deeply optimized, the design principles and functional implementations are significantly upgraded and tuned, and the architecture of scheduled messages is fundamentally renovated. The new version greatly improves the stability and performance of scheduled messages.