Data Engineering Guide

Real-Time Data Streaming

Not everything needs to be real-time. But when it does — fraud detection, live metrics, event-driven systems — streaming architecture changes the game. This guide covers Kafka, Flink, and practical patterns.

18 min readFor Data & Platform Engineers

See it as a diagram

Everything below, as a diagram you can edit. Describe yours and see it in seconds.

96/20003 credits left
Try:

No account needed · Editable canvas, not a picture

Streaming vs Batch: When Does It Matter?

DimensionBatchStreaming
LatencyMinutes to HoursMilliseconds to Seconds
Use CaseReports, warehouse loads, ML trainingFraud, live dashboards, IoT
ComplexityLowerHigher
CostPay for compute burstsAlways-on infrastructure
ToolsAirflow, dbt, SparkKafka, Flink, Kinesis

Rule of Thumb

If your stakeholders check a dashboard once a day, streaming is overkill. If they expect data within seconds, batch won't cut it. Default to batch, add streaming where latency requirements demand it.

Apache Kafka: The Foundation

Kafka is the distributed event streaming backbone for most streaming architectures. It decouples producers (apps writing events) from consumers (services processing events).

Topics

Named streams of events. Each event has a key, value, timestamp, and optional headers.

Partitions

Topics split into partitions for parallelism. Events with the same key go to the same partition (ordering guarantee).

Consumer Groups

Multiple consumers share partitions for horizontal scaling. Each partition is consumed by exactly one consumer in a group.

Retention

Events are retained for a configurable period (default 7 days). Can be set to infinite for event sourcing patterns.

Stream Processing with Flink

Apache Flink processes events as they arrive with exactly-once semantics. It handles windowing, state management, and complex event processing that Kafka Streams can't do at scale.

Windowed Aggregations

Tumbling, sliding, and session windows. Example: count events per 5-minute window, or aggregate user sessions until 30 min idle.

Stateful Processing

Flink maintains state across events. Join streams, detect patterns, and compute running totals without external databases.

Exactly-Once Semantics

With checkpointing, Flink guarantees each event is processed exactly once, even during failures. Critical for financial data.

SQL Interface

Flink SQL lets analysts write streaming queries in familiar SQL syntax. No need to learn Java/Scala APIs for basic transformations.

Architecture Patterns

Lambda Architecture

Parallel batch + streaming layers. Batch provides accuracy, streaming provides speed. Results merge in a serving layer.

Pros: Accuracy + speed. Cons: Two codebases, complex maintenance.

Kappa Architecture

Streaming-only. Single codebase processes all events. Reprocessing by replaying from Kafka. Simpler than Lambda.

Pros: One codebase, simpler. Cons: Harder to handle heavy aggregations, replay can be slow.

Hybrid (Recommended)

Stream low-latency use cases (fraud, alerts). Batch the warehouse and complex aggregations. Share the same Kafka backbone.

Pros: Right tool for each job. Cons: Two systems to manage.

Platform Comparison

PlatformBest ForManaged?
Apache KafkaEvent backbone, high throughputConfluent Cloud / MSK
Amazon KinesisAWS-native streamingFully managed
Google Pub/SubGCP-native, serverlessFully managed
RedpandaKafka-compatible, no JVMRedpanda Cloud
Apache FlinkComplex stream processingAWS KDA / Ververica

FAQ

When should you use streaming vs batch?
Streaming for sub-minute latency (fraud, live dashboards, IoT). Batch for daily reports, warehouse loads, and ML training. Default to batch, add streaming where latency demands it.
What is Apache Kafka?
A distributed event streaming platform that acts as a durable, high-throughput message bus decoupling producers from consumers. Core concepts: topics, partitions, consumer groups, retention.
What are Kafka alternatives?
Amazon Kinesis (AWS-native), Google Pub/Sub (GCP-native), Apache Pulsar (multi-tenancy), Redpanda (Kafka-compatible, no JVM), Confluent Cloud (managed Kafka).

Diagram your streaming architecture

Map Kafka topics, Flink processors, and data flows with AI-powered diagrams and cloud icons.

Try Datadef Free