Study Guide1,085 words

AWS Streaming Data Ingestion for Machine Learning

How to use AWS streaming data sources to ingest data (for example, Amazon Kinesis, Apache Flink, Apache Kafka)

AWS Streaming Data Ingestion for Machine Learning

This guide explores how to leverage AWS streaming services—Amazon Kinesis, Amazon Managed Streaming for Apache Kafka (MSK), and Amazon Managed Service for Apache Flink—to ingest and process data for real-time machine learning workflows.

Learning Objectives

After studying this guide, you should be able to:

  • Differentiate between Amazon Kinesis Data Streams and Amazon Data Firehose.
  • Explain the use cases for Amazon Managed Service for Apache Flink in an ML pipeline.
  • Compare and contrast Amazon Kinesis and Amazon MSK for streaming ingestion.
  • Identify the most efficient ingestion path for specific data formats (e.g., CSV to Parquet).
  • Select the appropriate AWS service for real-time inference and feature engineering.

Key Terms & Glossary

  • Streaming Data: Data that is generated continuously by thousands of data sources, typically sent in small sizes (kilobytes).
  • Producer: An application or device that sends data records to a streaming service (e.g., a mobile app, IoT sensor).
  • Consumer: An application that processes data from a stream (e.g., an ML model endpoint or a Flink application).
  • Shard: The base unit of throughput in a Kinesis Data Stream; provides a fixed capacity of 1MB/sec input and 2MB/sec output.
  • Partition: In Apache Kafka, the unit of parallelism and scale, similar to a Kinesis shard.
  • Stateful Computation: Processing that remembers information across multiple events, critical for windowed calculations like "average spending over the last 5 minutes."

The "Big Idea"

In traditional ML, data is processed in batches (e.g., nightly ETL). However, modern ML requires Real-Time Data Ingestion to support immediate decision-making. Streaming ingestion bridges the gap between raw event generation (clickstreams, logs) and model inference. By moving data through a pipeline that enriches and transforms it in motion, we can feed "fresh" features into SageMaker models for real-time predictions, such as fraud detection or dynamic pricing.

Formula / Concept Box

ConceptMetric / RuleKey Implication
Kinesis Shard Limit1 MB/s InScaling requires adding more shards if throughput exceeds 1MB/s.
Kinesis Put-to-Get Delay< 1 SecondEnables near-real-time consumption of data.
Exactly-Once ProcessingApache Flink GuaranteeEnsures that data is processed once and only once, preventing duplicates in ML features.
Format ConversionFirehose + LambdaBest for converting CSV/JSON to Parquet/ORC for efficient S3 storage.

Hierarchical Outline

  • Amazon Kinesis Ecosystem
    • Kinesis Data Streams (KDS): Low-latency, custom processing, requires manual scaling/sharding.
    • Kinesis Data Firehose: Fully managed, auto-scaling, delivers to S3/Redshift/OpenSearch.
    • Kinesis Video Streams: For ingesting and storing video/audio for ML computer vision.
  • Amazon Managed Streaming for Apache Kafka (MSK)
    • Managed Kafka clusters for users migrating existing Kafka applications.
    • High throughput, requires deeper Kafka knowledge than Kinesis.
  • Amazon Managed Service for Apache Flink
    • Real-time transformation and feature engineering.
    • Interactively query streams using SQL or Java/Python APIs.

Visual Anchors

Streaming ML Architecture

This diagram shows the flow from raw data sources to a model endpoint.

Loading Diagram...

Kinesis Data Stream Structure

A visualization of how shards manage parallel data flow.

\begin{tikzpicture}[node distance=1cm, auto] \draw[thick] (0,0) rectangle (4,0.8) node[midway] {Shard 1 (1MB/s)}; \draw[thick] (0,1) rectangle (4,1.8) node[midway] {Shard 2 (1MB/s)}; \draw[thick] (0,2) rectangle (4,2.8) node[midway] {Shard 3 (1MB/s)}; \draw[->, thick] (-1.5, 1.4) -- node[above] {Producers} (0, 1.4); \draw[->, thick] (4, 1.4) -- node[above] {Consumers} (5.5, 1.4); \node at (2, -0.5) {Elastic Scaling: Add/Remove Shards}; \end{tikzpicture}

Definition-Example Pairs

  • Kinesis Data Streams
    Definition: A scalable service for custom real-time data processing applications.
    Example: Capturing real-time website clickstream data to update a "trending now" recommendation model every few seconds.

  • Kinesis Data Firehose
    Definition: A fully managed service to load streaming data into AWS data stores with optional transformation.
    Example: Taking incoming JSON log data, using a Lambda function to convert it to Parquet, and saving it to S3 for a weekly training job.

  • Apache Flink (Managed Service)
    Definition: A framework for stateful computations over data streams.
    Example: Calculating a rolling average of sensor temperatures over a 10-minute window to detect anomalies in industrial machinery.

Worked Examples

Example 1: Format Conversion for Data Lakes

Problem: An application generates CSV data. You need to store it in S3 as Parquet to save costs on Athena queries for ML preprocessing. Solution:

  1. Ingest: Use Amazon Data Firehose to receive the CSV records.
  2. Transform: Configure Firehose to trigger an AWS Lambda function.
  3. Code: The Lambda function converts the CSV buffer to Parquet format.
  4. Store: Firehose writes the Parquet files to S3 with partitioned prefixes (e.g., yyyy/mm/dd).

Example 2: Real-Time Fraud Detection

Problem: A credit card company needs to flag transactions as fraudulent within seconds of the swipe. Solution:

  1. Ingest: Transaction data is sent to a Kinesis Data Stream.
  2. Process: An Apache Flink application reads the stream and performs feature engineering (e.g., "Has this card been used in two different cities in the last 10 minutes?").
  3. Inference: The Flink app calls a SageMaker hosted endpoint with the generated features.
  4. Action: If the model returns a high fraud probability, a message is sent to an SNS topic to block the card.

Checkpoint Questions

  1. True or False: Amazon Managed Service for Apache Flink provides its own internal data storage system for long-term persistence.
  2. Which service is the most cost-effective for loading geolocation data into Amazon Redshift for near-real-time analytics?
  3. What is the primary difference between Kinesis Data Streams and Kinesis Data Firehose regarding scaling?
  4. If you have an existing on-premises Kafka cluster and want to migrate to AWS with minimal code changes, which service should you use?
Click to see Answers
  1. False. Flink does not have its own storage; it integrates with S3, Kinesis, or MSK for state and data management.
  2. Amazon Data Firehose (using Redshift Streaming Ingestion or direct COPY).
  3. KDS requires manual shard management (scaling up/down), while Firehose scales automatically based on data volume.
  4. Amazon MSK (Managed Streaming for Apache Kafka).

Muddy Points & Cross-Refs

[!IMPORTANT] Kinesis vs. MSK Choice: Students often confuse when to use which. Use Kinesis for AWS-native apps and easy integration. Use MSK if you are already using Kafka or need specific Kafka features (like headers or complex topic configurations).

[!TIP] Flink vs. Lambda: Use Flink for complex, stateful time-windowed operations. Use Lambda (via Firehose or KDS) for simple, record-by-record transformations.

Comparison Tables

FeatureKinesis Data StreamsKinesis Data FirehoseAmazon MSK
ManagementManaged (Manual Sharding)Fully Managed (Auto-scaling)Managed (Cluster-based)
Latency< 200ms60 seconds (buffer-dependent)< 100ms
Data Retention24 hours to 365 daysNo retention (transient)Configurable (unlimited)
ML Use CaseReal-time feature extractionBatch/Near-real-time ingestionHigh-throughput Kafka apps

Ready to study AWS Certified Machine Learning Engineer - Associate (MLA-C01)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free