ivanshamaev/de-agent-skills/apache-flink

Claude Code and agent skill by ivanshamaev/de-agent-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Apache Flink — streaming architecture (JobManager/TaskManager/slots/parallelism), PyFlink Table API and SQL (Kafka/filesystem DDL, windowing TUMBLE/HOP/SESSION, aggregations), DataStream API (KeyedStream, stateful operations ValueState/MapState, process functions), event-time vs processing-time, watermark strategies, checkpointing (exactly-once, RocksDB state backend), Kafka source/sink (delivery guarantees), backpressure, savepoints, deployment (standalone/YARN/Kubernetes)

Install

npx vskill@latest install ivanshamaev/de-agent-skills/apache-flink

SKILL.md

The same SKILL.md was published earlier as ivanshamaev/de-agent-skills/apache-flink.

Apache Flink

When to Use

Load this skill when the user needs to:

  • Build low-latency stateful streaming pipelines (CDC, real-time aggregations, event-driven processing)
  • Use event-time processing, watermarks, and out-of-order event handling
  • Write PyFlink SQL or Table API pipelines with Kafka sources/sinks
  • Implement stateful operations (session detection, deduplication, windowed aggregation)
  • Configure checkpointing, state backends, and exactly-once semantics
  • Deploy Flink jobs on YARN, Kubernetes, or standalone clusters

Architecture

Client ──► JobManager (master)
├─ JobGraph compilation
├─ Task scheduling
├─ Checkpoint coordination
└─ REST API (:8081)
TaskManagers (workers) — N instances
└─ Task Slots (parallelism units)
└─ Subtask (one parallel instance of an operator)
Parallelism: each operator runs as P subtasks (default = slot count)
P per operator can be set independently
State Backend:
├─ HashMapStateBackend (default) — JVM heap, fast, size-limited
└─ EmbeddedRocksDBStateBackend — local SSD, unbounded state, slower reads

Setup

Install (PyFlink)
bash
pip install apache-flink==1.20.0
# Requires Java 11 on PATH
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Maven / Gradle coordinates for JARs
# Kafka connector (add to flink/lib/ or via --jars)
org.apache.flink:flink-connector-kafka:3.3.0-1.20
org.apache.flink:flink-sql-connector-kafka:3.3.0-1.20 # Table API
# Iceberg Flink runtime
org.apache.iceberg:iceberg-flink-runtime-1.20:1.7.0
# Avro
org.apache.flink:flink-avro:1.20.0

Table API & SQL (Recommended for ETL / Analytics)

Environment Setup
python
from pyflink.table import TableEnvironment, EnvironmentSettings
# Streaming mode
t_env = TableEnvironment.create(EnvironmentSettings.in_streaming_mode())
# Batch mode (bounded sources)
t_env = TableEnvironment.create(EnvironmentSettings.in_batch_mode())
# Parallelism
t_env.get_config().set("parallelism.default", "4")
# Checkpoint (required for production)
t_env.get_config().set("execution.checkpointing.interval", "60000") # 60s
t_env.get_config().set("execution.checkpointing.mode", "EXACTLY_ONCE")
t_env.get_config().set("execution.checkpointing.timeout", "300000") # 5 min
t_env.get_config().set("execution.checkpointing.min-pause", "30000") # 30s between checkpoints
t_env.get_config().set("state.backend", "rocksdb")
t_env.get_config().set("state.checkpoints.dir", "s3://flink-checkpoints/my-job/")
t_env.get_config().set("state.savepoints.dir", "s3://flink-savepoints/")
# Add connector JAR at runtime
t_env.get_config().set(
"pipeline.jars",
"file:///opt/flink/lib/flink-sql-connector-kafka-3.3.0-1.20.jar"
)
Kafka Source — DDL
python
t_env.execute_sql("""
CREATE TABLE orders_kafka (
order_id BIGINT,
user_id BIGINT,
amount DOUBLE,
status STRING,
event_time TIMESTAMP_LTZ(3), -- Kafka record timestamp (milliseconds)
-- Metadata columns
kafka_offset BIGINT METADATA FROM 'offset' VIRTUAL,
kafka_part INT METADATA FROM 'partition' VIRTUAL,
kafka_ts TIMESTAMP_LTZ(3) METADATA FROM 'timestamp' VIRTUAL,
-- Event-time watermark: tolerate 30s late arrivals
WATERMARK FOR event_time AS event_time - INTERVAL '30' SECOND
)
WITH (
'connector' = 'kafka',
'topic' = 'orders',
'properties.bootstrap.servers' = 'broker:9092',
'properties.group.id' = 'flink-orders-consumer',
'scan.startup.mode' = 'earliest-offset',
'value.format' = 'json',
'value.json.ignore-parse-errors' = 'true'
)
""")

Kafka source options:

OptionDescription
scan.startup.modegroup-offsets / earliest-offset / latest-offset / timestamp / specific-offsets
scan.startup.timestamp-millisEpoch ms when scan.startup.mode=timestamp
properties.*Pass any Kafka consumer property via this prefix
value.formatjson / avro / avro-confluent / debezium-json / canal-json / csv
key.formatFormat for message key
key.fieldsSemicolon-separated key fields
Kafka Source — Debezium CDC Format
python
t_env.execute_sql("""
CREATE TABLE customers_cdc (
customer_id BIGINT,
name STRING,
email STRING,
PRIMARY KEY (customer_id) NOT ENFORCED
)
WITH (
'connector' = 'kafka',
'topic' = 'cdc.public.customers',
'properties.bootstrap.servers' = 'broker:9092',
'properties.group.id' = 'flink-cdc-consumer',
'scan.startup.mode' = 'earliest-offset',
'value.format' = 'debezium-json'
)
""")
-- Flink automatically applies INSERT/UPDATE/DELETE semantics from Debezium envelope
Kafka Sink — DDL
python
t_env.execute_sql("""
CREATE TABLE orders_enriched_kafka (
order_id BIGINT,
user_id BIGINT,
amount DOUBLE,
status STRING,
region STRING,
PRIMARY KEY (order_id) NOT ENFORCED
)
WITH (
'connector' = 'kafka',
'topic' = 'orders-enriched',
'properties.bootstrap.servers' = 'broker:9092',
'key.format' = 'json',
'key.fields' = 'order_id',
'value.format' = 'json',
'sink.delivery-guarantee' = 'exactly-once',
'sink.transactional-id-prefix' = 'flink-orders-sink',
'sink.parallelism' = '4'
)
""")

Sink delivery guarantees:

ModeSemanticsRequires
noneBest effort—
at-least-once (default)No loss, possible duplicates—
exactly-onceNo loss, no duplicatesKafka transactions, transactional-id-prefix
Filesystem Source / Sink
python
t_env.execute_sql("""
CREATE TABLE orders_parquet (
order_id BIGINT,
user_id BIGINT,
amount DOUBLE,
status STRING,
dt STRING
)
PARTITIONED BY (dt)
WITH (
'connector' = 'filesystem',
'path' = 's3://datalake/bronze/orders/',
'format' = 'parquet',
'sink.rolling-policy.rollover-interval' = '10 min',
'sink.rolling-policy.check-interval' = '1 min',
'sink.partition-commit.trigger' = 'partition-time',
'sink.partition-commit.delay' = '1 h',
'sink.partition-commit.policy.kind' = 'success-file'
)
""")
Iceberg Sink
python
t_env.execute_sql("""
CREATE CATALOG iceberg_catalog WITH (
'type' = 'iceberg',
'catalog-type' = 'rest',
'uri' = 'http://iceberg-rest:8181',
'warehouse' = 's3://datalake/'
)
""")
t_env.execute_sql("USE CATALOG iceberg_catalog")
t_env.execute_sql("USE silver")
# Write stream to Iceberg table
t_env.execute_sql("""
INSERT INTO silver.orders
SELECT order_id, user_id, amount, status, event_time
FROM orders_kafka
""")

Windowing (SQL)

TUMBLE — Non-overlapping fixed windows
sql
-- Count orders per 5-minute tumbling window, per status
SELECT
window_start,
window_end,
status,
COUNT(*) AS cnt,
SUM(amount) AS total_amount
FROM TABLE(
TUMBLE(TABLE orders_kafka, DESCRIPTOR(event_time), INTERVAL '5' MINUTES)
)
GROUP BY window_start, window_end, status;
HOP (Sliding) — Overlapping windows
sql
-- 10-min windows sliding every 5 min (each event appears in 2 windows)
SELECT
window_start,
window_end,
user_id,
COUNT(*) AS cnt
FROM TABLE(
HOP(TABLE orders_kafka, DESCRIPTOR(event_time),
INTERVAL '5' MINUTES, -- slide
INTERVAL '10' MINUTES) -- size
)
GROUP BY window_start, window_end, user_id;
SESSION — Inactivity-based windows
sql
-- User session window: new session after 10 min of inactivity
SELECT
window_start,
window_end,
user_id,
COUNT(*) AS events,
SUM(amount) AS session_revenue
FROM TABLE(
SESSION(TABLE orders_kafka, DESCRIPTOR(event_time),
PARTITION BY user_id,
GAP => INTERVAL '10' MINUTES)
)
GROUP BY window_start, window_end, user_id;
Cumulate Window — Running totals within period
sql
-- Running total within each day, updated every 10 min
SELECT
window_start, window_end,
status,
COUNT(*) AS cnt
FROM TABLE(
CUMULATE(TABLE orders_kafka, DESCRIPTOR(event_time),
INTERVAL '10' MINUTES, -- step
INTERVAL '1' DAY) -- max size
)
GROUP BY window_start, window_end, status;

Watermarks

In DDL
python
t_env.execute_sql("""
CREATE TABLE events (
user_id BIGINT,
event_time TIMESTAMP_LTZ(3),
WATERMARK FOR event_time AS event_time - INTERVAL '10' SECOND
) WITH (...)
""")
-- Bounded out-of-orderness: advance watermark = max_event_time - 10s
-- Any event with ts < watermark is "late" and may be dropped
In DataStream API
python
from pyflink.datastream import WatermarkStrategy
from pyflink.common.watermark_strategy import Duration
# Bounded out-of-orderness (10 second tolerance)
watermark_strategy = (
WatermarkStrategy
.for_bounded_out_of_orderness(Duration.of_seconds(10))
.with_timestamp_assigner(
lambda event, _: event.event_time_ms # return epoch ms
)
.with_idle_source_timeout(Duration.of_minutes(5)) # advance watermark if source goes idle
)

DataStream API (Stateful / Low-Level)

Basic Pipeline
python
from pyflink.datastream import StreamExecutionEnvironment, RuntimeExecutionMode
from pyflink.datastream.connectors.kafka import KafkaSource, KafkaOffsetsInitializer
from pyflink.common import WatermarkStrategy, Types
from pyflink.common.serialization import SimpleStringSchema
env = StreamExecutionEnvironment.get_execution_environment()
env.set_parallelism(4)
env.get_checkpoint_config().enable_checkpointing(60_000) # 60s interval
env.get_checkpoint_config().set_checkpointing_mode(CheckpointingMode.EXACTLY_ONCE)
# Add connector JAR
env.add_jars("file:///opt/flink/lib/flink-connector-kafka-3.3.0-1.20.jar")
# Kafka source
source = (
KafkaSource.builder()
.set_bootstrap_servers("broker:9092")
.set_topics("orders")
.set_group_id("flink-datastream-consumer")
.set_starting_offsets(KafkaOffsetsInitializer.earliest())
.set_value_only_deserializer(SimpleStringSchema())
.build()
)
stream = env.from_source(
source=source,
watermark_strategy=WatermarkStrategy.no_watermarks(),
source_name="orders-kafka",
)
KeyedStream + Stateful ProcessFunction
python
from pyflink.datastream import KeyedProcessFunction, TimerService
from pyflink.datastream.state import ValueStateDescriptor
from pyflink.common import Types
import json
class OrderSessionDetector(KeyedProcessFunction):
"""Detects order sessions: emits session summary after 10 min inactivity per user."""
SESSION_TIMEOUT_MS = 10 * 60 * 1000 # 10 minutes
def open(self, runtime_context):
# State: last seen event time per user
self.last_event_state = runtime_context.get_state(
ValueStateDescriptor("last_event_ts", Types.LONG())
)
# State: order count in current session
self.order_count_state = runtime_context.get_state(
ValueStateDescriptor("order_count", Types.INT())
)
def process_element(self, value, ctx: KeyedProcessFunction.Context, out):
order = json.loads(value)
current_ts = ctx.timestamp()
# Update state
self.last_event_state.update(current_ts)
count = self.order_count_state.value() or 0
self.order_count_state.update(count + 1)

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ivanshamaev/de-agent-skills/apache-flink/badge)](https://verified-skill.com/skills/ivanshamaev/de-agent-skills/apache-flink)

Something wrong with this skill or its page? Tell us.