Apache Flink Basics
Learn Apache Flink, the true event-at-a-time stream processor: DataStream and Table APIs, Flink SQL, state, checkpoints and event-time processing.
Advanced · about 8 hours · difficulty 4/5
Learn first: Apache Kafka Fundamentals
Apache Flink processes events one at a time with very low latency and powerful state management. It is used for fraud detection, real-time features and alerting at large tech and fintech companies, and managed versions exist on AWS (Managed Service for Apache Flink) and Confluent.
Core concepts
- Job graph of operators (sources, transformations, sinks) running in parallel on TaskManagers, coordinated by a JobManager.
- DataStream API (Java, Python via PyFlink) for fine-grained control.
- Table API and Flink SQL for declarative pipelines:
SELECT window_start, city, COUNT(*) FROM TABLE(TUMBLE(...)) GROUP BY .... Flink SQL is the easiest entry point.
State and time
- Keyed state per key (per user, per card) with large state stored in RocksDB.
- Event time and watermarks are first-class.
- Timers let you act when time passes (flag a cart abandoned after 30 minutes).
Fault tolerance
- Checkpoints periodically snapshot state and source offsets for exactly-once processing.
- Savepoints are manual snapshots used for upgrades and migrations.
Flink vs Spark Structured Streaming
- Flink: lower latency, richer state and timers, better for complex event processing.
- Spark: one engine for batch and streaming, easier if your team already runs Spark.
Learn one in depth; understand where the other fits.
Pitfalls
- Unbounded state from keys that never expire; set state TTL.
- Upgrading a job without a savepoint and losing state.
You are ready to move on when you can run Flink locally with Docker, write a Flink SQL job that reads from Kafka and computes windowed counts, and explain how checkpoints give exactly-once results.
Key concepts
- JobManager and TaskManagers
- DataStream API
- Flink SQL and Table API
- Keyed state and RocksDB
- Event time and timers
- Checkpoints and savepoints
- State TTL
- PyFlink
Other options for this step
- Spark Structured Streaming: Build streaming pipelines with the same DataFrame API you use for batch: Kafka sources, event-time windows, watermarks, checkpoints and output modes.
Mini project
Run Flink and Kafka in Docker. Using Flink SQL, read card transaction events from Kafka and flag any card with more than 5 transactions in 1 minute, writing alerts to another Kafka topic.
Check yourself
What is the difference between a checkpoint and a savepoint, and when do you use each?
Free resources
- Apache Flink documentation (Apache Flink)
- Apache Flink (Apache Flink)
- Confluent Developer courses (Confluent)