Link Search Menu Expand Document
Table of contents
  1. Determine if and why the system needs asynchronous communication.
  2. Decide if multiple consumers process the same message or point-to-point.
  3. Decide if the communication is push-based or pull-based.
  4. Decide if the order of the messages is important.
  5. Decide if the communication is one-way or bi-rectional.
  6. Decide what to do with malformed messages and resource failures.
  7. Decide how to maintain consistency in a two-phase commit.

Message queues

WIP

Determine if and why the system needs asynchronous communication.

Message queues architectures

Event-driven architecture
Event-driven architecture
Web-Queue-Worker architecture
Web-queue-worker architecture

Event-driven architectures:

  • Events are delivered in near real-time and the application instances respond to them as they occur, without blocking each other.
  • They can use a pub/sub or streaming architecture.
  • In a pub/sub architecture, the infrastructure tracks subscriptions and sends events to each subscriber. After the message is received, it can’t be replayed. New subscribers don’t see the event.
  • In a streaming architecture, events ordered and written to a log. Instances don’t subscribe to the stream, they can read any part of it and advance through it. New clients can join at any point in time and replay events.

The consumer can process events in at least three ways:

  1. Simple processing: every event triggers an action in the consumer, e.g. sending an email.
  2. Complex processing: the consumer processes a series of events, looks for patterns and does an action, e.g. aggregate transactions over a time window, generate a notification if the average crosses a certain threshold.
  3. Event stream processing: the consumer ingests a feed of events and sends it to stream processors that process and transforms the stream, e.g. analytics and IoT workloads.

Web-Queue-Worker architectures:

  • Common in front-ends sending client requests to workers that perform resource-intensive, long-running background or batch jobs, e.g. a single-page web app calling an email or sms service.
  • This is a relatively simple architecture, with clear separation of concerns, decoupled and easy to scale independently. However, without careful consideration, both the front-end web application and the backend workers can easily become monoliths difficult to maintain.
  • For scalability, the workers can share state in a distributed external cache.
  • The system consists of producers generating event streams consumed by other components e.g. real-time processing, high volume, high velocity data from IoT etc.
  • The system has long-running workflows or batch operations, e.g. a Web-Queue-Worker architecture
  • The system has multiple decoupled components that need to communicate
  • The system has request spikes and must level the load
  • The system requires high throughput and scalability
  • The system requires clear separation of concerns
  • The system requires multiple teams to manage and scale it independently

Decide if multiple consumers process the same message or point-to-point.

  • Each message is consumed by a single receiver (point-to-point).
  • Each message can be consumed more than once.

Decide if the communication is push-based or pull-based.

TODO

Decide if the order of the messages is important.

TODO

Decide if the communication is one-way or bi-rectional.

  • The sender doesn’t need a response from the receiver
  • The sender expects an acknowledgement for receiving and processing the message

Decide what to do with malformed messages and resource failures.

  • The system has a limit of retries
  • The system has a delay in between retries, e.g. exponential back-off
  • The system has other queues to handle unprocessable messages, e.g. dead-letter queue

Decide how to maintain consistency in a two-phase commit.

For example, between a message queue and a database.