Learn Apache Flink - Real-time Analytics & Use Cases
Episode 20 of 23

Learn Apache Flink - Real-time Analytics & Use Cases

This episode weaves all the skills into real use cases: monitoring and alerting dashboards, fraud detection, real-time recommendation, and IoT processing. You'll also design an end-to-end streaming pipeline with data enrichment, stream joins, and real-time aggregations.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

Twenty episodes built skills one at a time. Episode 20 is the final exam: how it all comes together in real use cases. Good streaming isn't just running technology — it must produce decisions, alerts, and dashboards that people use every day.

We'll build a monitoring dashboard with alerting, implement fraud detection and real-time recommendation, process IoT data, then design an end-to-end pipeline with data enrichment, stream joins, and real-time aggregation. This is the map for translating Flink into business value.

Monitoring and Alerting Dashboards

Metrics to Grafana

A monitoring dashboard is built from metrics exported to Prometheus (episode 13). From there, Grafana displays trends and rule-based alerts:

Alert rule in Grafana
groups:
  - name: flink-alerts
    rules:
      - alert: JobRestarted
        expr: flink_jobmanager_job_restarts > 0
        for: 1m

flink_jobmanager_job_restarts is the metric counting job restarts. This rule fires an alert when a restart happens — without alerts, a silently restarting job won't be noticed until the problem worsens.

Business Metrics

Besides technical metrics, watch business metrics: transaction volume per minute, failed data ratio, and aggregation latency. Custom metrics built with counters and gauges (episode 13) become the foundation of dashboards that answer business questions, not just infrastructure questions.

Use Case: Fraud Detection

Detecting Suspicious Patterns

Fraud detection combines aggregation and CEP: transactions crossing a threshold within a time window trigger an alert immediately:

Detect consecutive large transactions
SELECT user_id, COUNT(*) AS jumlah, SUM(amount) AS total
FROM transactions
GROUP BY user_id, TUMBLE(event_ts, INTERVAL '10' MINUTE)
HAVING COUNT(*) > 10 AND SUM(amount) > 10000000;

HAVING filters suspicious transaction groups. For subtler sequential patterns — for example two large transactions within one minute — combine with the CEP from episode 10.

Alerting to the Destination System

Detection results aren't the end — send them to the alerting and case management systems:

Run the fraud detection job
./bin/flink run -d target/fraud-job.jar

./bin/flink run -d submits the job. In production, alerts are directed to a Kafka topic consumed by the fraud detection platform, or directly to a paging system for critical cases.

Use Case: Real-time Recommendation

The User's Current Context

Real-time recommendation uses current events, not just batch history: enriching with user data, then stream joins to combine clicks and catalog:

Combine clicks and product catalog
SELECT c.user_id, p.product_name
FROM clicks c
JOIN products FOR SYSTEM_TIME AS OF c.event_ts AS p
ON c.product_id = p.id;

FOR SYSTEM_TIME AS OF ensures the recommendation uses the correct product version at the moment of the click. The results are sinked to a recommendation engine that returns the top-N products for each user.

Scoring and Personalization

Combine click frequency per user (state), favorite categories, and real-time signals into a score. A good recommendation pipeline is always built from stateful aggregation — exactly the pattern you've mastered in episode 6.

Use Case: IoT Processing

Sensors That Never Stop

IoT produces a continuous stream of sensor data: temperature, vibration, energy consumption. Per-minute aggregation per device becomes the basis of monitoring:

Average temperature per sensor
SELECT device_id,
       AVG(temperature) AS rata_temperature,
       MAX(temperature) AS maks
FROM sensor_readings
GROUP BY device_id, TUMBLE(event_ts, INTERVAL '1' MINUTE);

AVG and MAX give a summary per device. Add automatic alerts when maks crosses a threshold — early detection before equipment breaks.

End-to-end Streaming Pipeline

The Complete Architecture

Assemble all the components into one pipeline:

End-to-end pipeline architecture
Kafka → Flink (enrich + join + aggregate) → Kafka → ClickHouse → Grafana

Kafka collects raw events, Flink enriches them with dimensions (temporal join), joins streams, and aggregates; the results go to Kafka to be stored in ClickHouse; Grafana displays the dashboards and fires alerts.

Design Principles

  • Enrich as early as possible: fix data quality before aggregation.
  • One responsibility per pipeline: separate the enrichment pipeline from the aggregation pipeline.
  • Idempotent and replayable: make sure results don't change when events are reprocessed.
Run the analytics pipeline
./bin/flink run -d target/analytics-job.jar

The ./bin/flink run -d command submits the pipeline. From here, the whole value chain — from raw events to business decisions — runs in seconds, not hours.

Conclusion

Episode 20 brought everything together: monitoring dashboards with alerting, fraud detection based on aggregation and CEP, real-time recommendation with enrichment and stream joins, per-sensor IoT processing, and designing an end-to-end pipeline from Kafka to dashboards.

The key takeaways:

  • Metric-based alerts let the system monitor itself.
  • Fraud detection combines window aggregation and CEP patterns.
  • Temporal joins give the correct data version context for enrichment.
  • IoT processing uses per-device aggregation with threshold alerts.
  • End-to-end pipelines are built with early enrichment and one responsibility per job.

In the next episode, episode 21, we'll discuss ecosystem & tooling — integration with Apache Beam, the Flink SQL Gateway, and the State Processor API, tooling like the Flink CLI, web UI, and IDE plugins, community resources and RFCs/FLIPs, and managed cloud offerings. You'll see Flink as part of a broader ecosystem.

Learn Apache Flink - Real-time Analytics & Use Cases | Learn Apache Flink