← Lessons

quiz vs the machine

Platinum1750

Concurrency

Reactive Functional Streams

Asynchronous sequences with operators and backpressure.

6 min read · advanced · beat Platinum to climb

Streams of events over time

A reactive stream is an asynchronous sequence of values that arrive over time: clicks, sensor readings, rows from a query. You process it with the same functional operators you use on lists, but the elements appear when they appear.

Operators build a pipeline

  • map transforms each element.
  • filter drops elements that fail a predicate.
  • merge and flatMap combine multiple streams into one.

Crucially these operators are declarative: you describe the dataflow once, and the stream pushes values through it as they emerge. State stays inside operators, not in shared variables.

Backpressure

A fast producer can overwhelm a slow consumer. Reactive streams solve this with backpressure: the consumer signals how many elements it can accept, and the producer must not exceed that demand. This turns an uncontrolled push into a demand driven flow.

Hot versus cold

A cold stream starts producing only when subscribed and replays for each subscriber. A hot stream emits whether or not anyone listens, so late subscribers miss earlier events. Mixing them up causes lost or duplicated work.

Key idea

Reactive streams are asynchronous sequences shaped by functional operators, with backpressure making the flow demand driven instead of overwhelming.

Check yourself

Answer to earn rating on the learn ladder.

1. What problem does backpressure in reactive streams solve?

2. How does a cold stream differ from a hot stream?

3. Why are stream operators called declarative?