This is the 14th day of my participation in the August More Text Challenge
One, foreword
Learning: Master key points of 100,000 user scale IM architecture design
General idea:
- Business background
- Overall Architecture
- Storage Architecture Design
- Computing Architecture Design
- Other Architectural Designs
Business Background:
Suppose you are working as a CTO in a startup company. Because wechat does not distinguish between work, life and entertainment, you have sent sensitive information to the wrong person or even the wrong group for many times. The CEO of your company decides to make an IM tool. In order to distinguish wechat from QQ’s popular IM demands, your company focuses on secure IM. The competitiveness of this product is as follows: It focuses on private chat and strictly controls the number of private friends, rather than adding wechat to buy a dish like wechat. [Company Background]
- The technical team is about 10 people, 6 on the back end, 2 on the front end, 2 on Android,
iOS
No;- The back-end
Java
Mostly, mostlyP6
~P7
;- The back-end have
MySQL
, microservices,Redis
Experience in development and use;- The backend has no experience with big data and recommendations.
Basic service scenarios:
- Each user uses an algorithm to generate asymmetric public and private keys;
- Messages sent by users are encrypted using public keys, and messages received by users are decrypted using their own private keys.
- [Fixed] Can only create one-to-one chat
- Chat messages burn after reading for a maximum of 60 minutes;
- No need to use your mobile phone number to register;
- Each user has a maximum of 20 friends.
Ii. Overall architecture
The boss said that we would achieve 10 million registered users within 3 years. As a CTO, how should you design the architecture?
Architectural design ideas:
- One hundred thousand scale: landing block, but if the business develops quickly, the architecture quickly does not adapt to what to do?
- Millions of scale: landing slower, but also facing the risk of business development too fast.
- Scale of ten million: The landing time may be more than 6 months, but basically there is no need to move the structure within 3 years.
Architecture evolution follows:
- Business scale changes: can be advanced design response
- Business diversity: It’s impossible to predict what features will be built, and it’s even harder to predict how large the team size will grow as a result of business diversity.
-
- Technological development: unpredictable, especially related to laws and policies, such as blockchain, localization, etc.
Iii. Storage architecture design
Performance estimation of large-scale storage with 100,000 users:
- [Registration] : 100,000 user registration information.
- [Login] : Although
IM
It’s an active product, but since it’s a brand new product, let’s say 100,000 registered users, 40% of the active users per day, 40,000 logins per day. - [Add friends] : Each active user has a maximum of 20 friends, and the number of friend relationships is 40,000 * 200,000 = 800,000 relationship data.
- [Chat] : Suppose that every active user sends 100 messages to five friends every day, then the number of messages is: 40,000 * 5 * 100 = 20 million, and the data is basically deleted that day, so the number of write, read and delete can be estimated to be 20 million.
Storage architecture:
MySQL
Active/Standby (User data + Relationship data)
100,000 user registration information, 40,000 login information, 800,000 relational data.
Redis
Active/Standby (Chat data)
20 million writes, 20 million reads, 20 million deletes.
MySQL
Why not use master-slave read-write separation?Redis
Why not read and write separate?
4. Computing architecture design
Calculation performance estimation of 100,000 users:
- [Registration] : 100,000 users registered in one year
TPS
Is very low. - [Login] : Although
IM
Is a relatively active product, but since it is a brand new product, we assume 100,000 registered users, 40% of the active users every day, assuming that the login time is concentrated in the morning and evening 4 hours, loginTPS
Average: 40,000/14400 = 3. - [Add friends] : Each active user has a maximum of 20 friends. The number of friends is 40,000 * 200,000 = 800,000. The data is calculated in one year.
TPS
It’s negligible. - [Chat] : Assuming that each active user sends 100 messages to five friends per day, the number of messages is: 40,000 * 5 * 100 = 20 million; Suppose that messages are sent within six hours (one hour in the morning, one hour at noon, one hour at night and four hours at night)
TPS
:20 million /(3600*6)≈ 1000, reads the messageQPS
= Send messageTPS
, delete the messageTPS
≈ send messageTPS
Load balancing for computing architectures
The load-balancing architecture is shown as follows:
Caching architecture for computing architecture:
5. Other architectural design
Extensible architecture design:
High Availability Architecture Design – Metropolitan Data Dr: