Message Queue

Synchronous and Asynchronous communication:

synchronous means when a request is sent, the sender expects an immediate response until next operations will enter into wait state.

Asynchronous means when a send a request to a service it accept the request and it won't wait for immediate response its continue next operations.

Message queues are a form of asynchronous communication commonly used in distributed systems. They excel at handling large volumes of data and can effectively reduce latency.

one to one service:

producer-consumer architecture here producer will send a message and that message are stored in the message and consumer will get the message from the message queue.

In a message queue system where producers send data to a queue, maintaining order is crucial. This ensures that consumers process messages in a sequential and organized manner. The scalability of the system is enhanced by allowing the creation of additional consumers to handle increased request loads.

Consider a scenario with messages M1, M2, and M3. Each message is consumed by a consumer, which then sends an acknowledgment back to the message queue. The ordering mechanism, often following the First-In-First-Out (FIFO) principle, ensures that the next message is not processed until the acknowledgment for the current one is received, this is the downside of FIFO.

However, if ordering is not strictly enforced, and a consumer fails to acknowledge a message, the system may enter a potentially problematic state. In such a case, the subsequent message might be processed, while the unacknowledged message remains in the queue. This situation could lead to a "dead letter queue" If any consumer wishes to reprocess the unacknowledged message, then dead letter queue msg will comes to message queue.