# 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. Free notes,...

Canonical: https://www.internhack.in/roadmaps/tracks/data-engineer/flink
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/data-engineer/kafka)

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](https://www.internhack.in/roadmaps/tracks/data-engineer/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](https://nightlies.apache.org/flink/flink-docs-stable/) (Apache Flink)
- [Apache Flink](https://flink.apache.org/) (Apache Flink)
- [Confluent Developer courses](https://developer.confluent.io/) (Confluent)

Previous: [Spark Structured Streaming](https://www.internhack.in/roadmaps/tracks/data-engineer/spark-structured-streaming) · Next: [Data Quality Fundamentals](https://www.internhack.in/roadmaps/tracks/data-engineer/data-quality-fundamentals)

## More in Streaming Data

- [Stream Processing Concepts](https://www.internhack.in/roadmaps/tracks/data-engineer/streaming-concepts)
- [Apache Kafka Fundamentals](https://www.internhack.in/roadmaps/tracks/data-engineer/kafka)
- [Kafka Connect and Schema Registry](https://www.internhack.in/roadmaps/tracks/data-engineer/kafka-ecosystem)
- [Spark Structured Streaming](https://www.internhack.in/roadmaps/tracks/data-engineer/spark-structured-streaming)
- [Apache Flink Basics](https://www.internhack.in/roadmaps/tracks/data-engineer/flink)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Data Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/data-engineer)
