O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Stream Processing with Apache Flink

Book Description

Get started with Apache Flink, the open source framework that powers some of the world’s largest stream processing applications. With this practical book, you’ll explore the fundamental concepts of parallel stream processing and discover how this technology differs from traditional batch data processing.

Longtime Apache Flink committers Fabian Hueske and Vasia Kalavri show you how to implement scalable streaming applications with Flink’s DataStream API and continuously run and maintain these applications in operational environments. Stream processing is ideal for many use cases, including low-latency ETL, streaming analytics, and real-time dashboards as well as fraud detection, anomaly detection, and alerting. You can process continuous data of any kind, including user interactions, financial transactions, and IoT data, as soon as you generate them.

  • Learn concepts and challenges of distributed stateful stream processing
  • Explore Flink’s system architecture, including its event-time processing mode and fault-tolerance model
  • Understand the fundamentals and building blocks of the DataStream API, including its time-based and statefuloperators
  • Read data from and write data to external systems with exactly-once consistency
  • Deploy and configure Flink clusters
  • Operate continuously running streaming applications

Table of Contents

  1. Preface
    1. What You Will Learn in This Book
    2. Conventions Used in This Book
    3. Using Code Examples
    4. O’Reilly Online Learning
    5. How to Contact Us
    6. Acknowledgments
  2. 1. Introduction to Stateful Stream Processing
    1. Traditional Data Infrastructures
      1. Transactional Processing
      2. Analytical Processing
    2. Stateful Stream Processing
      1. Event-Driven Applications
      2. Data Pipelines
      3. Streaming Analytics
    3. The Evolution of Open Source Stream Processing
      1. A Bit of History
    4. A Quick Look at Flink
      1. Running Your First Flink Application
    5. Summary
  3. 2. Stream Processing Fundamentals
    1. Introduction to Dataflow Programming
      1. Dataflow Graphs
      2. Data Parallelism and Task Parallelism
      3. Data Exchange Strategies
    2. Processing Streams in Parallel
      1. Latency and Throughput
      2. Operations on Data Streams
    3. Time Semantics
      1. What Does One Minute Mean in Stream Processing?
      2. Processing Time
      3. Event Time
      4. Watermarks
      5. Processing Time Versus Event Time
    4. State and Consistency Models
      1. Task Failures
      2. Result Guarantees
    5. Summary
  4. 3. The Architecture of Apache Flink
    1. System Architecture
      1. Components of a Flink Setup
      2. Application Deployment
      3. Task Execution
      4. Highly Available Setup
    2. Data Transfer in Flink
      1. Credit-Based Flow Control
      2. Task Chaining
    3. Event-Time Processing
      1. Timestamps
      2. Watermarks
      3. Watermark Propagation and Event Time
      4. Timestamp Assignment and Watermark Generation
    4. State Management
      1. Operator State
      2. Keyed State
      3. State Backends
      4. Scaling Stateful Operators
    5. Checkpoints, Savepoints, and State Recovery
      1. Consistent Checkpoints
      2. Recovery from a Consistent Checkpoint
      3. Flink’s Checkpointing Algorithm
      4. Performace Implications of Checkpointing
      5. Savepoints
    6. Summary
  5. 4. Setting Up a Development Environment for Apache Flink
    1. Required Software
    2. Run and Debug Flink Applications in an IDE
      1. Import the Book’s Examples in an IDE
      2. Run Flink Applications in an IDE
      3. Debug Flink Applications in an IDE
    3. Bootstrap a Flink Maven Project
    4. Summary
  6. 5. The DataStream API (v1.7)
    1. Hello, Flink!
      1. Set Up the Execution Environment
      2. Read an Input Stream
      3. Apply Transformations
      4. Output the Result
      5. Execute
    2. Transformations
      1. Basic Transformations
      2. KeyedStream Transformations
      3. Multistream Transformations
      4. Distribution Transformations
    3. Setting the Parallelism
    4. Types
      1. Supported Data Types
      2. Creating Type Information for Data Types
      3. Explicitly Providing Type Information
    5. Defining Keys and Referencing Fields
      1. Field Positions
      2. Field Expressions
      3. Key Selectors
    6. Implementing Functions
      1. Function Classes
      2. Lambda Functions
      3. Rich Functions
    7. Including External and Flink Dependencies
    8. Summary
  7. 6. Time-Based and Window Operators
    1. Configuring Time Characteristics
      1. Assigning Timestamps and Generating Watermarks
      2. Watermarks, Latency, and Completeness
    2. Process Functions
      1. TimerService and Timers
      2. Emitting to Side Outputs
      3. CoProcessFunction
    3. Window Operators
      1. Defining Window Operators
      2. Built-in Window Assigners
      3. Applying Functions on Windows
      4. Customizing Window Operators
    4. Joining Streams on Time
      1. Interval Join
      2. Window Join
    5. Handling Late Data
      1. Dropping Late Events
      2. Redirecting Late Events
      3. Updating Results by Including Late Events
    6. Summary
  8. 7. Stateful Operators and Applications
    1. Implementing Stateful Functions
      1. Declaring Keyed State at RuntimeContext
      2. Implementing Operator List State with the ListCheckpointed Interface
      3. Using Connected Broadcast State
      4. Using the CheckpointedFunction Interface
      5. Receiving Notifications About Completed Checkpoints
    2. Enabling Failure Recovery for Stateful Applications
    3. Ensuring the Maintainability of Stateful Applications
      1. Specifying Unique Operator Identifiers
      2. Defining the Maximum Parallelism of Keyed State Operators
    4. Performance and Robustness of Stateful Applications
      1. Choosing a State Backend
      2. Choosing a State Primitive
      3. Preventing Leaking State
    5. Evolving Stateful Applications
      1. Updating an Application without Modifying Existing State
      2. Removing State from an Application
      3. Modifying the State of an Operator
    6. Queryable State
      1. Architecture and Enabling Queryable State
      2. Exposing Queryable State
      3. Querying State from External Applications
    7. Summary
  9. 8. Reading from and Writing to External Systems
    1. Application Consistency Guarantees
      1. Idempotent Writes
      2. Transactional Writes
    2. Provided Connectors
      1. Apache Kafka Source Connector
      2. Apache Kafka Sink Connector
      3. Filesystem Source Connector
      4. Filesystem Sink Connector
      5. Apache Cassandra Sink Connector
    3. Implementing a Custom Source Function
      1. Resettable Source Functions
      2. Source Functions, Timestamps, and Watermarks
    4. Implementing a Custom Sink Function
      1. Idempotent Sink Connectors
      2. Transactional Sink Connectors
    5. Asynchronously Accessing External Systems
    6. Summary
  10. 9. Setting Up Flink for Streaming Applications
    1. Deployment Modes
      1. Standalone Cluster
      2. Docker
      3. Apache Hadoop YARN
      4. Kubernetes
    2. Highly Available Setups
      1. HA Standalone Setup
      2. HA YARN Setup
      3. HA Kubernetes Setup
    3. Integration with Hadoop Components
    4. Filesystem Configuration
    5. System Configuration
      1. Java and Classloading
      2. CPU
      3. Main Memory and Network Buffers
      4. Disk Storage
      5. Checkpointing and State Backends
      6. Security
    6. Summary
  11. 10. Operating Flink and Streaming Applications
    1. Running and Managing Streaming Applications
      1. Savepoints
      2. Managing Applications with the Command-Line Client
      3. Managing Applications with the REST API
      4. Bundling and Deploying Applications in Containers
    2. Controlling Task Scheduling
      1. Controlling Task Chaining
      2. Defining Slot-Sharing Groups
    3. Tuning Checkpointing and Recovery
      1. Configuring Checkpointing
      2. Configuring State Backends
      3. Configuring Recovery
    4. Monitoring Flink Clusters and Applications
      1. Flink Web UI
      2. Metric System
      3. Monitoring Latency
    5. Configuring the Logging Behavior
    6. Summary
  12. 11. Where to Go from Here?
    1. The Rest of the Flink Ecosystem
      1. The DataSet API for Batch Processing
      2. Table API and SQL for Relational Analysis
      3. FlinkCEP for Complex Event Processing and Pattern Matching
      4. Gelly for Graph Processing
    2. A Welcoming Community
  13. Index