Real-Time Big Data Pipeline

Kafka, Spark Structured Streaming, MinIO, Docker

View on GitHub

Streaming financial transactions end to end

Context

Batch pipelines let you re-read the input as many times as you like. Streaming ones do not, and most of what makes streaming difficult (ordering, delivery guarantees, what a “batch” even means when the data never stops) only shows up once something is actually running. I built a full streaming stack that runs locally so those problems are reproducible rather than theoretical: a producer generating financial transaction events, Kafka carrying them, Spark Structured Streaming processing them, and object storage holding the result.

Constraints

  • The input cannot be re-read. A batch job can be re-run on the same files. A stream has to be processed correctly as it arrives, or the state has to be recoverable from checkpoints.
  • Ordering and delivery. Events can arrive late or be delivered more than once, and the output has to tolerate both.
  • A batch that never closes. Output is written in micro-batches, and the batch size and trigger interval decide how many files the output produces.
  • The whole stack on one machine. Kafka, Spark and MinIO run together under Docker Compose, so memory and startup order are part of the design.
  • Simulated input. The producer generates the transactions, so the pipeline has to be correct without a real source to compare against.

What I built

Docker Compose: the whole stack from one command Producer simulated financial transaction events configurable rate Kafka transactions topic durable log replayable offsets Spark Structured Streaming schema validation enrich · micro-batches MinIO S3-compatible store partitioned Parquet ready to query

A producer publishes simulated transaction events to a Kafka topic at a configurable rate. Spark Structured Streaming consumes that topic continuously, validates each event against a declared schema, enriches it, and writes the result to MinIO as partitioned Parquet, laid out so downstream readers can prune whole partitions instead of scanning everything.

The whole stack (Kafka, Spark, MinIO) is defined in Docker Compose, so docker-compose up reproduces it from nothing. That matters more than it sounds: a streaming bug that only appears under load is worth very little if you cannot get back to the same starting state.

Design choices

A declared schema. Spark validates each event against a schema defined in the code. Inference on a stream takes the shape from whatever arrives first, so a malformed event could change the schema of the output. With a declared schema that event fails validation instead.

Partitioned output. The Parquet output is laid out so downstream readers skip whole partitions. A flat directory is simpler to write, but every query then scans everything, and that cost grows with the length of the run.

Object storage as the sink. MinIO is S3-compatible, so the same layout and paths work on cloud object storage. Local disk would work for the demo and need rewriting afterwards.

Next steps

  • Throughput. Find the event rate at which consumer lag starts to grow, which shows where the pipeline stops keeping up.
  • End-to-end latency. Time from publish to a readable Parquet file.
  • Late events. Watermarking on event time, with a test that sends late events and checks what the output does with them.
  • File compaction. A short trigger interval produces many small files, so readers would need a compaction job.

Stack

Apache Kafka, Spark Structured Streaming, MinIO, Parquet, Docker Compose, Python