SpinTheMic
Pro

Explain it in 60 seconds

foreachBatch in Structured Streaming

Data Engineering · Spark · Experienced

What is foreachBatch and when do you use it?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • foreachBatch gives you each micro-batch as a normal DataFrame plus a batchId.
  • Lets you use batch APIs like MERGE into Delta or JDBC writes.
  • Useful for writing to multiple sinks or upserts.
  • You must make writes idempotent, since a batch can be replayed.
  • Cache the batch DataFrame if writing it to several places.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics