How Does Whatsapp Queue Your Messages?

3 min read

Elo there, mate! It’s going to be almost two years of the pandemic in a few months, and the way we have adapted our lifestyles, oh boy! We all stayed connected and even got our work done using various messaging platforms. The usage of multiple platforms, including Whatsapp, Instagram, and Facebook, increased significantly. Whatsapp was the one with the highest usage, and with India being Whatsapp’s biggest market this year! But did you know that Whatsapp uses one of the very basic data structures, queue, which is used by this messaging platform to deliver your messages successfully? 

What is Queue?

A queue, as the name indicates, is exactly like the one in real life. A queue has two ends, a head and a tail, and items are added only in the tail end and removed from the head end. Imagine a group of people waiting in a queue to get pizza, and the first person who got there, i.e., the first in the line, would be given preference and would be the one to receive the pizza or be “pushed out.” This concept technically is known as FIFO or First In First Out. 

What is a message queue?

As indicative of the title, a message queue is a queue full of messages. This asynchronous service is used to transfer messages or data between two people or a group of people. The person who sends the message into the queue is the producer, and the one who receives the message is the consumer. From the queue’s point of view, a message is just a collection of bytes and can be anything from a normal text message or a message containing a customer’s order ID or even an error message. 

  • In a message queue system, there are multiple servers known as brokers. These brokers are highly reliable and scalable, and they form a cluster. Once a message is produced or sent from the producer side, the message is stored in the message queue until the consumer is available to take the messages. 
  • Once the consumer or the recipient is available to take the message, the queue pushes the message to the consumer and waits for the consumer to process the message entirely.
  • After the consumer processes the message, it is entirely deleted from the queue. 

Message Queue Solutions

There are multiple open-source and free software that is used for message queuing.

Kafka: Apache Kafka’s messaging system is a well-thought-out publish-subscribe system and a queuing system that can handle very high volumes of data. Kafka is fault-tolerant and constantly monitors the nodes through various services, making it efficient to work with. 

Rabbit MQ: RabbitMQ is one of the most used open-sourced messaging broker systems that originally implemented the Advanced Message Queuing Protocol (AMQP). Queues are a single thread in this system, and one queue can handle up to 50,000 messages. 

Amazon SQS: Amazon Simple Queue Service is a distributed message queuing system used to decouple various microservices and applications without requiring them to maintain their message queues. Amazon SQS also provides a web service API that users can access using common programming languages.

ActiveMQ: ActiveMQ is another message broker system written in Java and has a full Java Message Service Client. It has built-in AJAX and REST support and supports various protocols like AMQP, MQTT, STOMP, etc.

How does Whatsapp deliver your messages?

Before we get into how the messages are queued in Whatsapp, let’s understand the app itself. Coded using the ERLANG programming language, Whatsapp is the most used with almost 2 billion monthly users. Whatsapp uses the open-sourced Extensible Messaging and Presence Protocol (XMPP) to facilitate instant messages between two parties. Initially, Whatsapp started by using the Ejabbered server. With such a high number of users daily, it is essential that servers handle the load efficiently and the system is reliable. In the years, the code was restructured, switching from XMPP to an internally designed protocol and modifying some core components to improve and achieve optimal server performance. 

As and when you send a message, it is queued in the server until the receiver reconnects to retrieve these messages. So when you text your friend, and if they don’t have internet access to receive the messages, these messages are queues in the Whatsapp servers, and this process is known as the “store and forward” mechanism. Only when the receiver accepts the messages are they wiped from the server and deleted from the queue. Later, when the receiver has an internet connection, these messages are delivered to them or are retrieved by the receiver. When the receiver finally acknowledges that the message has been received, the successful retrieval of the message is sent back to the Whatsapp server, and this is when you see the double tick mark next to your messages. 

These data structures go a long, and having a good understanding of this will take you a long way as well. So the next time your teacher starts discussing data structures, pay good attention there. Yeah? Okay?

Well, then see you next time!

What Is An Integrated Development Environment?

An integrated development environment (IDE) is software that facilitates software developers in writing source code, debugging it, and providing specific tools for automation that...
jn0706
5 min read

Updates for the month of April 2022

Update on Laddus We had initiated Laddus in our system almost 8 years ago as an attempt to encourage the correct user behavior and...
surajmsharma
1 min read

The World Has A New SnackDown Champion!

Hello there! After a whole four months and just an extra few days, we finally have our new SnackDown Champion! With more than 75k+...
ganga4518
3 min read

Leave a Reply