Goals

Get to know software patterns using queues to perform distributed processing of workloads.

Introduction

Context

Competing Consumers Pattern

In a queue-centric workflow pattern, work is placed in a queue and processed by multiple workers. Workers can retrieve work from the queue whenever they are ready to process it. Scaling is often based on the length of the queue or the average waiting time of a job in the queue (J). To scale, workers can be added or removed on demand.

queue_centric_pattern.svg

Competing Consumers - Enterprise Integration Patterns

Example

Queues are scalable cloud services like the AWS Simple Queue Service (SQS):

From https://aws.amazon.com/sqs/

From https://aws.amazon.com/sqs/

Fully Managed Message Queuing – Amazon Simple Queue Service – Amazon Web Services

Little’s Law

In queuing theory, Little’s Law describes a fundamental relationship between three key quantities in any stable system: the average number of items in the system, the average arrival rate of new items, and the average time an item spends in the system.

The power of this law lies in its generality - it holds regardless of the specific distribution of arrival or service times, as long as the system is in a long-term steady state.

The formula for Little’s Law is:

$$ L = \lambda \cdot W $$

Where:

Example: Supermarket

Imagine we observe a supermarket and count that, on average, there are 30 customers in the store at any given time (L). We also determine that 6 new customers enter the store each minute (λ). Using Little’s Law, we can estimate the average time a customer spends shopping (W).

$$ 30=6 \cdot W \Rightarrow \frac{30}{6} = W \Rightarrow 5 $$

This means that each customer spends about 5 minutes in the supermarket - without having to measure individual shopping trips. This simple but powerful formula is widely used in computer science to analyze system load, network traffic, or job processing times in queues.