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:

  1. Business background
  2. Overall Architecture
  3. Storage Architecture Design
  4. Computing Architecture Design
  5. 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]

  1. The technical team is about 10 people, 6 on the back end, 2 on the front end, 2 on Android,iOSNo;
  2. The back-endJavaMostly, mostlyP6~P7;
  3. The back-end haveMySQL, microservices,RedisExperience in development and use;
  4. The backend has no experience with big data and recommendations.

Basic service scenarios:

  1. Each user uses an algorithm to generate asymmetric public and private keys;
  2. Messages sent by users are encrypted using public keys, and messages received by users are decrypted using their own private keys.
  3. [Fixed] Can only create one-to-one chat
  4. Chat messages burn after reading for a maximum of 60 minutes;
  5. No need to use your mobile phone number to register;
  6. 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:

  1. One hundred thousand scale: landing block, but if the business develops quickly, the architecture quickly does not adapt to what to do?
  2. Millions of scale: landing slower, but also facing the risk of business development too fast.
  3. 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:

  1. Business scale changes: can be advanced design response
  2. 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.
    1. 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:

  1. [Registration] : 100,000 user registration information.
  2. [Login] : AlthoughIMIt’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.
  3. [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.
  4. [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:

  1. MySQLActive/Standby (User data + Relationship data)

100,000 user registration information, 40,000 login information, 800,000 relational data.

  1. RedisActive/Standby (Chat data)

20 million writes, 20 million reads, 20 million deletes.

MySQLWhy not use master-slave read-write separation?RedisWhy not read and write separate?





4. Computing architecture design

Calculation performance estimation of 100,000 users:

  1. [Registration] : 100,000 users registered in one yearTPSIs very low.
  2. [Login] : AlthoughIMIs 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, loginTPSAverage: 40,000/14400 = 3.
  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.TPSIt’s negligible.
  4. [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: