Apache Flink
1.18.xSummary
Stateful stream processing engine written in Java/Scala providing event-time processing with watermarks, checkpointed stateful operators, and exactly-once end-to-end semantics with compatible sources and sinks. Handles unbounded (streaming) and bounded (batch) datasets through the same API surface.
Primary Use Case
Real-time stateful computation over event streams: fraud detection with windowed pattern matching, real-time aggregation pipelines, CDC event processing for derived data views, and ETL pipelines requiring exactly-once guarantees.
Workload Fit
Strengths
Best for
- ·Stateful streaming with exactly-once guarantees where event ordering and late data handling are first-class concerns
- ·Fraud detection and real-time alerting using Flink CEP (Complex Event Processing) for pattern matching across event sequences
- ·CDC pipeline processing where upstream database changes must be transformed, enriched, and applied to downstream systems with transactional guarantees
- ·Real-time aggregation over time windows (tumbling, sliding, session) that feed dashboards, feature stores, or materialized views
- ·ETL workflows that process bounded datasets (batch mode) and streaming data through the same operator graph
Excels when
- ·Workload requires exactly-once end-to-end semantics: Flink's two-phase commit checkpoint protocol is one of the few streaming systems that genuinely provide this guarantee
- ·State size per job exceeds what fits in JVM heap and RocksDB state backend with incremental checkpoints provides cost-effective large-state storage
- ·Event-time processing is required: watermarks and allowed lateness enable correct aggregation over out-of-order event streams without application-level buffering
- ·Pipeline complexity justifies the investment: joins between streams, enrichment against broadcast state, time-correlated pattern matching
Architectural advantages
- ·Chandy-Lamport distributed snapshot algorithm provides consistent checkpoints across all operators without stopping processing: checkpoint is asynchronous to the data path
- ·RocksDB state backend provides state sizes that exceed JVM heap with incremental checkpoints that only upload changed sstables to checkpoint storage
- ·Watermark mechanism enables correct event-time windowing over out-of-order data without requiring the event source to deliver events in order
- ·CEP library provides state machine-based pattern detection over event sequences (e.g., detect three failed logins within 60 seconds) without custom state management
- ·Unified batch and streaming API: a Flink job that processes a bounded dataset and an unbounded stream use the same DataStream or Table API
When to Avoid
Avoid when
- ·Team has fewer than 2–3 engineers with Flink or Spark Streaming operational experience: the operational surface (checkpoint tuning, backpressure debugging, state evolution) is not suitable for teams new to distributed streaming
- ·Latency requirement is sub-100ms end-to-end: exactly-once checkpoint-based processing introduces latency proportional to checkpoint interval; use Kafka Streams or custom consumer logic for millisecond-latency requirements
- ·Workload is simple stream filtering or format conversion without stateful aggregation: Kafka Streams or simple consumer processes are adequate and far simpler to operate
- ·Job topology will change frequently: each topology change requires a savepoint and replay from the checkpoint; rapid iteration is expensive
Common misuses
- ·Using Flink for stateless transformations or simple filtering: the checkpoint overhead and operational complexity are not justified; Kafka Streams or a simple consumer achieves the same result with far less infrastructure
- ·Not testing state schema evolution before upgrading a job with large state: breaking savepoint compatibility in production requires replaying from source (Kafka), which may require hours of catch-up processing
- ·Setting checkpoint interval to 10+ minutes to reduce I/O cost: longer checkpoint intervals mean more state to replay on failure and longer recovery times; balance interval against recovery time objective
Consistency & Transactions
Scaling
Read scalability
Source parallelism scales by increasing the number of source subtasks reading from Kafka partitions or other partitioned sources. Each subtask reads from a subset of partitions independently. Read throughput scales linearly with parallelism up to the source partition count.
Write scalability
Sink parallelism scales by adding sink subtasks writing to downstream systems. For transactional sinks (JDBC, Kafka exactly-once), the number of open transactions at checkpoint boundaries grows with sink parallelism: downstream systems must support the concurrent transaction count.
Failure Behavior
Known failure modes
- ·Checkpoint pressure: slow or unavailable sinks cause checkpoint barriers to accumulate in the operator pipeline; checkpoint latency increases until the checkpoint timeout is exceeded and the job enters a restart loop
- ·State backend RocksDB compaction pressure: write-heavy stateful jobs generate L0 sstables faster than RocksDB compaction can merge them; read amplification increases and checkpoint size grows
- ·Watermark stalling: a single idle or slow source partition holds back the global watermark; all event-time windows that depend on the watermark advancing stop emitting results
- ·Backpressure cascade: a slow sink subtask propagates backpressure upstream through the operator DAG; the entire job slows to the pace of the slowest sink
- ·Savepoint/checkpoint incompatibility after job upgrade: changes to operator UIDs, state schemas, or serializer versions break savepoint restore: state schema evolution requires explicit compatibility planning
- ·Exactly-once transaction accumulation: at high sink parallelism, Kafka exactly-once sinks hold open transactions for the entire checkpoint interval; exceeding Kafka's transaction timeout causes commits to fail
Bottlenecks
- ·Sink throughput: the slowest sink subtask determines the throughput ceiling for the entire job; external system write latency becomes the job throughput limiter
- ·Checkpoint storage I/O: at high parallelism with large state, checkpoint uploads to S3 consume network bandwidth proportional to state size times checkpoint frequency
- ·RocksDB compaction contention: write-heavy stateful operators cause compaction threads to compete with processing threads for CPU; pin compaction threads to isolated cores on high-throughput jobs
- ·Watermark propagation delay through idle partitions: a Kafka partition that receives no events holds back the watermark for all subtasks; configure idle source timeout to advance watermarks past idle partitions
- ·JobManager single point of coordination: job submission, checkpoint coordination, and failure recovery all go through the JobManager; HA requires ZooKeeper or Kubernetes leader election
Degradation patterns
- ·Checkpoint duration creep: as state grows over the job lifetime, checkpoint upload time increases; monitoring checkpoint size trend identifies impending checkpoint timeout before it causes job restarts
- ·Backpressure cascade from sink overload: a temporarily slow downstream system causes upstream operators to fill their network buffers; processing latency increases across the entire job DAG
- ·Watermark stall from idle partitions: in multi-source jobs, a source that stops producing events freezes the global watermark; all event-time windows stop emitting until the idle source advances
Recovery considerations
- ·Savepoints are manually triggered consistent snapshots used for planned upgrades and migrations; checkpoints are automatically managed for failure recovery: they serve different purposes
- ·Incremental RocksDB checkpoints upload only changed sstables to checkpoint storage; recovery from an incremental checkpoint requires replaying all incremental steps since the last full checkpoint
- ·After job failure, Flink replays from the last successful checkpoint; source offset is reset to the checkpoint's stored offset: Kafka sources must retain messages at least until the checkpoint interval plus replay time
Operational Pitfalls
- ·Not assigning stable operator UIDs: if UIDs are auto-generated, any change to the job topology invalidates all savepoints and prevents stateful job upgrades without data loss
- ·Using the default HashMapStateBackend for large-state jobs: all state lives in JVM heap; GC pressure causes task manager failures when state grows beyond a few GB per subtask
- ·Setting checkpoint interval too short for the job's throughput: frequent checkpoint barriers increase I/O load on the checkpoint storage (S3) and can cause job throughput degradation
- ·Not monitoring checkpoint duration and size metrics: checkpoint latency is the primary indicator of impending job instability; jobs should alert when checkpoint duration exceeds 80% of the checkpoint interval
- ·Deploying on Kubernetes without tuning pod resource requests/limits: Flink's TaskManagers require predictable CPU and memory; resource contention from co-located pods causes checkpoint timeouts
- ·Not accounting for watermark strategy when processing out-of-order events: without allowed lateness configured, events arriving after the watermark are silently dropped
Architecture Guidance
Common topology roles
Migration notes
- ·From Spark Streaming: Flink's event-time watermark model is more rigorous than Spark's micro-batch model; jobs requiring exact event-time semantics benefit from migration; jobs that use micro-batch semantics do not
- ·From Kafka Streams: Kafka Streams is simpler to operate (runs in the application process, no separate cluster) but lacks Flink's exactly-once across multiple sinks, CEP, and large-state RocksDB backend
- ·Job version upgrades require savepoint compatibility planning; operator UIDs must be stable across versions and state schema changes must use compatible serializers
Advisor Guidance
When: scenario requires exactly-once end-to-end stream processing
Configure Kafka source with EXACTLY_ONCE isolation, use Kafka transactional sink or JDBC sink with checkpointed commits; set checkpoint interval based on recovery time objective
When: scenario has stream processing with large stateful aggregations
Use RocksDB state backend with incremental checkpoints; monitor RocksDB compaction pending tasks and checkpoint duration as the primary stability indicators
When: team does not have distributed streaming operational experience
Flink's operational surface (checkpoint tuning, backpressure diagnosis, state evolution, watermark debugging) requires staff-level streaming expertise; evaluate Kafka Streams for simpler stateful use cases
Comparison Factors
exactly once guarantee
One of the few streaming systems providing genuine exactly-once end-to-end; two-phase commit protocol is rigorous and well-tested
operational complexity
Very high: checkpoint tuning, state backend selection, backpressure diagnosis, savepoint management, and watermark strategy all require deep expertise
event time processing
Best-in-class: watermarks, allowed lateness, and side output for late data are first-class language constructs
end to end latency
Tens of milliseconds to seconds depending on checkpoint interval; not suitable for sub-100ms latency requirements with exactly-once
Managed Cloud Options
Enables Patterns
Basis
Flink's checkpoint algorithm and state backend behavior are publicly documented; operational characteristics verified against Flink documentation and practitioner reports from LinkedIn, Alibaba, and Netflix