DEV Community

Cover image for Streaming Data into Amazon Redshift: Kinesis vs. MSK Patterns
Aniket Abhishek Soni
Aniket Abhishek Soni

Posted on AI-assisted

Streaming Data into Amazon Redshift: Kinesis vs. MSK Patterns

You ship your data ingestion pipeline. It passes local integration tests, the schema validation logic holds up in staging, and the throughput metrics look healthy. Then, your Redshift cluster starts hitting transient lock contention, or your downstream analytics dashboards show partial data during high-traffic spikes. You realize that your batch-based ingestion strategy is creating a "micro-batch gap" that prevents real-time decision-making, but moving to streaming ingestion introduces complexities around delivery guarantees and consumer state management that your previous batch jobs never faced.

The solution is to move away from custom polling loops and toward native integration services like Amazon Data Firehose or Managed Service for Apache Flink. This article covers the patterns for ingesting high-volume streams into Amazon Redshift, focusing on when to use managed delivery versus custom stream processing. The scope is limited to streaming ingestion from Kinesis Data Streams and Amazon MSK; it does not cover batch loading from S3 or cross-region replication.

How it actually works

When you ingest from Kinesis or MSK into Redshift, you are essentially choosing between managed, opinionated delivery (Firehose) and custom, stateful processing (Flink).

flowchart LR
    producer["Producer (Kinesis/MSK)"]
    firehose["Amazon Data Firehose"]
    flink["Amazon Managed Service for Apache Flink"]
    redshift["Amazon Redshift"]

    producer --> firehose
    producer --> flink
    firehose --> redshift
    flink --> redshift

The managed approach: Amazon Data Firehose

Firehose acts as a delivery buffer. It polls your Kinesis stream or MSK topic, batches records based on size or time thresholds, and performs an COPY command into Redshift. This is a "set it and forget it" mechanism.

To configure Firehose for Redshift, you must provide a manifest and a staging S3 bucket. Firehose will deliver the data to S3 first, then issue the COPY command.

{
  "RedshiftDestinationConfiguration": {
    "ClusterJDBCURL": "jdbc:redshift://<cluster-endpoint>:5439/<db>",
    "CopyCommand": {
      "DataTableName": "public.events",
      "DataTableColumns": "id,payload,timestamp"
    },
    "RoleARN": "arn:aws:iam::<account-id>:role/firehose-delivery-role",
    "S3BackupMode": "Enabled",
    "S3Configuration": {
      "BucketARN": "arn:aws:s3:::<your-bucket>",
      "RoleARN": "arn:aws:iam::<account-id>:role/firehose-delivery-role"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The stateful approach: Managed Service for Apache Flink

If you need to perform windowed aggregations, deduplication, or complex joins before the data touches Redshift, use Flink. Flink maintains the consumer offset and the state internally. You use the Flink Redshift connector to sink data directly into your tables.

// Conceptual snippet for Flink Redshift Sink
RedshiftSink<Record> sink = RedshiftSink.<Record>builder()
    .setJdbcOptions(JdbcOptions.builder()
        .setDBUrl("jdbc:redshift://<endpoint>:5439/<db>")
        .setTableName("public.metrics")
        .build())
    .build();
stream.sinkTo(sink);
Enter fullscreen mode Exit fullscreen mode

Design choices and tradeoffs

Managed Delivery, not Custom Consumers. Use Firehose whenever possible. You trade off granular control for operational simplicity. If you write your own Lambda function to read from Kinesis and push to Redshift, you are responsible for batching logic, error handling, and manual retries. Firehose handles this automatically.

Staging S3, not Direct Injection. Even if you want "streaming," always use S3 as a staging layer. Redshift’s COPY command is highly optimized for S3. Attempting to insert individual rows via INSERT statements from a stream consumer will cripple your Redshift cluster’s performance and likely lead to transaction log bloat.

At-least-once, not Exactly-once. Both Firehose and Flink typically guarantee at-least-once delivery. In a streaming context, duplicates are a mathematical inevitability. Your Redshift schema design must account for this by using an idempotent landing table—load into a staging table, then use a stored procedure to perform a UPSERT (merge) into your final fact table based on a unique event ID.

Failure modes

Symptom: The COPY command fails.
Cause: The most common culprit is schema mismatch. If your incoming JSON doesn't match the table structure or the COPY command options, the transaction will roll back.
Fix: Check the STL_LOAD_ERRORS system table in Redshift. It provides the specific row and column that caused the failure.

Symptom: High latency in data availability.
Cause: If you use Firehose, you may have configured the buffer size (in MB) or buffer interval (in seconds) too high.
Fix: Adjust the "Buffering hints" in your Firehose delivery stream. Note that lowering these settings will increase the frequency of COPY commands, which can pressure your Redshift concurrency slots.

Symptom: Flink application restart loops.
Cause: Checkpointing failures. If your Flink state is too large or the destination Redshift table is locked, the checkpoint will time out, causing Flink to restart and re-process the stream from the last successful checkpoint.
Fix: Ensure your Redshift cluster has enough WLM (Workload Management) slots for the ingestion user to avoid queuing.

When to reach for it (and when not to)

Use Firehose if:

  • You are performing simple ingestion (ETL "Load").
  • Your transformation requirements are minimal (e.g., format conversion like JSON to Parquet).
  • You want the lowest operational overhead.

Use Managed Service for Apache Flink if:

  • You need to perform sliding window calculations (e.g., "average price over the last 5 minutes").
  • You need to join the stream with static data in real-time.
  • You need to deduplicate records before they hit the warehouse.

Do not use streaming ingestion if your analytics use case can tolerate a delay of 15–30 minutes. In those cases, traditional batch processing using AWS Glue or even S3 Event Notifications is more cost-effective and easier to debug.

Conclusion

Streaming data into Redshift requires balancing the need for low latency against the inherent batch-optimized nature of the database. By using Firehose for simple delivery and Flink for complex stateful logic, you can build a robust pipeline that avoids common pitfalls like transaction log bloat and duplicate records.

Your next step is to examine your current COPY execution times in STL_LOAD_COMMITS. If you see high frequency but small row counts, you are likely over-buffering and should adjust your ingestion intervals to batch more effectively.

References

About the examples: automated checks confirmed that the JSON block parses. The examples have not been run end to end, so test them in a non-production environment before relying on them.

Cover photo by Scott Rodgerson on Unsplash.


This article was drafted with AI assistance and is intended for technical review and fact-checking before publication.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The S3-staging rule is the part I would underline for anyone coming from a transactional database — row-by-row INSERTs into Redshift are the silent killer, and your STL_LOAD_COMMITS check at the end is the right diagnostic: high-frequency, small-row-count COPYs are the fingerprint of an over-eager buffer. The one trade-off I would push on is the at-least-once UPSERT advice: with a Firehose buffer, a retry after a partial COPY can re-deliver a whole batch, so the merge key has to be genuinely unique per event, not per batch. Did you ever hit a case where the event ID itself was the thing that duplicated, and how did you make the dedupe survive that?