Skip to the page

Streaming and CDC · mid

Kafka ingestion into the lakehouse and choosing an engine

A clickstream pipeline needs the right number of partitions, a schema contract, a stream consumer that commits to a table, a dead-letter path and replay from the bronze table. Spark and Flink fit different latency needs.

The notes

What you must know

  • Sizing: 250,000 events a second at about 1 KB is about 250 MB/s, so tens to over a hundred partitions with headroom. Replication factor 3, acks=all, min.insync.replicas=2.
  • Key by user or session id when per-user order matters, no key for an even spread when it does not. A hot key can overload one partition.
  • Schemas: Avro or Protobuf with a schema registry and compatibility rules. Put event_id, event_time and a schema version in every event.
  • Consumer: Spark Structured Streaming, Flink or a Kafka Connect sink writing a Delta or Iceberg bronze table every 1 to 5 minutes. The checkpoint is on object storage and each micro-batch is one table commit.
  • Broken events go to a dead-letter table with the error and raw payload, and the stream keeps running.
  • Small files: the trigger interval balances latency and file count. Compact hourly, partition by event date, cluster by event name.
  • Duplicates from app retries: deduplicate by event_id in silver within a time bound (dropDuplicatesWithinWatermark, Spark 3.5 and later) or with a MERGE.
  • Replay: from Kafka only within its retention. For older data replay from bronze, which keeps raw events for months.
  • Monitor consumer lag (records and minutes), batch duration against the trigger, input versus processing rate, dead-letter rate and table freshness.
  • Spark Structured Streaming uses micro-batches (latency usually seconds) and shares code with batch. Flink processes one event at a time with millisecond latency, rich keyed state, timers and savepoints. Flink is another system to run.
  • Sub-second features with large keyed state fit Flink (or Kafka Streams). Watch for two code paths giving different numbers. Kafka 4.x runs only in KRaft mode, with no ZooKeeper since 4.0.

The red pen

Common traps: mistake → fix

  • Mistake: A handful of Kafka partitions is enough

    Fix: size for peak throughput with headroom.

  • Mistake: Rely on Kafka's retention to replay last quarter

    Fix: use the bronze table.

  • Mistake: Flink is faster so always Flink

    Fix: consider team skills and operations.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design ingestion from Kafka into a lakehouse with 15-minute freshness.
  2. How do you handle bad events in a stream?
  3. How do you replay data after a bug?
  4. Spark Structured Streaming or Flink for per-user features within a second?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview