Q1,design an account System
<1> first look at the scene scenario:
The simplest is to find an example, such as the user system of Twitter.
Consider what needs to be: 1,register/updata/remove.2,login/logout.3, balance/menbership.
Consider what is most important in the requirements, what is most frequent: login/logout most frequent, but login than the Logout frequency should be much larger, so consider login to be able, in addition register is also very important, also need to design first alone.
<2> Estimating and calculating necessary (QPS):
1.Register:
ASK:
Total users:1,000,000,000 (then egg)
Daily Active users:1,000,000 (important)
Predict:
Register percentage:1% ~ 10% can, generally look at the flow, the new system is probably 20-30%, the old system 3-5% is also reasonable, here with 1%.
Daily active users in three months:1,000,000 * 2 = 2,000,000 (estimation) factor can be 1.5/2/3 is reasonable
Because we do a system all for three months, all the design standards are three months later.
Daily Register users:2,000,000 * 1% = 20,000;
Register QPS = 20,000/86400s < 1QPS ==> stand-alone handling no problem at all
2. Login:
Predict:
Login percentage:15%
Average Login times:1.2 (because not everyone login can enter the password, the total error when)
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 * = 42/s
<3> Application:
<----> Receptionist (Task Dispatcher) <----> 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 |
--------------------------------------
| | | |
| | | |
--------------------------------------
[System Design] Database system-------Account system Q1_design User system