Skip to content
Gold 8 min read · Operations 2 practice problems ↓

Backpressure and rate limits

When data arrives faster than a stream processes it: measuring lag, catch-up arithmetic, rate limits per source, and what to scale.

Step 4 · Structured Streaming · Gold · Running streams in production, lesson 2 of 3

Read first: Triggers · Monitoring streams (skip if you know them)

In plain words first

Think of a bathtub with the tap on and the plug out. The tap is the input rate, the drain is the processing rate, and the water level is the lag, the data waiting to be processed. If the tap runs faster than the drain, the level rises. The tub has a rim: in a pipeline, that is how long KafkaKafka: A system that stores streams of events in topics, in order within each partition, so many readers can read them, and read them again, at their own pace. Learn more → keeps messages. Past it, data overflows and is lost.

Backpressure means slowing the tap when the drain cannot keep up. Spark cannot slow your producersproducer: An application that writes events to a topic. Learn more →, so it does the next best thing: it decides how much to drain in each micro-batchmicro-batch: One small round of a stream: Spark takes the data that arrived since the last round, processes it like a little batch job, and saves its progress. Learn more →, and you widen the drain when that is not enough.

Unlock the full lesson

You have read the free part. The rest of this advanced lesson:

  • Two rates and a little arithmetic
  • Spark pulls, Kafka waits
  • Rate limits per source
  • Sizing the limit
  • When limits are not enough: scale
  • Try it yourself
  • Common mistakes
  • Key takeaways
  • Interview prep with 3 follow-up questions
  • Check yourself: 3 questions

Unlock it with the Complete pass (every advanced problem and lesson) or on its own.

Practise this

Interview problems on streaming, graded on hidden tests

Keep going

Up next · Running streams in production · lesson 3 of 3 · 7 min read
Restarts, query changes and reprocessing
Which changes a checkpoint accepts, how to rebuild a stateful query safely, and source schema changes.

Related lessons

Previous: Monitoring streams

Primary sources: Kafka source options (rate limits, minPartitions) · File source options · Delta: limit input rate · Spark Streaming (DStream) backpressure setting