WHATSAPP System Design: Chat Messaging Systems for Interviews

  Рет қаралды 1,888,256

Gaurav Sen

Gaurav Sen

Күн бұрын

Пікірлер: 1 200
@gkcs
@gkcs 2 жыл бұрын
You can watch more system design videos here: interviewready.io
@architkapoor2503
@architkapoor2503 3 ай бұрын
Gaurav, there is one thing you missed discussing here. How is the service-to-service communication bidirectional here. Gateway and Sessions are also peer-to-peer. But perhaps, that can achieved via gRPC, or again through web-sockets, or asynchronously through an event bus. Great if you can clarify.
@vanhungbkcbg1
@vanhungbkcbg1 Ай бұрын
@@architkapoor2503 yeah, same from me, how to connect between gateway and session service in bidirectional? we are having multiple session service instance
@louis-ericsimard7659
@louis-ericsimard7659 5 жыл бұрын
Hi Gaurav, I have been a developer for 43 years and a system architect for 30. As a very experienced professional all I can say is: good work ! You are the real deal.
@gkcs
@gkcs 5 жыл бұрын
Thank you Louis! 😁
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
nice
@jawwadismail9419
@jawwadismail9419 4 жыл бұрын
@@BackToBackSWE r u real?
@umangmalhotra1222
@umangmalhotra1222 4 жыл бұрын
@@jawwadismail9419 Apparently Yes.
@judisjeevan4908
@judisjeevan4908 3 жыл бұрын
43 years..!!!! wtf..which language did you use..what kind of developer you have been..? World wide web just came into existence on 1989.
@ashishchourasia2830
@ashishchourasia2830 4 жыл бұрын
I don't know anything about system design or even what it is, yet I clicked the video and watched it full. Just understood everything, great teaching skills :)
@zippytyro
@zippytyro 5 жыл бұрын
I learn more on KZbin than school !!
@gkcs
@gkcs 5 жыл бұрын
Yey!
@dailyupdates7282
@dailyupdates7282 4 жыл бұрын
Learn from pune University It is very tough Very difficult subjects
@developerforcloud1478
@developerforcloud1478 4 жыл бұрын
Lately i started seeing so many posts all over saying "I learn more on youtube than school/college" No, need to demotivate young generation. They cannot teach you system design in school, this is specialization, not general subjects like PCM. Even in kinder garden, they teach kids about movement of hands to write, ultimately at home parents have to help kids in practice. We cannot expect nursey schools to teach kids writing.
@marioleon86
@marioleon86 4 жыл бұрын
That is a fact. I said the same 8 years ago in some countries the quality of contents in university is really poor, so when you discover youtube is a tool for learning you agree with this sentence
@headoverbars8750
@headoverbars8750 4 жыл бұрын
I would say by now that is true for me as well and I have a college education
@LauraSokolovska
@LauraSokolovska Ай бұрын
I've gone through all of your system design videos in preparation for my interview - I have found them so useful and easy to understand. Thanks for taking the time to put these together - your sense of humour is also great :D
@gkcs
@gkcs Ай бұрын
Thank you!
@asurakengan7173
@asurakengan7173 4 жыл бұрын
This was great. A minor nitpick, this is not what peer to peer means although it can be confusing. Peer to peer would mean apart from one time registration, the connection never touches your server and instead is established directly between 2 clients(friends on whatsapp). Also HTTP now has server push and whatsapp actually uses XMPP(slightly modified).
@StanleySathler
@StanleySathler 2 ай бұрын
@@asurakengan7173 Hi bud. If HTTP supports server push, does it mean we no longer need WebSockets out there?
@F1mus
@F1mus 4 жыл бұрын
Hey man, nice video, but there's a mistake: long polling is not polling every minute to get updates. Long polling is when you keep an HTTP request open (think: spinner in Chrome while the page is loading) forever, until the server decides to respond. This in effect makes it near real-time. It's one of the ways websockets work.
@puru.gupta901
@puru.gupta901 2 жыл бұрын
He meant Ajax polling probably, a lot of people refer to normal polling as long polling
@RaghvendraSinghIIITA
@RaghvendraSinghIIITA 2 жыл бұрын
I was going to mention the same. Major problem in long polling is that if the amount of data on server is too much then you need to keep creating the new paginated requests. But otherwise for small push messages long polling works well.
@shilashm5691
@shilashm5691 2 жыл бұрын
Yes, if he is worried about sending messages from server to client. He can use Server Side events
@kobew1351
@kobew1351 Жыл бұрын
long polling still requires client to send a request first, in this case websocket works the best. or a custom protocol on top of tcp also ok.
@joshuakoehler6457
@joshuakoehler6457 8 ай бұрын
Yep, he meant to say *short* polling.
@varunmahanot5766
@varunmahanot5766 4 жыл бұрын
occasions like good morning in India putting a lot of pressure on the servers🤣🤣
@gkcs
@gkcs 4 жыл бұрын
Hahaha!
@krithikasaikrishnan622
@krithikasaikrishnan622 4 жыл бұрын
You forgot about forwards that must be forwarded within 3 seconds :P
@reyazahmed3427
@reyazahmed3427 4 жыл бұрын
Hahahaha 🤣🤣
@rckstrbhushan
@rckstrbhushan 4 жыл бұрын
Hahaha
@TheRealKitWalker
@TheRealKitWalker 4 жыл бұрын
Bwahahahahaha!! 😂😂
@codewithidan
@codewithidan 8 ай бұрын
Hey, just wanted to clarify a bit about long polling. Long polling is actually more of a request from the client to the server and instead of the server returning a response immediately, the server is waiting for a change of some kind, and when there is a change, the server returns the response finally to the client. It was more common back in days before Websockets were introduced and adopted by browsers around 2011 roughly.
@mitgundigara466
@mitgundigara466 5 ай бұрын
I personally felt this is too abstract however it's good place to start. There are multiple scenarios which is not handled and it's assumed that it's happy case. I request to go slight deeper in each feature. The design explained in the video is "common sense", any software developer would have think of it. But I really request if you can answer some of the below questions which interviewer can ask us during the interview, if we would have explain the same. 1) You first explained we would store the mapping of each client to the gateway box. But there will be multiple clients will be connected to same gateway. let's say A is on gateway no 1 and B & C is on gateway no 2. then let's say A sends message to B. How would gateway-2 know where we need to route the message for B and C. My hunch is gateway will be storing this information. 2) I really wanted to understand when you will use Gateway vs Load Balancer. In your all videos somewhere you have used gateway and some places you used Load Balancer. You should explain why gateway over load balancer. 3) How are you maintaining the sequence of the message is not explained, this should be a very basic message. A and B can see different view of the message. 4) Why do we need message queue to store the failed message? IMO we should maintain 3 DBs. Sent, Delivered & NotDelivered with userId as key and Map. This will be easier. Whenever A sends message and chat server receives the message you can probably initiate two thread where one thread store message in NotDelivered table and the other thread calls SessionService to fetch the B's gateway box and send the message. Once B send acknowledgement then we can remove message from the NotDelivered and put in Delivered table. You can delete the message from the DB and archive the message in the low cost storage like S3 after 30 days or data is backup. Generally it happens every day night. The advantage of this is let's say B is offline then we do have store all the message that B got from all user's in B's contact list in Not Delivered table. Once B turns internet on their app will send long polling request and then can easily fetch all the data. Is this good design? I might be wrong but this is my thought. 5) You should mention what data we can cache and at which layer. 6) I think you should be more clear when your connection will be active, when it will not. I think if someone has opened whatsapp application or as long as it is there in app background stack the connection should be open. Once we remove the application from the background stack then connection will be lost. Once the connection is lost then your application will continue to send the long polling request until internet is on at certain interval. This kind of arch will have benefit of both websocket and long polling. Once internet is off it can't do even long polling. 7) What type of database and what are the data we are storing. I read in grokking system book that we can use Cassandra (wide column family) But I didn't understood why. So What I am suggesting if possible rather than making too much abstract information, make videos little more systematic it can help us. I think there are multiple counter questions interviewer can ask. why to choose this database over other. what data you would cache, which cache policy would you use (write back/around/through). 8) Here API gateway is just routing the chat server right? It's very difficult to put all the information together. But making video more systematic would certainly help me and others. You can have define structure while making system design video. at least following structure might help better. If you can even explain 5 mins for each of the section could be very helpful to all of us doing system design preparation. 1) Requirement 2) Define constraint/limitation/ data constraint like no of server, Incoming/outgoing data/memory storage 3) High level design for each feature 4) API Gateway/ Load Balancer 5) Data layer what data you will be storing 6) Caching 7) Sharding
@curs3m4rk
@curs3m4rk Ай бұрын
good observations
@revanshraman
@revanshraman Ай бұрын
@@mitgundigara466 yes, indeed. It is too high level. I wish the interviewers are satisfied with such explanations.
@wonderstruck.
@wonderstruck. 14 сағат бұрын
1. You’ll need some discovery service to assign clients to “gateways” and keep track. 2. Guessing he meant API gateways, which can contain a load balancer as well as whatever you want like a rate limiter. I’m not a fan of stickying clients to API gateways like he did, since that abuses what an API gateway is. 3. Maintaining sequence is complex yet crucial. Each message will contain the timestamp, and ideally the message ID should be sortable by sequence or time for fast indexing. 4. Hitting DB is slow, so you likely want a single DB system for all messages. When the recipient receives the message, their sent acknowledgement can be stored as a flag within that DB or a separate smaller one. When the recipient comes back online, they can ask for all messages since last online. 6. If the connection is dropped, the client can’t receive the server’s messages, no matter the protocol. 7. Cassandra is a NoSQL wide-column data store, which is basically a flexible key-key-value store. NoSQL is typically preferred in chat apps because they must store immense amounts of distributed data (run a quick calculation to confirm) that prioritizes availability over consistency. 8. API gateway here is not actually routing anything. The design assumes clients are already routed to the proper API gateways, which are doubling as the chat servers.
@inasuma8180
@inasuma8180 2 жыл бұрын
i'm interviewing this week for systems design for the first time in my 6 year career. this isn't part of my job. but here i am, learning an irrelevant (to me anyway) skill to be better at tech interviews. thanks for sharing!
@maggiemu4650
@maggiemu4650 4 жыл бұрын
I really amazed by how good you are at explaining complex concept in such a simple way. I can just keep watching all your video. Great job! ❤️
@gkcs
@gkcs 4 жыл бұрын
Thanks!
@kartik180rajesh1
@kartik180rajesh1 4 жыл бұрын
You're really underrated in the developer circle. People need to watch all this a lot more than programming basics.
@varunmanjunath6204
@varunmanjunath6204 3 жыл бұрын
He doesn't have enough videos .plus partial knowledge. Although he us very good
@abhisheknair_music
@abhisheknair_music 4 жыл бұрын
These videos clearly shows how far away are university syllabuses from the real-world problems
@ImEli2215
@ImEli2215 4 ай бұрын
4 years ago and your comment is still valid today.
@chrisburd9751
@chrisburd9751 4 жыл бұрын
Excellent video - as a former data architect from JP Morgan Chase looking to expand their knowledge for social applications - excellent.
@gkcs
@gkcs 4 жыл бұрын
Thank you 😁
@dieddzaandam
@dieddzaandam 2 жыл бұрын
Great video! About the 'last seen' feature: I don't think the Last Seen is based on the last activity (e.g. sending a chat) but rather when the user closed the connection to whatsapp. So in my opinion, as soon as 1) the network is interrupted or 2) the user closes the application, the 'last seen' should be updated.
@shenth27
@shenth27 2 жыл бұрын
It should be updated as well when the user comes online and every 10 or 15 secs. So simple health probing from the app to the gateway should work
@GaneshAcharyaAnEngineer
@GaneshAcharyaAnEngineer 5 жыл бұрын
Great video, this kind of stuff is not easy to learn and not enough resources out to explain. Thank you for your great efforts
@gkcs
@gkcs 5 жыл бұрын
Glad to help 😁
@kaushalkishore9792
@kaushalkishore9792 3 жыл бұрын
Good work. There are a few important topics worth covering though. 1. What happens to a message sent to an offline user. 2. What choices of storage do we have ? 3. What kind of load + image/video messages ?
@unmeshchougule5666
@unmeshchougule5666 2 жыл бұрын
I believe the 1st point is already covered by him, the message is stored in queue/db.
@aditya.chandel
@aditya.chandel 2 жыл бұрын
1. All messages are stored in the database. Once the receiver comes online, receiver's client application checks with the chat server if the receiver has any pending messages that he/she should receive. If there are, then those messages are delivered to the user's client application via websocket. 2. A wide column database like HBase will be good for this use-case (i.e. lots of small messages with very low relation). 3. I didn't understand what you mean here. For storing images and videos we should make use of CDNs.
@kobew1351
@kobew1351 Жыл бұрын
for no.1 , the answer depends on how you "persist" the messages. In case of queues, a pull request can suffice as all messages in the queues are "pending to be delivered". The trouble (if it's indeed a trouble) would be how you should manage such a big amount of queues (e.g. one queue per friend pair). however if messages are stored in db, there has to be information like "what's the oldest message that client A hasn't received yet ?". this is so that message order can be retained, And more questions come like how sharding/partitioning is done...etc
@hridayeshsharma1058
@hridayeshsharma1058 2 жыл бұрын
12:43 Now I understand why my gf would still show online for sometime even after we have sent goodnight messages. 😂😂
@adamhughes9938
@adamhughes9938 4 жыл бұрын
interview: "ya I'd have a lst seen microservice". Reality: "ok just add that as a function in your monolith we don't have time for a new service"
@gkcs
@gkcs 4 жыл бұрын
Exactly! I've seen this happen in real life 🙈😂
@ankushmaheshwari
@ankushmaheshwari 2 жыл бұрын
Good video! Would have liked even more if you had included following points as well becuase I felt lost there. 1. How does the gateway manage the TCP connections for each user? Is it in memory or in external store? What happens to the clients connection and messages when the gateway goes down? 2. How does the session service talks to gateway? Is it using RPC or message passing etc?
@ankitjain6787
@ankitjain6787 2 жыл бұрын
Same question
@aditya.chandel
@aditya.chandel 2 жыл бұрын
1. A map of userId and its corresponding connection object is stored in the chat server's (gateway) memory/RAM. If a gateway goes down then all of the online clients connected to the effected gateway will loose their websocket connection, but quickly they will make a new connection to the another functioning gateway.
@yaraye5397
@yaraye5397 4 жыл бұрын
One thing I really like about your video is that you always tried to explain things from the client side, which makes it highly understandable for us as clients in our daily life. Thanks for your video!
@svgi1210
@svgi1210 5 жыл бұрын
Age and experience doesn't matter to achieve, you proved it bro
@kushagrak960
@kushagrak960 4 жыл бұрын
KZbin recommendation, thank you so much for this gem
@nootics
@nootics 5 жыл бұрын
I'm happy that I know what the most important part of programing is which is what you just showed, and not the writing part. It's the pen and paper part that matters. This really satisfies my superiority complex
@gkcs
@gkcs 5 жыл бұрын
Lol 😛
@iitgupta2010
@iitgupta2010 5 жыл бұрын
Hi Gaurav, Great video few suggestions; 1. Keeping too many gateway would kill you latency [or may be I'm overthinking] but if we have some services which basically authenticate and establish the web socket connection, there after other services which work as mediator and communicate back-n-forth with client then we can simply reduce the number of gateway we need. [ essentially the gate would do this, but we don't need as many gateway as client are there; imagine 50 million clients at a time on whatsApp] 2. We should not stick with only push mechanism, where you said that "server will keep trying to to send the message to B" instead here it should be pull technique should be use. What I. mean is, once a user successfully establish the connection to Chat server, it AsK "do you any thing for me" and server response back (through queue technique so that message order are persisted ) and then after its all push technique until same thing happen for different user This way we keep server doing less and redundant work, to keep checking. Again think about 50 million user there. on Percent, 0.01% [5K users at least] of them chat each other. then there would be very high number of user might not be online, and for that server keep trying. 3. We don't need to keep checking in server database for where the user is, we should cache them. That may be 50 million entries at max at a time. As soon as the user goes off, remove him [ make sure the app should send the right information, don't send that when user just stack the application and will come back in a minute or so. it should be only when there is no internet connected.] In the essence, the connection would be of two types {1. active 2. ideal- help to build last seen too} when connection is ideal, we can utilise the connection for other chat and as soon as the user receive a message then we'll either create a new (if that connection goes off) or use the same. This is trade off you see, making a new connection is costly but keeping lot of the ideal is also poor. incase , if we mark offline the user who is connected to internet, we'll lost real time communication.
@shivujagga
@shivujagga 2 жыл бұрын
For point 2 - Notification service and chat-service will be push, whereas, first time client connection would be pull.
@shubhimohta8488
@shubhimohta8488 2 жыл бұрын
If first time client connection is pull, will that not create an overhead as client can connect disconnect too frequently due to unstable internet connection or is that acceptable?
@kobew1351
@kobew1351 Жыл бұрын
no,2 makes sense when queues are in place or messages themselvs are persisted somewhere in database (so that a select can be performed). for no.1 a server box likely can only handle a few millions at most, so for whatsapp scale, several tens of gateways will be needed.
@kobew1351
@kobew1351 Жыл бұрын
@@shubhimohta8488 that should be fine, 1. for most users, connections are there for some time. 2. the payload over a pull is generally not very big and is acceptable .
@shubham.6059
@shubham.6059 3 ай бұрын
Came here for revision observed that the video has dual audio option now as Hindi and English. Great work!
@gkcs
@gkcs 3 ай бұрын
Thank you!
@clinton11994
@clinton11994 4 жыл бұрын
I watched other videos on messaging systems and this video has a very detailed approach, I was hunting for videos just to know how to have multiple servers for socket processes when the client is a mobile app and I feel this video has helped me a lot with that.
@theverybestdev
@theverybestdev 4 жыл бұрын
@@SK18459 you both didn't post anything yet
@rajchoudhary4349
@rajchoudhary4349 4 жыл бұрын
well narrated and presented. never knew whatsapp and tinder has so much thing at backend. interesting when you ask someone for a coffee. and she accepts the coffee invitation. both are important sugar in coffee and web sockets and the micro services. lol. Hats off. truly brilliant .
@itssantanu
@itssantanu 2 жыл бұрын
Hi Gaurav , fantastic architecture design and explanation . But, for group massaging, "session" micro service is calling another "Group" micro service , which is kind of http chaining and potentially example of anti-pattern. Can't we implement messaging mechanism like "distributed Kafka" to make it more decoupled. Just a thought of mine. Let me know your take on this.
@SreekarAnugu
@SreekarAnugu 3 жыл бұрын
I only had one or two serious system design interviews till now and the face expressions of the interviewer really put you off sometimes. I have never seen anyone explaining system design like this, it's good to know that I'm not very far off.
@hemantjain6016
@hemantjain6016 5 жыл бұрын
Great Video, Really liked this one...!!! Just wanted to ask that for the last seen timestamp wouldn't it be better if the client sends a request(Or should I say message!) to the server when the user exits the messaging app(maybe when he exits the main app activity)., Wouldn't it save a lot of overhead for the last seen timestamp(Not taking into consideration the online stamp)?
@gkcs
@gkcs 5 жыл бұрын
That's a really good idea...it should save a lot of bandwidth in general. It would also be quite accurate. Nice point!
@hemantjain6016
@hemantjain6016 5 жыл бұрын
@@gkcs I didn't know anything about system design until I started watching your videos. Starting to get interested in system design because of your effort.
@hiteshgoyal1620
@hiteshgoyal1620 5 жыл бұрын
Nice idea..well thought..!!
@mrgotu
@mrgotu 5 жыл бұрын
There might be chance that user lost internet connectivity before exiting app
@toddmoore112
@toddmoore112 5 жыл бұрын
why don't you create one watshapp like app when you know the design and overtake it ?
@cmdaltctr
@cmdaltctr 2 жыл бұрын
I found your channel randomly and I was so grateful, thank you so much.
@samyakjain6698
@samyakjain6698 3 жыл бұрын
You did a great job of listing the microservices and interaction between them. One thing which I would like to know more is the database design. How do we maintain a system with so many chats each with thousands of messages growing over time.
@DebajyotiDev
@DebajyotiDev 2 жыл бұрын
Once WhatsApp successfully sends a message to B, they will delete it from their end and save whatever to your GDrive / iCloud. They do not store billions of messages. N.B: I don’t work in whatsapp.
@aditya.chandel
@aditya.chandel 2 жыл бұрын
A moderately sized server can maintain around 25k-35k simultaneous TCP connections, so a single server can serve about 25k-35k users (assuming that every user uses just one client). And to handle the ever-growing user base there no option other than adding more physical servers.
@balaramkantipudi3728
@balaramkantipudi3728 5 жыл бұрын
With this video I got interest in the topic of system design completely,even I don't know what it was before...
@gkcs
@gkcs 5 жыл бұрын
Glad to hear that!
@TheOriginalDonPablo
@TheOriginalDonPablo 5 жыл бұрын
I have hit the like button. I have subscribed. You are awesome!. So happy I found your channel.
@miafar7212
@miafar7212 2 жыл бұрын
I'm from a non technical background and this video was super helpful and clear. On a side note, "Check with your doctor if group messaging is right for you" - hilarious :'D
@aww_rijit
@aww_rijit 4 жыл бұрын
How does Telegram can function having lakhs of members in each group?
@therealb888
@therealb888 5 жыл бұрын
Finally an Indian tech/engineering related youtuber who can speak English! But more importantly a very well explained video. Keep it up!
@gkcs
@gkcs 5 жыл бұрын
That's quite a demeaning comment b888, considering English is rarely our first language. Thanks for the compliment though 🙂
@ashishupadhyay3368
@ashishupadhyay3368 5 жыл бұрын
I wish there was a 100 like button for the video, thanks Gaurav. You've been an inspiration for me in cracking Amazon in 2018 placements. :)
@gkcs
@gkcs 5 жыл бұрын
Congratulations Ashish! Thanks for the feedback 😎 P.S. You could be a channel member now if you like 😉
@gkcs
@gkcs 5 жыл бұрын
It's explained by me here :D gkcsblog.wordpress.com/2018/11/06/gaurav-sen-channel-memberships/
@Gimmiyimmy
@Gimmiyimmy 5 жыл бұрын
Nice explanation but I have some queries.. 1. Gateway means API Gateway or something else ? 2. Is this system cost effective. ? 3. How do we maintain session in Session service. Chat service works in stateless environment ? 4. Can you share complete UML of this design ?
@varungupta2045
@varungupta2045 2 жыл бұрын
A critical piece that I feel is missing here is delivery of messages when the user is offline. You might not have an active connection to all users at all but you do need to deliver all the messages that were sent to them once they are connected.
@beibit-ds
@beibit-ds 2 жыл бұрын
maybe store the message in the db, and when client status changes retry
@paulhatcher951
@paulhatcher951 Жыл бұрын
+1 I was asked this question in an interview a while back. First question when I'd done simple send receive was "What If user B is offline and not in session".
@shreyasns1
@shreyasns1 2 жыл бұрын
Hello Gaurav, Great video. You did not explain how the messages are stored in database, what DB to chose and how to handle retries in case offline user. So here are my questions to you. 1. How are you storing the 1:1 messages in the DB? and How do you retry if the user if offline? 2. How are you storing the sequence of the messages to shown the right order for the client side? 3. How are you storing group messages in DB and the same questions like above.
@ammarshareef462
@ammarshareef462 5 жыл бұрын
Yet another great video on system design! Keep up the good work, also now I can watch in 1080p YAY!
@gkcs
@gkcs 5 жыл бұрын
Yey!
@venkatasundararaman
@venkatasundararaman 2 жыл бұрын
Wonderful video which covers all the technical concepts involved. This is incomplete without any resource estimates like storage/bw and what kind of stores to use like a Key/Value store like etcd will work etc.
@jonahlin6399
@jonahlin6399 4 жыл бұрын
Hey Gaurav - thanks so much for putting up such quality content! You're truly a wizard.. I've been learning so much about system design purely from your videos. I was wondering though, where exactly should I be placing the message queue in this example? Would it be after the sessions microservice confirms with the group-service which users are part of the specific group that the message is directed towards?
@saifrnaik
@saifrnaik 4 жыл бұрын
Hi Gaurav, thank you so much for these videos. You're the real deal :-) I was trying to dig in deeper (apologies if these are trivial queries). I was trying to understand the handshake between your gateway and the Sessions Server. Let's say Person A is chatting with Person B. Step 1: Person A hits the gateway (a reverse proxy) that will do most of the heavy lifting (auth, TLS termination etc) and detect the websocket handshake. Step 2: The gateway forwards the request to your Sessions Server(which is your websocket server) Step 3: The Sessions server receives the request and sends back a reponse HTTP/1.1 101 Switching Protocols Upgrade: websocket. My understanding goes a bit gray from here (please also correct if something is a miss in the above three steps) Do all further communications between A and the the proxy now use websockets and then the same protocol to hit the sessions server? Hence, the client calls something like - wss://www.whatsapp.com/socketserver and hits the reverse proxy, and that forwards the request to the sessions server? or am i missing something. If this is in an application like slack... then it would switch between wss and http based on the service it's trying to invoke (say chatting vs creating a channel)
@saifrnaik
@saifrnaik 4 жыл бұрын
Most of the answers are in the tinder video kzbin.info/www/bejne/qp_Hq3-wo92kapI Not deleting the comment in case someone has similar questions
@arturkomyakov7729
@arturkomyakov7729 4 жыл бұрын
QQ: if you try to keep gateways light and delegating all complicated logic and memory usage to other services, you will still have to scale them per number of users/messages. So either there should be some discussion around batching between gateway and sessions or you can just scale the number of gateways and keep some logic there (for example parsing).
@dalitex-c4885
@dalitex-c4885 5 жыл бұрын
HTTP Long polling is NOT polling. It is just Client sends request and Server only responds when they have any messages and client initiates fresh request as part of ACK to previous message. Web sockets are persistent connection mainly meant for real-time communications.
@BiancaAguglia
@BiancaAguglia 5 жыл бұрын
Yours are some of the most helpful videos I've come across. Thank you for doing such a wonderful job.
@gkcs
@gkcs 5 жыл бұрын
Thank you!
@KiprutoR
@KiprutoR 8 ай бұрын
KZbin is such an amazing platform. Thanks for the video
@Gualcm
@Gualcm 5 жыл бұрын
I love you man, I used this to get an offer in my interview today.
@gkcs
@gkcs 5 жыл бұрын
Congratulations!
@vikrant4666
@vikrant4666 5 жыл бұрын
u wrote same thing under facebook system design video
@dasamlan9874
@dasamlan9874 4 жыл бұрын
@@vikrant4666 whatsapp is owned by fb, right?
@alsan378
@alsan378 Жыл бұрын
Thank you Gaurav, you cant imagine how much this video helped me last year.
@gkcs
@gkcs Жыл бұрын
Thanks Alvaro!
@Cyborg1170
@Cyborg1170 2 жыл бұрын
Thank you Sir. I moved from India to San Antonio as new college grad. Amazon offering me 500K per year. Excited. Thanks for video.
@yuvrajgupta3092
@yuvrajgupta3092 3 жыл бұрын
Today,I found it as KZbin recommendation.It really a grate video👍👍. Bhaiya please make the same series for the zomato like app..
@yangangye5819
@yangangye5819 4 жыл бұрын
Thanks for your effort! It's great to learn lots of things from your video. But I still have a question after watching this video. Why consistent hashing can help to reduce duplicate information (on 20:57 explaining the group service)? Isn't it just a way of knowing which record should be found on which server?
@phildinh852
@phildinh852 2 жыл бұрын
Probably for vertically partitioning table?
@adambright5416
@adambright5416 2 жыл бұрын
And here I am, looking at some guy teaching IT things I should probably know already... Thanks :D
@PradeepMahato007
@PradeepMahato007 4 жыл бұрын
Great Video, Helpful !! I feel the 'Last Seen' feature could be improved (based on the steps described in the video). The only shortcoming I see with the current approach is, 'What if the user replies a message (i.e an action taken by the user) from the notification directly without opening the application !!'. One approach could be if a flag is sent in the request { 'fromNotif': true } that could be used to determine to decide if the Last_Seen table needs to be updated. Another could be to use the WebSocket connection itself and using the disconnect callback (once the user gets out of the application, the WebSocket connection can be disconnected). Push Notification can be used to update the message count once the user is outside an application and more approaches could be formulated further. Nevertheless, your video does help for beginners in system design.👍
@vedant9887626061
@vedant9887626061 4 жыл бұрын
Nice video. Just had few questions . 1. How mobile A will know to connect to which gateway , think there has to be something in between mobile and gateway such that it can balance the load on gateway's . Also once a tcp connection is made then it can directly connect to its respective gateway .
@kushal1
@kushal1 5 жыл бұрын
Would be great if you have another video to break it down feature wise and why these were the final choices in terms of languages/tools/concepts used to implement all this. Maybe helpful for people coming from non-backend development
@gkcs
@gkcs 5 жыл бұрын
Have a look at the playlist mentioned in the description. Each feature is explained with alternatives.
@kushal1
@kushal1 5 жыл бұрын
@@gkcs Concepts of system design are in place. I saw that playlist. What I mean is if one has to implement this architecture. We have to think which features in in what languages. Should this part be in Python/Node. Shall we consider gateway to database communication in Golang routines or Java etc... kind of questions.
@gkcs
@gkcs 5 жыл бұрын
@@kushal1 Aren't those questions, too vague? I have never seen a system design interviewer ask them. At the end of the day, I may like everything implemented in binary opcodes for efficiency, but I have to perform as per the deadlines set by the product.
@kushal1
@kushal1 5 жыл бұрын
@@gkcsWow! Someone is rude now. I never mentioned from interview perspective. It was a suggestion to dig into tech stack and make another video maybe. Thanks anyway for your content.
@gkcs
@gkcs 5 жыл бұрын
@@kushal1 Sorry if I sounded rude, it wasn't my intention in the slightest. Replying to comments all day has taken off my tact perhaps. I'll look into this a little more and get back to you. Digging into the tech stack will certainly be of use :)
@mightytechno
@mightytechno 3 жыл бұрын
One of the best channel to learn system design. Good work.
@vinayagamnatarajan
@vinayagamnatarajan 3 жыл бұрын
Hi @Gaurav Sen This is very good session. Just wanted to ask, If use MQTT instead of web sockets. Does the native support for publish/subscribe would bring any advantage for the chat application?
@lunaRdeltaY
@lunaRdeltaY Жыл бұрын
same question here
@mohammedsharikuzama5518
@mohammedsharikuzama5518 5 жыл бұрын
I visited the Uber Hyderabad office the other day for an event. Thought of meeting you. Never had a chance to reach out hope I will meet you someday. Thanks a lot for your amazing videos man. They help a lot.
@gkcs
@gkcs 5 жыл бұрын
Thanks Sharik!
@harsh_garg
@harsh_garg 4 ай бұрын
Hi, you mentioned how we determine online status, what if the user opened the whatsapp but hasn't done any activity post that on whatsapp, just sitting idle [how we determine online status as per the discussion], but still online.
@wonderstruck.
@wonderstruck. 15 сағат бұрын
We could open a new WebSocket connection to track online status. Client sends heartbeats to the server letting it know it’s still online, and server writes this to a DB for other clients to access. If client disconnects, server stops receiving heartbeats and knows to mark client as offline.
@mulllhausen
@mulllhausen 3 жыл бұрын
7:40 what you describe here is just regular polling. long polling does indeed operate on a near real-time basis - the connection is held open and the server can respond to the client in real time. the difference between long polling and web sockets is that with long polling you have to drop and re-establish the connection after the client receives data from the server, since this terminates the connection. whereas a web socket stays open indefinitely.
@Frigno
@Frigno 5 жыл бұрын
I'm not into programming, though I appreciated this video. I'd really like you to publish a similar lesson, but for Telegram. Thanks in advance, and keep up the good work.
@gkcs
@gkcs 5 жыл бұрын
I'll check out Telegram and see if I can make time for it 🙂
@suthan2003
@suthan2003 4 жыл бұрын
I really like the way he smiles and teaches. I know nothing about systems but that smile alone made me comfortable to watch the video......keep the same passion my friend......
@jayeshudhani99
@jayeshudhani99 3 жыл бұрын
Hi Gaurav, I have one query : How will database keep re-trying? Should we use message queue here instead of DB?
@Arghamaz
@Arghamaz 5 жыл бұрын
Brilliant communication skills and very good English accent... great job keep it up
@大盗江南
@大盗江南 5 жыл бұрын
This video is awesome! Hoping I can find a good job after months of watching ur videos again and again! Thx! U r amazing!
@gkcs
@gkcs 5 жыл бұрын
Thank you!
@shobhitsingh7735
@shobhitsingh7735 3 жыл бұрын
Have you got the job?
@大盗江南
@大盗江南 3 жыл бұрын
@@shobhitsingh7735 i got other thing in priority last year. but now i will have microsoft interview for sde2 in 1/2 weeks......... jesus.....so now i am reviewing everything...
@mahendramungamuru9500
@mahendramungamuru9500 6 ай бұрын
@@大盗江南 got placed buddy ?
@lloydlasrado
@lloydlasrado 2 жыл бұрын
Wow Gaurav you should tap your back for being so popular. Lyft HR in USA forwarded this link of yours as an example to get acquittance to System Design interviews. Kudos on this achievement.
@gkcs
@gkcs 2 жыл бұрын
Yeah!
@lloydlasrado
@lloydlasrado 2 жыл бұрын
@@gkcs Quit your Tech job and become professor in IIT. Students need a positive smiling professor like you :)
@rishabhdixit4214
@rishabhdixit4214 5 жыл бұрын
Again a masterpiece...nice work Gaurav 😊😊...can you create a playlist for OOPS and Design pattern?..thanks in advance
@gkcs
@gkcs 5 жыл бұрын
Thank you! I have them on my list. Going as per the polls now :D
@ankitjain6787
@ankitjain6787 2 жыл бұрын
@@gkcs voting for design patterns
@javohir307
@javohir307 4 жыл бұрын
Finally found this kind of tutorials. Thank you very much very good explanation. But one thing i have not understood is Gateway. I know what does it do but dont know what is it :)
@gkcs
@gkcs 4 жыл бұрын
Try the microservices tutorial video on the channel. It talks about the gateway service with code :)
@charlieporciuncula3300
@charlieporciuncula3300 4 жыл бұрын
Dude! As a beginner, I'm mind blown! Subscribed!
@SahilPatel-jv1fw
@SahilPatel-jv1fw 2 жыл бұрын
Bhaiya ye video ne meri placement lagva di, thank you so much
@dinotumu
@dinotumu 4 жыл бұрын
This is just that amazing video I was looking for. Regarding de-priotising, there is this feature called broadcast messages in whatsapp which I presume is used to send messages like "happy new year" etc. Can you tell me if I am right?
@rekhahindwar2255
@rekhahindwar2255 Ай бұрын
I think we can design a chat system using the topic subscription method the topic could be named using group ID and in the case of simple chat, we can take the topic by joining the ID of two chat users. Also, for the last seen activity, we can trigger the event when the user closes the WhatsApp app. So we can also design a WhatsApp app by triggering events and topic subscriptions method.
@VenturesWithVenk
@VenturesWithVenk 5 жыл бұрын
Nice Video! Regarding authentication though, most of the applications in the real world rely on client directly calling the authentication service, get a valid token(JWT?) which can be used by other services before responding. This avoids the extra parsing/un-parsing hop between gateway and sessions service.
@msms3260
@msms3260 4 жыл бұрын
He is a master of block diagrams
@mervekaymak1703
@mervekaymak1703 5 жыл бұрын
Great!Thank you. Next topic should be "Service discovery"
@nitinagarwal4068
@nitinagarwal4068 4 жыл бұрын
Hey Gaurav, 1) For first feature, why you are re-directing whole data traffic through session service ? Gateways can find the mapping through session service, and send one gateway can send data directly to other Gateway. 2) Why MQTT is not preferred over Web-socket ?
@ankitmaurya3591
@ankitmaurya3591 5 жыл бұрын
After watching this.... I am highly interested in system design
@MagicWeiCN
@MagicWeiCN 4 жыл бұрын
nice video, however, I want to point out that the WebSocket is not for peer to peer communication, certainly, you can use it to achieve the goal, but it is c/s model rather than p2p.
@susheelmadwani
@susheelmadwani 5 жыл бұрын
@Gaurav: Man I envy you, you are a gem explaining the complex things. I have 1 basic question: As we are using websockets for communication, don't we require not million but thousands of servers to connect billions of users ?? If you can help me understand this part can help a lot.
@deepbrar6152
@deepbrar6152 4 жыл бұрын
I don't think WhatsApp uses WebSockets. A traditional method to scale this kind of application is using telecom technologies such as Jabber or core ErLang.
@bhavikgarg5662
@bhavikgarg5662 4 жыл бұрын
@@deepbrar6152 Yes Whatsapp uses EJabbered which is implemented in ErLang
@adamhughes9938
@adamhughes9938 4 жыл бұрын
I also am confused here. If A and B are both connected to the server, is the websocket connection direct between A and B or is it still going through the server?
@nehadalvi409
@nehadalvi409 4 жыл бұрын
@@adamhughes9938 I think the websocket connection is between both A and the server and also between B and the server.
@alibarznji2000
@alibarznji2000 2 жыл бұрын
First minute into the video, already subbed and clicked the bell icon
@RicardoSilvaTripcall
@RicardoSilvaTripcall 5 жыл бұрын
Amazing content, kudos from Brazil !!!
@gkcs
@gkcs 5 жыл бұрын
Thank you!
@dev9033
@dev9033 2 жыл бұрын
thanks for making our life more simple with release this, so we can skip CRUD and start build whatsapp for first implementation
@vijaybabaria3253
@vijaybabaria3253 4 жыл бұрын
thanks for the amazing contents, brother.. another topic suggestion is system design for payment processing system like venmo or paypal
@vaddiparthivenkatamuralikr8334
@vaddiparthivenkatamuralikr8334 5 жыл бұрын
I have been following your videos but never commented before. They contain very intellectual stuff mostly, could I request you to please concentrate on below average guys like me who can understand better with few examples. You are a great narrator.
@gkcs
@gkcs 5 жыл бұрын
Sure Vaddiparthi, thanks!
@Gondkar86
@Gondkar86 5 жыл бұрын
Hey Gaurav, excellent video. Learning a lot from your system design videos. However, i had a question related to last seen/online feature. Wouldn't something like hearbeat mechanism be useful for this to update the timestamp of the user?
@gkcs
@gkcs 5 жыл бұрын
Thanks! Heartbeat for everyone would be too expensive. Especially as many users are active for a short period of time. 🙂
@aditya.chandel
@aditya.chandel 2 жыл бұрын
A better approach would be to log the timestamp at which the user last interacted with the client application (android, ios, etc).
@rahulsharma5030
@rahulsharma5030 3 жыл бұрын
thanks for nice video. 1.Can you tell me @22:24, why do we need message queues here? The message queues it seems between session and group service because actual message is sent by session service. So session service is asking for synchronous response to its request.Give me users for this groupID, why do we need to push this request message to message queue? 2. Also, how does client knows which api gateway to connect?They must be hitting some loadbalancer, which will balance connections across load api gateway?
@NeemiasJunior1
@NeemiasJunior1 4 жыл бұрын
7:15 "This can't be done with HTTP". Actually this is wrong, it's only true for HTTP1, but it is possible using HTTP2 using a mechanism called server push: en.wikipedia.org/wiki/HTTP/2_Server_Push
@abhisheksitar
@abhisheksitar 2 жыл бұрын
Great system design discussion, thank you Gaurav!
@abhijit-sarkar
@abhijit-sarkar Жыл бұрын
Having sat in FAANG interviews both as an interviewer and as a candidate, I can say that this is not going to hold up for someone interviewing for a senior position.If you have less than 5-7 years of experience, you may get away with some hand waving, but for 10+ years, we want to see more depth. Some of the users have already brought up questions like delivery of offline messages, which is a basic feature missing. Apart from that, there are some crucial things missing in this video: 1. **API**: You want to discuss basic API (like REST) design, verbs supported, payload etc. You don't need to spend 30 minutes creating a JSON schema, but mention the endpoints and what's being sent and received. This matters for latency, and for some advanced things like security, API versioning, bandwidth usage etc. 2. **Back of the envelope calculations**: This is important for scalability, availability and storage. How many daily active users? Is there a limit to the message size? (you probably don't want people dropping 5 GB pirated movies in a group). How many gateway servers do you need? How long are the messages stored? Do you need to shard the DB? What is your partition key, and how do you deal with hot partitions? 3. Most importantly, **offer alternative design options and discuss trade offs**. If you can only talk about one thing, then you most likely learned it from some blog/video/whatever. There's no perfect solution in system design, so, we want to know you can think out of the box, and why you are choosing to go one way or the other.
@YeetYeetYe
@YeetYeetYe 11 ай бұрын
Yeah there is A LOT missing here. Like.. A LOT
@anchalsharma0843
@anchalsharma0843 6 ай бұрын
thanx Abhijit! This comments gives me an idea of what else to think of rather than taking a fixed approach. If you could suggest some resources/or just general advice to me for preparing sys design, i'd really appreciate it. (I've 2 yrs of exp )
@karthicktvm
@karthicktvm 3 жыл бұрын
One more great video. I have query on introducing a parser service after API gateway. 1. Isn't API gateway supposed to be the only point of entry which further routes the transaction to various other services? 2. By introducing a parser service and all unparsing are taken care by it, should I consider the service as another gateway in addition to API gateway? 3. In this case, what are the typical services expected out of API gateway before the parser could further identify the message and route it to other services?
@shoban2090
@shoban2090 5 жыл бұрын
Your system design videos are excellent! very easy to understand when comparing to others. It would be great if you explain multiple recursion(more than one recursive call in a function). I've reffered some online resources but It looks more confusing. I know you could make it easy to understand :)
@gkcs
@gkcs 5 жыл бұрын
I'll add this to my list of videos to do 😁
@shoban2090
@shoban2090 5 жыл бұрын
Wow! Thanks Gaurav 😊
@aqualung1466
@aqualung1466 2 жыл бұрын
Great video Guarav, thank you.
@junko78
@junko78 4 жыл бұрын
Hi Gaurav!! Thank you for educating me with all your awesome videos! I have a request for a video! Can you talk about building a cloud-native system? Things like what's the benefit of using cloud and where we should be careful when designing a system. Also, as Hadoop is dying recently, I feel like some of the solutions are out-dated. For example, HDFS and HBase won't be a good option anymore as they require Hadoop cluster.
@intekhab3425
@intekhab3425 Жыл бұрын
This didn’t age well
@VivekSingh-es1zr
@VivekSingh-es1zr 3 жыл бұрын
Thanks for this awesome video. This Gateway we are talking about here is some sort of router like we have in networks or its an application deployed on some server?
@kaspatro749
@kaspatro749 4 жыл бұрын
Hi Gaurav, Thank you for the informative video! I have a question or clarification, are you referring the gateway as a load balancer? Or different services (microservice)? At first glance I think it would make sense that it's a load balancer but just wanted to confirm because it seems more like a "server" and scaled horizontally. It would be helpful if you could reply. Thank you :)
@gkcs
@gkcs 4 жыл бұрын
It has a snapshot of the load balancer's "allocation".
@MrGPromo
@MrGPromo 4 жыл бұрын
@@gkcs first of all its a great video to explain the architecture in most simplistic way, i am having couple of comments / questions. As whats app is most popular chat application in the world, i believe it's worth to explain the mechanism to determine which gateway client should connect to? Also, please correct me if i am wrong, as per the architecture explained, Session service is having responsibility of managing receivers address (gateway) as well as sending the message to gateway so that gateway can forward the message to receiver? If that's correct, what will be the protocol of this communication, will it be http?
System Design: TINDER as a microservice architecture
36:41
Gaurav Sen
Рет қаралды 1,2 МЛН
Synyptas 4 | Арамызда бір сатқын бар ! | 4 Bolim
17:24
Don't look down on anyone#devil  #lilith  #funny  #shorts
00:12
Devil Lilith
Рет қаралды 45 МЛН
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
SIDELNIKOVVV
Рет қаралды 4 МЛН
Google system design interview: Design Spotify (with ex-Google EM)
42:13
IGotAnOffer: Engineering
Рет қаралды 1,1 МЛН
Designing INSTAGRAM: System Design of News Feed
24:29
Gaurav Sen
Рет қаралды 634 М.
How NETFLIX onboards new content: Video Processing at scale 🎥
10:44
System design mock interview: "Design WhatsApp or Telegram" (with ex-Google EM)
52:23
IGotAnOffer: Engineering
Рет қаралды 149 М.
System Design Interview: Design WhatsApp
7:22
Hayk Simonyan
Рет қаралды 8 М.
Whatsapp System design or software architecture
27:40
Tech Dummies Narendra L
Рет қаралды 254 М.
System Design Interview: TikTok architecture with @sudocode
45:35
Synyptas 4 | Арамызда бір сатқын бар ! | 4 Bolim
17:24