Benefit distribution
In e-commerce and new retail, benefit distribution is used for marketing campaigns that target specific users. In these scenarios, it is technically difficult to guarantee strong consistency between the database (DB) and cached data. To address this issue, Alibaba Cloud ApsaraMQ for RocketMQ provides a benefit distribution solution. This topic uses an e-commerce scenario to describe the background, architecture, and advantages of this solution.
Background information
- User rules: Define which users, such as new users or members, are eligible for benefits. You can set specific conditions as needed.
- Benefit types: Specify the types of benefits, such as red packets, points, or coupons.
- Acquisition cost: Define the cost to acquire a benefit. For example, users may need to spend member points to obtain a discount coupon.
- Time control: Set the time for benefit distribution. For example, you can distribute 100 coupons to new users at 10:00 AM.
- Inventory: Ensure that the number of benefits is sufficient and matches the number of configured users.
After this operational data is written to the DB, it is transformed into a technical policy and then written to the cache. The data is then transformed into user distribution trace data, which consists of individual rules. Only users who meet these rules can claim the corresponding benefits.
Pain points
Allowing users to claim benefits by accessing cached data ensures efficient access and reduces the load on the DB. However, this approach introduces new problems:
- If there are many rules, a large volume of data is written from the DB to the cache. This process puts high pressure on the downstream cache. This scenario is rare.
- Data is written from the DB to the cache in a single attempt. A write operation might fail due to network jitter or other reasons, which can cause delayed data updates. For example, the inventory is originally set to 100,000. The operational policy then changes this number to 10. If the data is not synchronized promptly, downstream services are not notified of the change, which can lead to financial loss.
Solution architecture
ApsaraMQ for RocketMQ provides a retry feature and guarantees that no messages are lost. Therefore, this solution uses ApsaraMQ for RocketMQ between the DB and the cache to ensure strong consistency. The following figure shows the architecture.

Advantages of the solution
ApsaraMQ for RocketMQ provides the following advantages:
- High data throughput.
- Support for large-scale message accumulation. This helps reduce the impact of traffic peaks on downstream applications.
- Simplified implementation between the DB and the cache. This greatly reduces the development workload. Without ApsaraMQ for RocketMQ, the implementation method would be much more complex.
- Support for real-time messaging and a retry feature. This ensures that no messages are lost and guarantees strong consistency.