Skip to content
StackDecode
System Design
9. Message Queues and Event-Driven SystemsAnimated

Producer-Consumer Pattern

Producers create work; consumers process it.

The idea

A shared queue decouples the rate at which work is produced and consumed.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

ProducerEvent brokerBillingEmailAnalytics
  • client
  • gateway / proxy
  • service
  • cache
  • data store
  • queue / stream

A service publishes an event: "OrderPlaced".

step:
1/4
at:
Producer
1/8

The green dot is a request moving through the system.

Step by step

  1. 1Producers add tasks
  2. 2A queue buffers them
  3. 3Consumers pull tasks
  4. 4Add consumers to go faster

Where it is used

Task processing.

Watch out for

An unbounded queue can hide an overload.

Related