Chapter 16. Flow control patterns

 

In the previous chapters, you learned how to decompose systems into smaller pieces and how these pieces communicate to solve greater tasks. One aspect we have left out so far is that in addition to who interacts with whom, you must also consider the timeliness of communication. In order for your system to be resilient to varying loads, you need mechanisms that prevent components from failing uncontrollably due to overwhelming request rates. This chapter therefore introduces four basic patterns:

  • The Pull pattern propagates back pressure from consumers to producers.
  • The Managed Queue pattern makes back pressure measurable and actionable.
  • The Drop pattern protects components under severe overload conditions.
  • The Throttling pattern helps you avoid overload conditions where possible.

There are many variations on these patterns and a lot of applicable theory to be studied (in particular, control theory and queueing theory), but a treatment of these fields of research is outside the scope of this book. We hope you will be inspired by the basics presented in this chapter and refer to the scientific literature for in-depth coverage.

16.1. The Pull pattern

Have the consumer ask the producer for batches of data.

16.2. The Managed Queue pattern

16.3. The Drop pattern

16.4. The Throttling pattern

16.5. Summary