シャドーイング練習: System Design Mock Interview: Design WhatsApp - 動画で英語スピーキングを学ぶ
読み込み中...
1
can you tell me how you would design WhatsApp?
2
Hey everyone, welcome back to another Exponent System Design mock interview.
3
My name is Kevin Wei and on today's show we have Roshan.
4
Before we get started, Roshan, do you mind telling the audience just a little bit about yourself and then we'll get into the mock interview?
5
Of course, Kevin.
6
Thank you.
7
Thank you so much for inviting me to this interview.
8
My name is like roshan i work as a sd2 at amazon
9
and yeah i spend most of my time building highly scalable systems
10
and you know uh creating impact in the lives of billions of people excellent thank you roshan
11
so let's do this question today can you tell me how you would design whatsapp yeah of course
12
so maybe like usually whenever we start the system designs first we start with collecting all the requirements
13
so Kevin what I'm gonna do is first you know try to get all the requirements
14
that the WhatsApp application could have because today like you know everybody's aware of WhatsApp
15
and it has like a bunch of features
16
but in the interest of time maybe we will be developing only some you know essential features is that fine Kevin?
17
Yeah that sounds good maybe you can tell me what these essential features what the priorities might be sure
18
so yeah maybe i'll start writing it down
19
so first thing like maybe we can start with very basic
20
so today whatsapp is used uh you know to send
21
and receive messages uh you know um between um two peers
22
so yeah this is one of the most basic feature where
23
two person like one person one person can you know send
24
and receive message to another person
25
so this is like a you know the minimum feature
26
that any typical chat application should have the second uh one could be you know a group messaging where a member
27
would create a group they will add some x number of people in the group
28
and whenever the person sends the message all the other parties in the group will receive it
29
and everybody will know that who has sent that message
30
so that's the second feature that we may have
31
and we can also have like once the message has been
32
sent you know um the other person would be really interested
33
to know whether it has been delivered second one would be
34
like rather it should there should be three things three receipts basically the sent receipt the delivered receipt
35
and the read receipt so maybe in case
36
if we want we can add that as well sent delivered and read receipt
37
so yeah this could be another feature um so kevin anything uh
38
so far like on these three features do you want to add something yeah this makes sense sending
39
and receiving messages this seems like p0
40
group messaging is interesting and sending delivering read receipts just to let the user know
41
that the app is working and that everything that they're doing is working as planned
42
i think we can stick with this for now and then
43
if we want to add more features we can
44
if we have time okay so now maybe i'll just ask some more clarifying questions on this uh the first feature
45
so when we say messages
46
so are we talking only about the text messages are uh
47
you know the the person can send documents images videos um is that feature available in the first version
48
yeah great question let's assume that most of the messages are going to be text or images okay okay
49
okay got it so i think uh yeah so maybe i let me add some uh title in here
50
whatsapp system requirements okay
51
so now uh maybe i'll proceed with the you know the
52
design of like what what is going through my mind so um let me let me draw some icons in here
53
nice i love it some visuals for us yeah so let's say like this is the user a
54
and we also have another user in here B.
55
Okay.
56
So now we need some kind of a protocol where A can communicate to B
57
but in a more secured way so that we don't get, you know, like some third party should not be able to, you know, decode the message and,
58
you know, read it because that would be a pretty awful experience for the user B.
59
like to the to both the users for that matter.
60
So we need some kind of a protocol where we can you know establish
61
that communication and I think we have something called web sockets.
62
So web sockets was specially designed for peer-to-peer communication.
63
So maybe I can quickly write that down one second.
64
um web sockets however uh just using web sockets won't work uh how would like how would my system know
65
that you know this uh this user b is present in
66
some network like b should b would be connected to some network right
67
so we need some kind of a you know database where we know
68
to which box is a connected to and
69
which box is b connected to
70
so let me just change this a bit let me put this here
71
and let me remove this line over here and yeah
72
so let's say maybe i can here okay so now let me see
73
okay so we need api gateway
74
okay
75
so basically what would happen is this you know this phone
76
this this user a is connected to api gateway one
77
and there's another user b which is connected to ap api gateway two Now, maybe we can have a microservice.
78
Let me put that here.
79
And we can call it as a session service.
80
One second.
81
Session microservice.
82
Basically, the responsibility of session microservice is to connect with a DB.
83
And it will tell us which user is connected to which box or which API gateway.
84
So, maybe I think, yeah.
85
So say suppose when the message
86
when A wants to send a message to B it would first go to API Gateway
87
and then connect to this microservice
88
and this microservice will fetch you know the box number of the user B
89
and then the session microservice will connect back to API Gateway number 2
90
and from there it will go to API Gateway to be
91
and the protocol that we will be using here is web sockets maybe i can write that down real quick
92
so this is how i think i would be able to you know send
93
and receive messages and i think this solution is also pretty scalable how are we going to ensure
94
that is maybe the type of database that we will maintain here is maybe NoSQL database.
95
We can use that for scalability purposes as well.
96
Yeah, NoSQL like maybe DynamoDB.
97
So why would you use NoSQL here rather than a relational or SQL database?
98
As in when the number of users grows, we want the systems to scale, right?
99
And NoSQL are one of the most of the time why we use no sequels
100
because it helps us during scaling and
101
we don't have to stick to one schema the schema could be pretty dynamic
102
so yeah okay for scalability yeah it makes sense yeah
103
and maybe i think i can quickly write that format as well
104
so for now i'm just thinking of a key value pair so it could have something like um the key
105
and yeah so the key could be the you know um user
106
and the value could be the the box uh or the gateway
107
so by that by that way we'll be able to identify
108
which user is in which box so yeah so
109
that would only this this problem this particular design will solve the first requirement
110
but we still have not addressed the images thing
111
so usually for static content we have s3
112
that is the most preferred feature like you know most preferred option
113
so maybe i i think i would stick to that
114
so maybe i think when
115
when user wants to send a image right the only difference between text
116
and image here is um by the way we are not planning to store this uh text anyway right
117
because as soon as uh as soon as this um text
118
reaches the session microservice we are only going to get the user name
119
and their box number
120
and then send the text message as it is we don't
121
need to store this text anyway however in case of images i'm thinking would it make sense to store it um
122
we we can say that we don't want to store it just
123
because we don't store text
124
so we also don't want to store images for privacy yeah privacy purposes okay
125
so yeah in
126
that case then i think we are good with first requirement
127
maybe before we go to second requirement let's complete the third one So send, delivered and released.
128
Now, as soon as, you know, this user A has sent a message,
129
like as soon as a message is received by the session microservice, what we can also do is immediately send a response back,
130
like an acknowledgement to user a
131
that your message has been received by us this session microservice can do
132
that so maybe what we can also do is like let me put
133
that real quick okay and the text here would be a read um message um send acknowledgement
134
okay and maybe let me put some numbers as well
135
so basically the the number one here indicates uh the first part of it
136
because the message has been sent now once the session microservice has got the box number of the user b
137
and once it has sent that message to b
138
what we can do is it can send back an acknowledgement to session microservice
139
so maybe let me put it this way um api gateway
140
and from here to session microservice and let me add some numbers here
141
so this is more of a message received acknowledgement and
142
And what I can also do here is I can add another text in here.
143
It says message delivered acknowledgement.
144
Okay.
145
So just to summarize, user A has sent a message to APA Gateway.
146
APA Gateway would have communicated to session microservice.
147
And as soon as the session microservice has got a message from A, it will send a message sent acknowledgement.
148
That is point number one.
149
and session microservice would interact with DB.
150
It would get the box number and it knows exactly where user B is.
151
So it would go to API gateway 2 and API like you know this message will get redirected to B.
152
Now as soon as the message is you know received by B, B can again send a acknowledgement.
153
So that is point number 2 and as soon as session microservice gets that acknowledgement
154
it will send a message delivered acknowledgement to A.
155
So, you know, sent has been covered, delivered has been covered.
156
Now read receipt.
157
So the thing is, as soon as the user B opens the message, we can do exactly similar thing what we did for, you know, point number two.
158
So maybe I think I can draw another box in here.
159
So what happens here when user B reads the message?
160
yeah message read acknowledgement yeah
161
so now once the message has been read we need to you know somehow indicate
162
that to user a right
163
so what we can do is again we can use the
164
typical feature of what whatsapp is already averaging like maybe changing the color of the double ticks
165
so as soon as session microservice communicates that to a the the double ticks might be changed to double blue ticks.
166
So that would be point number four, I believe.
167
This is point number four.
168
Yeah, that makes sense.
169
Cool, yeah, that makes sense.
170
So this makes sense for peer-to-peer texts and images.
171
The texts and images are not stored.
172
They're just transmitted through the network.
173
We have sent, delivered, and read receipts.
174
Can we cover the group messages here?
175
So now let us talk about the group messaging.
176
So what essentially are we trying to achieve here is step number one, some user will create a group.
177
Step number two, the user will add some X number of people.
178
By the way, I forgot to ask this Kevin, how many, what is the maximum number of people who can be in the group?
179
yeah for simplicity let's say 10 people okay maybe I think I can write
180
that down real quick max 10 members yeah
181
and feel free to tell me
182
if in the future we want to change this to like 99
183
or 999 how that would change so maybe I think I can write
184
that down um should be scalable to more than 100 plus members okay got it
185
so maybe i'll think i'll start with 10 first
186
and then let's see how we can uh make it more scalable kevin so yeah
187
so maybe i'm just thinking of how i can tweak the existing design a bit to start supporting the group messaging.
188
So here if you see when a message was sent,
189
we had this key value pair with only one user and only one box.
190
So what if we have a list of a map?
191
So whenever a group will get created.
192
So what would happen is a list will get created with
193
them with a map having the key as the user and its associated box number.
194
So by that way, what would happen is whenever a message is sent,
195
the microservice or the messaging microservice will iterate over each of the elements in the list
196
or rather the the key value pair it will check the you know the the you know the user name
197
and its associated box number and it will exactly follow all the procedures
198
that we have created for one does that make sense kevin yep that makes sense How can we ensure scalability here?
199
Okay, the problem here is that when we are sending a message, we don't want to send the message in sequential order.
200
We can actually parallel, you know, parallelize things here.
201
We can ensure that, like, say suppose there are 100 members in the list, we can separate them in a batch of 10 or 20.
202
And we can have a main thread who will initiate a message, you know, who will initiate the group messaging, but the child thread will,
203
you know, equally distribute the number of items in the list and then send it to them parallel. By that way,
204
the other set of members in the list do not have to wait until the first set of members are done.
205
Got it.
206
Cool.
207
All right.
208
That takes our group messaging.
209
I have one more question before we wrap things up.
210
So you have user A here connected to API Gateway 1, you have user B connected to API Gateway 2.
211
If we have user C, where would user C be connected to?
212
Is it to their own API gateway or would they share a gateway?
213
No, they can share their gateway.
214
It's not mandatory that they need to have their own gateway can definitely share the gateways okay
215
and how would the how are the users assigned to the gateways is it uh randomly
216
or is there some structure there uh well for now i don't think we need any structure
217
but yeah they will be assigned randomly given okay got it
218
cool thanks roshan uh i think i understand where you're getting with this uh you somehow want to ensure
219
that not all the users end up in getting connected to one gateway right right
220
so i think yeah in order to solve
221
that problem what we can do is we can have a
222
limit on the number of users getting connected to a gateway
223
so by that as soon as that
224
that count reaches the max count we know
225
that okay the gateway is fully occupied now we have to move to the next gateway yeah
226
that makes sense um yeah thanks for clarifying
227
that point for me all right cool um thanks rishan for
228
your time i have a few pieces of pieces of feedback here
229
that i'd love to point out
230
and then i'd love it to turn it back to you
231
maybe you can give some advice to the audience as well yeah
232
so you did a really good job prioritizing the features in
233
the beginning figuring out what should be in the mvp you know whatsapp is a huge app
234
and you you were able to pick the ones that are most important to discuss for the MVP.
235
I think you also did a really good job of distinguishing some of the ambiguous parts of the question.
236
So, like sending and receiving messages, this could be anything from text to photos to videos to audio messages.
237
And you did a good job pointing out that ambiguity and helping to hone in the scope there around text and images.
238
And the last point I wanted to make is
239
that you did a really good job checking in with me and figuring out what questions I was trying to ask you, not only at the end there, but also in the beginning.
240
After you finished talking about sending and receiving messages, you didn't just move on to the next part of the question.
241
You paused and you asked me if I had any questions before moving on.
242
So I really appreciate your mock interview here.
243
And before we wrap things up, do you have any pieces of advice for the audience if they have their own system design interview?
244
yeah of course thank you kevin thank you for acknowledging this mock interview
245
and for people who are you know watching this video right
246
now um maybe i think i would just summarize of whatever
247
kevin has said just try to ask as many clarifying questions
248
that you have
249
because uh the only person to whom you can talk during the interview is your interviewer
250
so they are the ones who who will who are you who are here to help you out
251
so maybe you can ask as much clarifying questions
252
and whenever you are designing something so whatever is going through your mind
253
or whatever you are drawing just uh you know call it out loud
254
so that the interviewer knows what is going through your mind
255
and in case if you make any mistakes they will immediately stop you
256
or you know they might tell you to uh you know tweak your solution a bit
257
so yeah the key thing here is during the system design interview it's really really important
258
that you keep talking to your interviewer instead of you know just keeping it with yourself
259
so yeah makes sense thank you roshan thanks for the audience for watching
260
and good luck with your upcoming system design mock interview thanks
261
so much for watching don't forget to hit the like
262
and subscribe buttons below to let us know that this video is valuable for you.
263
And of course, check out hundreds more videos just like this at tryexponent.com.
264
Thanks for watching and good luck on your upcoming interview.
このレッスンについて
「System Design Mock Interview: Design WhatsApp」を使って、シャドーイングで英語を練習しましょう。
毎日15〜30分の練習で、IELTSスピーキングへの自信と実践的な英会話力が身につきます。
シャドーイングとは?英語上達に効果的な理由
シャドーイング(Shadowing)は、もともとプロの通訳者養成プログラムで開発された言語学習法で、多言語習得者として知られるDr. Alexander Arguelles によって広く普及されました。方法はシンプルですが非常に効果的:ネイティブスピーカーの英語を聞きながら、1〜2秒の遅延で声に出してすぐに繰り返す——まるで「影(shadow)」のように話者を追いかけます。文法ドリルや受動的なリスニングと異なり、シャドーイングは脳と口の筋肉が同時にリアルタイムで英語を処理・再現することを強制します。研究により、発音精度、抑揚、リズム、連音、リスニング力、そして会話の流暢さが大幅に向上することが確認されています。IELTSスピーキング対策や自然な英語コミュニケーションを目指す方に特におすすめです。