Data Concurrency - Producer Consumer Thread


Producer / Consumer is concurrency model (ie two threads/process communication) where:

  • one thread called a Producer sends data
  • and the other thread called the Consumer receive data.

The data send and received is called a message.


When the consumer becomes also a producer for another consumer, they form a chain called a pipeline.

See also Event - Provider

Upstream faster than downstream

What solutions do we have when there is a fast producer and a slow consumer (ie if the upstream is faster, than the downstream)

  • Backpressure - the slower consumer request a given amount of data from the faster producer
  • Buffer the messages in a queue
  • Drop some message - networking hardware does that
  • Block the producer until the consumer catch up. It slows down the entire pipeline.

Powered by ComboStrap