My Thoughts on WeChat Red Packets
Filed under Mathematics, Probability theory on February 25, 2025. Last updated on February 25, 2025.
toc
- Overview
- The Rise of WeChat Red Packets
- Market Insights from WeChat Red Packets
- The Mathematical Principles Behind Red Packets
- Product Design and Technical Points Behind Red Packets
- Monte Carlo Method
Overview
WeChat Red Packets have been with us for many years. Since its birth in 2014, WeChat Red Packets have become an indispensable part of Chinese people's lives. Additionally, "red packets" as a growth tool has become something that many companies seek to emulate.
If you're not interested in the history of WeChat Pay and WeChat Red Packets, you can skip directly to The Mathematical Principles Behind Red Packets to understand the principles and implementation from a mathematical perspective.
The Rise of WeChat Red Packets
2014 was my last year at Tencent, and it was also a year of intense competition in China's mobile payment market. At that time, in China's internet payment sector, Alipay from the Alibaba group held absolute dominance, while Tencent's Tenpay, though also a leading third-party payment service, had a market share far behind Alipay's.
However, the birth of WeChat Red Packets completely changed this situation. Tencent, already strong in social networking, quickly gained a foothold in mobile payments under the viral spread of WeChat Red Packets, becoming a force that could rival Alipay in the payment sector.
Tencent's Work Resumption Red Packets
As a company founded in Guangdong, it has become a tradition for Tencent to give employees red packets when work resumes after the Chinese New Year. On the first day back at work after the Chinese New Year, grabbing red packets and having group meals are the highlights for all Tencent employees. Among all red packets, the most important ones are from the Executive Office.
On that day, the executives would personally hand out red packets to each colleague waiting in line at their office door. The red packet itself was secondary; the atmosphere of receiving red packets and the opportunity to meet with the executives were what mattered most.
In the early years, when Tencent had relatively fewer employees, the executives could still personally distribute red packets. However, as Tencent rapidly grew and the number of employees increased dramatically, how to efficiently distribute red packets became an issue. It is said that the birth of WeChat Red Packets originated from this problem.
Tencent's Innovation Culture
Compared to other Chinese internet companies, Tencent's corporate culture has always been very open and inclusive. Under this backdrop, the horse race mechanism has spawned many innovative products. Logically, a product like WeChat Red Packets should have been the responsibility of the WeChat team, but in reality, the birth of WeChat Red Packets can basically be attributed to the Tenpay team.
It is said that WeChat Red Packets was initiated by one product manager and three developers, all of whom were core members of the Tenpay team. Gradually, the WeChat Pay brand became the common ground between the WeChat and Tenpay teams.
Market Insights from WeChat Red Packets
Before WeChat Red Packets, "red packets" as a growth tool seemed to have never appeared before. In my opinion, there are several reasons:
-
Before WeChat Red Packets, the concept of a personal digital wallet had not been widely popularized.
Although Alipay was an important third-party payment channel with its own independent account balance system, people mostly viewed it as a supplement to bank accounts rather than an independent wallet. Alipay did have account-based products like Yu'ebao, but Yu'ebao's essence was a money market fund, not a high-frequency wallet application.
During the same period, Yu'ebao already had a high market share, and it seemed Alipay had no motivation to develop another wallet application scenario.
-
The market was still exploring what third-party payments and mobile payments could do.
Before WeChat Red Packets, most people's imagination of mobile payments was limited to the payment level, merely completing transactions between buyers and sellers. WeChat Red Packets as a product transcended the payment category, making people realize that mobile payments could have more possibilities.
The success of WeChat Red Packets, especially WeChat Pay's catch-up with Alipay, was largely due to the viral spread of WeChat Red Packets. It showed everyone the growth potential and possibilities beyond payments. Essentially, the transaction parties changed from "buyer" and "seller" to "user" and "user".
The Mathematical Principles Behind Red Packets
So, how should we design a red packet product? Here, I'll share some of my thoughts to get the discussion started.
Essentially, red packets are a game of probability, so we need to review some basic concepts of probability theory: random variables and probability distributions.
If you want to skip directly to the conclusions, you can jump to Product Design and Technical Points Behind Red Packets.
Random Variables and Their Probability Distributions
Suppose we have one set of data:
13.94, 5.69, 13.11, 8.12, 2.53, 9.19, 6.82, 0.99, 18.95, 6.71...
And another set of data:
7.24, 12.74, 14.25, 12.12, 8.93, 8.25, 10.38, 2.40, 17.61, 6.08...
Can you spot the difference between these two datasets? It's certainly difficult to see at first glance. Let's visualize them.
Now the result is clear. These two random variables follow uniform distribution and triangular distribution respectively.
How to Precisely Describe Random Variables
While we can plot the probability distribution of random variables, this isn't enough. If we want to implement a random variable generation function, we need to describe the probability distribution more precisely.
Mean
First, it's important to note that some probability distributions don't have a mean, like the Cauchy distribution. We don't need to consider distributions without means here. For a product like red packets, we definitely want the packet amounts to have a mean, otherwise the difference in amounts received by different users would be too large, affecting user experience.
Variance and Standard Deviation
Variance and standard deviation are two important indicators that describe the dispersion of random variables. The larger the variance and standard deviation, the greater the dispersion of the random variable.
Interval
With mean and variance of random red packet amounts, we also need to consider the interval of packet amounts. Some random distributions have infinite intervals, like the normal distribution. If we want to use a normal distribution, we need to truncate the random variable to ensure the red packet amounts have a finite interval.
Product Design and Technical Points Behind Red Packets
To define a red packet, we need two user input parameters: the number of packets and the total amount.
Fundamentally, red packets need to be both fair and interesting. Fairness is the foundation, while being interesting is key. If the packet amounts are completely random, users might be disappointed by amounts that are too small; if the amounts are completely fixed, there would be no fun at all.
Product Design
For random red packet amounts, based on the above requirements, we need to satisfy at least two conditions:
- The expected value of red packet amounts should be as equal as possible.
- The variance of red packet amounts should be within a reasonable range - neither too small nor too large.
Additionally, there are some constraints to consider:
- Red packet amounts should have a minimum value and cannot be negative.
- Red packet amounts should have a maximum value and cannot exceed the total amount.
Technical Points
Probability Distribution
To simplify our implementation, we'll use uniform distribution as our default discussion. Other distributions like normal distribution can be considered later.
First, to ensure red packet amounts have a mean, the expected value of each red packet amount should be as equal as possible. And the expected value should be close to the average of the total amount. Following this logic, let's assume a total amount of 100, divided into 10 packets, with an expected value of 10 for each packet.
Running 10,000 random simulations, we get the following results:
However, observing the graph above, we find that the expected value each player receives isn't exactly 10. This is because we used a static mean. As packets are claimed, the probability of later players getting the same expected value decreases. For the last player, due to the fallback logic where they receive the remaining amount rather than a random value, their expected value ends up being greater than 10.
Dynamic Mean
To solve the static mean issue, we introduce a dynamic mean, making the expected value of each red packet equal to the average of the remaining amount.
Running another 10,000 random simulations, we get these results:
From these simulation results, we can see that dynamic mean effectively solves the mean difference issue. However, we notice that while the dispersion of packet amounts doesn't show the jumps seen with static mean, there's still an increasing trend.
Online vs Offline Algorithm
In our red packet amount generation algorithm, we assumed an online approach. Each amount generation depends on previous context; after an amount is generated, the context is immediately updated for the next generation.
However, in real red packet scenarios, whether to use an online algorithm may depend on specific circumstances. If we can generate amounts offline, introducing a shuffling algorithm on top of dynamic mean can result in fairer packet amounts.
From these simulation results, we can see that the shuffling algorithm effectively addresses the dispersion issue. This makes intuitive sense, as shuffling helps randomize the order of amounts, making the dispersion more uniform.
Summary
Above, we discussed the red packet amount generation algorithm and provided corresponding simulation results. Key points include:
- Determining the probability distribution of red packet amounts.
- Introducing dynamic mean to ensure expected values are as equal as possible.
- Based on actual circumstances, introducing shuffling algorithm to ensure uniform dispersion of amounts.
In actual development, there are many more details to consider, which we won't expand on here.
Monte Carlo Method
In the simulations above, I used the Monte Carlo method. By plotting the probability distributions of relevant data, we can visually observe the probability distribution patterns and gain an intuitive understanding of the simulation results. Here's an interactive tool that allows everyone to better understand the red packet amount generation process.