Saturday, May 15, 2021

WhatsApp - Forwarding multiple messages in whatsapp follows which type of data structure

Interesting Interview Question for Senior Developer :  

Well I have multiple opinions on the same such as 

1) Whatsapp and most chat clients on the client-side use SQLite (A tiny embeddable database software) to store the data, and so the chat client does NOT use any data structure on their own and just calls the order-by query on the database, which gives them the list of chats ordered by the time.

This means the database has an index on the date and time of the last chat, and for this, if you look at the SQLite documentation, they use the often-used data structure of b-trees.



2)The data structure used in the queue.

A queue essentially works on the principle of "First In First Out".

A queue is maintained for each user which contains the message to be delivered to the user.

When the user comes online the messages in the queue are delivered and the queue is deleted.

Nothing is stored on the server.

3)WhatsApp uses a customized version of the open standard Extensible Messaging and Presence Protocol (XMPP)

WhatsApp follows a 'store and forwards' mechanism for exchanging messages between two users. When a user sends a message, it first travels to the WhatsApp server where it is stored. Then the server repeatedly requests the receiver acknowledge receipt of the message. As soon as the message is acknowledged, the server drops the message.

Well according to me it would be based on some key facts about networking.

For Delivered: After the message would be received at the client's phone an acknowledgment message sent would be pushed from the client's phone.

For Reading by When the user opens the screen where the message is present, again a notification would be sent this won't require implementing complex data structures but utilizing the features of the protocols being used for transmission. Which have become a part of WhatsApp now.

Whereas sent would indicate message being sent from your phone to the servers at WhatsApp

So for implementing this when in a group chat the message response needs to be stored in a queue that would verify all the above steps for each member in the group and accordingly will set the Status.

Now coming to an important point the original and "native" transport protocol for XMPP is Transmission Control Protocol (TCP), using open-ended XML streams over long-lived TCP connections, and TCP/IP protocol uses a network congestion-avoidance algorithm that includes various aspects of an additive increase/multiplicative decrease (AIMD) scheme, with other schemes such as slow-start to achieve congestion avoidance.

This could be one of the algorithms being implemented for network acknowledgments, they added a lot more features as they have customized XMPP to use on top of their transmission.

I hope I have answered your queries. Thanks.


No comments: