当前位置:Gxlcms > 数据库问题 > [系统设计] Database System -------Account System Q1_Design User System

[系统设计] Database System -------Account System Q1_Design User System

时间:2021-07-01 10:21:17 帮助过:3人阅读

Q1,Design an Account System

<1>首先要先看场景scenario:

最简单的就是找一个例子,比如twitter的user system。

考虑都应该有什么需求:1,register/updata/remove.2,Login/Logout.3, Balance/menbership.

考虑需求中什么最重要,什么用的最频繁:Login/Logout 最频繁,但是Login比Logout频率应该会大很多,所以考虑Login就可以了,另外register也很重要,也需要单独先设计一下。

<2>估算并计算Necessary(QPS):

  1.Register:

  ASK:

    Total users:1,000,000,000 (然并卵)

    Daily active users:1,000,000 (重要)

  Predict:

    Register percentage : 1% ~ 10%都可以,一般看流量,新系统大概20-30%,老系统3-5%也都是合理的,这里用1%。

    Daily active users in three months: 1,000,000 * 2 = 2,000,000 (估算) 系数可以是1.5/2/3 都是合理的

                      因为我们做一个系统都是为了三个月之后,所有设计标准也是三个月之后的。

    Daily register users: 2,000,000 * 1% = 20,000;

    Register QPS = 20,000 / 86400s < 1QPS ==>单机处理完全没问题

  2. Login:

  Predict:

    Login percentage: 15%

    Average Login times: 1.2 (因为不是每个人登陆都可以输入对密码,总有错的时候)

    Daily login time = 2,000,000 * 15% * 1.2 = 360,000

    Login frequency = 360,000 / 86400 S = 4.2/s

    Normal login frequency = 4.2 * 2 = 8.4/s

    peak login frequency = 4.2 * 10 = 42/s

<3> Application:

  <----> receptionist(任务分发器) <----> Account Service {register/updata/remove, login/logout, balance/membership}

<4> Data: user(V1)

  class user {

    private:

      int userId; // primary key ==> save space, select quickly

      String name;

      String password;

  }

  UserTable:

  class userTable{

    private:

      vector<user> table;

    public:

     ...insert(...);

     ...delete(...);

     ...update(...);

     ...select(...);

  }

  ___________________________

  |  userID  |  name  |  password  |

  --------------------------------------

  |              |            |                 |

  |              |            |                 |

  --------------------------------------

 

 

    

[系统设计] Database System -------Account System Q1_Design User System

标签:

人气教程排行