VAYULearn
Colour theme
Investigate a failure
VAYU Learn

AWS Data Engineering

Amazon Kinesis: Real-Time Streaming on AWS

DataForge AWS Data Engineering Series - Blog 8 of 20

AWS Data EngineeringKafka & Streaming

The consumer had been running fine for months. Then, over the course of one Tuesday afternoon, records started arriving late — first by seconds, then by minutes, then by hours. Nobody had changed the consumer code. Nobody had changed the producer. The stream’s IteratorAgeMilliseconds metric, if anyone had been watching it, would have shown the problem building for hours before it became visible downstream.

The actual cause: a marketing campaign had doubled event volume overnight, pushing the stream past the throughput a single shard could handle. The shard didn’t reject the extra records — it accepted them, but the consumer, bound by that same shard’s read throughput limit, fell further behind with every batch. By the time someone noticed the dashboard was showing stale data, the consumer was four hours behind real time, and catching up took most of the next day.

This is the defining characteristic of Kinesis failures: shard capacity limits don’t produce errors when exceeded on the write side — they produce growing lag on the read side, invisible unless you’re specifically watching for it, and the fix (adding shards) doesn’t happen automatically unless you’ve configured it to.

Let’s go deep.


TL;DR

Kinesis Data Streams is AWS’s native real-time streaming service, built around shards — fixed units of throughput capacity (1MB/s write, 2MB/s read each) that you provision explicitly unless using on-demand mode. Understanding how shards, sequence numbers, and consumer checkpointing actually work is what separates pipelines that scale gracefully from pipelines that silently accumulate lag until someone notices stale data downstream. Kinesis Data Firehose and Kinesis Data Analytics extend the base service for specific patterns — managed delivery to S3, and real-time SQL/Flink processing — that solve different problems than raw Kinesis Data Streams.

By the end of this article you’ll be able to:

  • Explain shard capacity limits precisely and calculate whether your stream is correctly provisioned
  • Understand how consumer checkpointing and sequence numbers provide exactly-once-adjacent processing guarantees
  • Choose correctly between Kinesis Data Streams, Firehose, and Kinesis Analytics for a given use case
  • Diagnose consumer lag before it becomes a downstream data freshness incident

Series context: This is the first of two streaming articles - Blog 9 covers MSK (managed Kafka) as the alternative streaming platform. Both build on IAM (Blog 3) and VPC networking (Blog 4) for producer/consumer access patterns.

One hot partition key hashes to one shard, always - more total shards doesn’t help. That shard throttles while the lag climbs silently for hours, invisible unless someone is watching IteratorAgeMilliseconds before the dashboard goes stale.

What a Shard Actually Is

A shard is Kinesis’s fundamental unit of throughput capacity. Every architectural decision about Kinesis traces back to understanding exactly what one shard can and cannot do.

Per shard, per second:
Write capacity: 1MB/s, or 1,000 records/s (whichever
limit is hit first)
Read capacity: 2MB/s, or 5 GetRecords calls/s
shared across ALL consumers reading
that shard (unless using Enhanced
Fan-Out, covered below)
A stream is a collection of shards. Total stream
throughput = number of shards x per-shard limits.
Example: a stream with 10 shards provides:
Write: 10MB/s or 10,000 records/s aggregate
Read: 20MB/s aggregate, shared across consumers

The critical detail that catches teams off guard: these limits are per-shard, not per-stream in the way people initially assume, and a single “hot” partition key can exceed a shard’s limit even when the stream’s aggregate capacity looks sufficient. Records are assigned to shards based on a hash of their partition key — if one partition key (say, a single high-volume customer ID) represents a disproportionate share of traffic, every record with that key lands on the same shard, and that shard can be throttled even while other shards in the same stream sit mostly idle.


How Records Actually Get to a Shard: The Mechanism

This is the mechanism worth understanding precisely, because the opening scenario’s silent lag accumulation traces directly back to shard-level throughput being exceeded without anyone realizing which shard, or why.

Producer sends a record with partition_key = "customer_A"
Step 1: Kinesis computes MD5 hash of the partition key
hash("customer_A") = some large number
Step 2: The stream's shard hash key ranges determine
which shard owns this hash value
Shard 1: hash range 0 to 999999
Shard 2: hash range 1000000 to 1999999
Shard 3: hash range 2000000 to 2999999
...
If hash("customer_A") falls in Shard 2's range,
EVERY record with partition_key = "customer_A"
goes to Shard 2, always, deterministically.
Step 3: Shard 2 accepts the write if it's within its
1MB/s / 1,000 records/s limit for the current
one-second window
Step 4: If Shard 2 is at capacity, the write is
THROTTLED (ProvisionedThroughputExceededException)
- NOT silently dropped, but the producer must
handle the exception (typically with retry +
backoff)
The failure mode: if customer_A is a very high-volume
customer, and many other customers' records ALSO happen
to hash into Shard 2's range, Shard 2 can be throttled
constantly while Shard 5, handling low-volume customers,
sits nearly empty.

Why this produces the opening scenario’s symptom: throttled writes on the producer side get retried, adding latency but not necessarily failing outright (most SDK implementations retry automatically). But if the aggregate stream volume genuinely exceeds total shard capacity — not just one hot shard — records queue up waiting for capacity, and the consumer side experiences this as growing distance between “when a record was written” and “when the consumer actually processed it.” This is IteratorAgeMilliseconds, the single most important CloudWatch metric for any Kinesis consumer, and it's the metric almost nobody dashboards until after their first lag incident.


Consumer Checkpointing: How “Exactly-Once-Adjacent” Actually Works

Kinesis doesn’t provide true exactly-once processing out of the box — it provides at-least-once delivery, and the consumer’s checkpointing discipline is what determines how close to exactly-once the overall pipeline behaves.

Kinesis Client Library (KCL) checkpoint pattern:
Consumer reads a batch of records from a shard
Consumer processes the batch (writes to S3,
triggers downstream logic, etc.)
Consumer explicitly calls checkpoint() AFTER
successful processing, recording the sequence
number of the last successfully processed record
If the consumer crashes BEFORE checkpointing:
On restart, it resumes from the LAST CHECKPOINT,
re-reading and re-processing records that were
already handled before the crash
-> at-least-once delivery (possible duplicates)
If the consumer checkpoints BEFORE fully processing
(a common mistake - checkpointing too early):

On restart after a crash mid-processing, those
records are considered "done" and are NEVER
re-read
-> silent data loss, the more dangerous failure
mode because nothing errors

The correct checkpointing discipline, stated as a rule: checkpoint only after the batch has been durably processed downstream (written to S3, committed to a database, etc.) — never checkpoint as a side effect of merely reading the batch. This is the identical idempotency and ordering discipline covered in the Databricks series regarding MERGE and stable business keys — downstream consumers must be able to tolerate reprocessing the same record without producing incorrect duplicate state.

# Correct pattern: process fully, then checkpoint
for record_batch in shard_iterator:
write_to_s3(record_batch) # durable write completes first
checkpoint(record_batch.last_sequence_number) # then checkpoint

# Incorrect pattern: checkpoint before processing completes
for record_batch in shard_iterator:
checkpoint(record_batch.last_sequence_number) # WRONG -
# if write_to_s3
# fails after this,
# data is lost
write_to_s3(record_batch)

Enhanced Fan-Out: Solving the Shared Read Throughput Problem

The default 2MB/s read limit per shard is shared across every consumer reading that shard. Two consumers reading the same shard split that 2MB/s between them — not each getting their own 2MB/s.

Standard consumers (shared throughput):
Shard read limit: 2MB/s TOTAL, shared
3 consumers reading the same shard:
each effectively gets ~0.67MB/s in practice,
and they compete for the 5 GetRecords/s call limit
Enhanced Fan-Out (EFO):
Each registered consumer gets its OWN dedicated
2MB/s read throughput per shard
Uses HTTP/2 push instead of polling - lower latency
(typically ~70ms vs the ~200ms polling interval)
Additional cost: per-consumer-shard-hour charge,
plus data retrieval charges

When Enhanced Fan-Out is worth the extra cost: multiple independent consumer applications need to read the same stream at full throughput simultaneously — for example, one consumer writing to S3 for archival, another triggering real-time alerts, and a third feeding a live dashboard. Without EFO, these three consumers compete for the same shared 2MB/s, and all three fall behind under load. With EFO, each gets dedicated throughput.

When it’s unnecessary complexity: a single consumer application, or multiple consumers where aggregate read volume comfortably fits within the shared 2MB/s limit. Adding EFO here adds cost without solving a problem that exists.


Kinesis Data Firehose: Managed Delivery, No Consumer Code

Firehose is a separate but related service — instead of writing consumer code that reads from shards and checkpoints manually, Firehose manages delivery to a destination (S3, Redshift, OpenSearch, Splunk) automatically.

Firehose delivery pattern:
Producer -> Firehose delivery stream -> automatic
buffering (by size or time interval) ->
automatic delivery to destination
Configuration:
Buffer size: e.g., 5MB
Buffer interval: e.g., 60 seconds
Whichever threshold is hit FIRST triggers delivery
Larger buffer = fewer, larger files delivered to S3
(better for Blog 2's file layout
principles - avoids the small-file
problem)
Smaller buffer = lower latency, but more files
(worse for downstream Athena/Glue
costs, per Blog 2)

The direct connection to Blog 2: Firehose’s buffer configuration is exactly the small-file-vs-latency trade-off from Blog 2, expressed as an ingestion parameter. A Firehose stream configured with a 60-second/1MB buffer delivering continuously will create the exact file-count explosion described in Blog 2’s small file cost calculation — and the fix is the same principle: larger buffers, fewer and bigger files, unless genuine sub-minute latency is a hard requirement that justifies the downstream cost.

Firehose does NOT require:
Shard management (Firehose scales automatically
based on throughput, no manual shard provisioning)
Consumer code (no checkpointing, no KCL, no
custom application logic for the delivery path)
Firehose is NOT appropriate when:
You need custom processing logic before delivery
beyond simple transformations (though Firehose
does support Lambda-based inline transformation)
You need sub-second latency (Firehose's minimum
buffer interval floor adds inherent latency)
You need multiple independent consumers reading
the same data with different processing logic
(Firehose is a single delivery pipe, not a
multi-consumer stream)

Kinesis Data Analytics: SQL and Flink on Streaming Data

Kinesis Data Analytics runs continuous SQL queries or Apache Flink applications directly against streaming data, producing output to another stream, Firehose, or a Lambda function.

Use case pattern:
Kinesis Data Stream (raw events)
|
v
Kinesis Data Analytics
(windowed aggregation: "count events per
5-minute tumbling window, grouped by region")
|
v
Output: another Kinesis stream, or Firehose to S3
Correct for:
Real-time anomaly detection
Streaming aggregations (running totals, moving
averages) that need to be available with
sub-minute latency
Complex event processing (pattern matching across
a sequence of events)
Not correct for:
Simple delivery with no transformation (use
Firehose instead - far simpler and cheaper)
Batch-style aggregations where a few minutes of
latency is acceptable (a scheduled Athena query
or Glue job is simpler and often cheaper, per
Blog 7's decision framework)

Kinesis vs MSK: The Decision Preview

Blog 9 covers MSK (managed Kafka) in full depth, but the decision boundary is worth stating here since it directly affects whether Kinesis is the right starting point at all.

Choose Kinesis when:
Starting fresh on AWS with no existing Kafka
investment
Want AWS-native integration (IAM auth, tighter
CloudWatch integration, simpler Firehose delivery)
Team doesn't have Kafka operational expertise
Shard-based capacity planning is acceptable
Choose MSK when:
Already running Kafka and want to migrate without
rewriting producer/consumer code
Need Kafka Connect's ecosystem of pre-built
connectors
Need Kafka-specific semantics (consumer groups,
exactly-once semantics via transactions) that
Kinesis doesn't directly replicate
Team already has Kafka operational expertise

Architecture Flow: A Complete Kinesis Pipeline

Producers (web app, IoT devices, application logs)
|
| PutRecord / PutRecords, partition_key chosen
| deliberately to avoid hot-sharding
v
+-------------------------------------------------+
| Kinesis Data Stream |
| N shards, each: 1MB/s write, 2MB/s read |
| Monitor: IteratorAgeMilliseconds, |
| WriteProvisionedThroughputExceeded |
+----------+-----------------------+--------------+
| |
v v
Kinesis Data Analytics Kinesis Data Firehose
(real-time aggregation, (buffered delivery,
windowed queries) no consumer code)
| |
v v
Output stream/Lambda S3 (Blog 2's partitioning
and format principles
apply to the delivered files)

Failure Modes You’ll See in Production

Shard throughput exceeded without anyone monitoring IteratorAgeMilliseconds. The opening scenario. Stream volume grows past provisioned shard capacity. Writes get throttled and retried; consumers fall behind. Nothing errors outright — the system degrades gradually, and without a dashboard on consumer lag, the first signal anyone gets is a downstream complaint about stale data.

Hot partition key concentrating load on one shard. A stream partitions by customer_id, and one enterprise customer generates 40% of total event volume. That customer's events all hash to the same shard, which gets throttled constantly while eight other shards handle the remaining 60% of volume comfortably. Adding more shards to the stream doesn't fix this — the hot key still hashes to one shard regardless of how many total shards exist, unless the partition key strategy itself changes.

Consumer checkpointing before processing completes. A consumer application checkpoints immediately after reading a batch, before the batch has been durably written downstream. A crash between the checkpoint and the write causes silent data loss — those records are never re-read because the checkpoint already marked them as done, and nothing indicates data went missing.

Firehose buffer configured for minimum latency, creating a small-file problem. A team sets Firehose’s buffer interval to 60 seconds (near the practical minimum) to minimize latency, without considering that this creates 1,440 files/day landing in S3 — directly triggering Blog 2’s small-file cost and performance problems in every downstream Athena query against that data.

Enhanced Fan-Out enabled for a single consumer, adding unnecessary cost. A team enables EFO defensively, assuming it’s a best practice, for a pipeline with exactly one consumer application comfortably within the shared 2MB/s limit. The per-consumer-shard-hour charge accumulates with no corresponding benefit, because there was never a shared-throughput contention problem to solve.

On-demand mode assumed to eliminate all capacity planning. A team switches to Kinesis on-demand mode (which auto-scales shard count) assuming this removes the need to think about throughput at all. On-demand mode still has scaling limits and can take time to scale up during sudden extreme spikes — it reduces but doesn’t eliminate the need to understand shard-level throughput behavior, particularly for hot-key scenarios which auto-scaling doesn’t solve.


Trade-offs: What Kinesis Optimizes For

Kinesis optimizes for:

  • AWS-native integration — IAM authentication, CloudWatch metrics, tight Firehose/Analytics integration
  • Managed infrastructure — no brokers to patch, no cluster to operate
  • Flexible consumption patterns — multiple independent consumer applications can read the same stream (subject to throughput sharing unless using EFO)
  • Simple delivery via Firehose when no custom processing is needed

Kinesis doesn’t optimize for:

  • Kafka ecosystem compatibility — existing Kafka producers/consumers require rewriting, not just reconfiguring
  • Silent visibility into capacity problems — throttling and lag require deliberate monitoring, they don’t surface automatically
  • True exactly-once semantics out of the box — requires careful consumer-side checkpointing discipline to approximate
  • Cost efficiency at very high, sustained throughput compared to self-managed or MSK Kafka at scale, where the economics can favor the alternative

The honest trade-off: Kinesis provides an easier operational starting point than Kafka/MSK for teams without existing streaming infrastructure, at the cost of requiring precise understanding of shard-level throughput mechanics to avoid the silent-degradation failure mode that defines most Kinesis production incidents.


Real-World Constraints

Shard limits on resharding operations. Splitting or merging shards (to adjust capacity) is not instantaneous and has rate limits on how many resharding operations can occur in a given period. Teams anticipating a predictable traffic spike (a planned marketing campaign, a known seasonal peak) should provision shard capacity ahead of time rather than relying on reactive resharding during the event itself.

Data retention and cost trade-off. Default retention is 24 hours, extendable up to 365 days at additional cost. Extended retention enables replay for reprocessing scenarios (the same replay-from-Bronze principle covered in the Databricks series) but isn’t free — teams should size retention to actual operational reprocessing needs, not default to maximum retention “just in case.”

Cross-account and cross-region consumption requires the same IAM and networking patterns from Blogs 3 and 4.A consumer in a different AWS account or region reading a Kinesis stream needs the resource-based policy and potentially VPC endpoint configuration covered in earlier articles — Kinesis doesn’t introduce new security primitives, it inherits the same IAM and networking foundation as every other service in this series.


What This Means for the Rest of the Series

Blog 9 (MSK): the direct alternative to this article,
for teams already invested in Kafka or
needing Kafka-specific semantics
Blog 10 (Lambda): Lambda functions are a common Kinesis
consumer pattern for event-driven
processing - Blog 10 covers the
Lambda-specific considerations
Blog 15 (Real-time pipeline architecture): assembles
Kinesis,
Firehose, and
S3 into the
complete
end-to-end
pattern this
article
introduced
piece by piece

Summary: The Engineering Lesson

Kinesis’s shard model is simple to describe and easy to misjudge in practice. A shard’s throughput limit is a hard ceiling, and exceeding it doesn’t produce a clean failure — it produces throttling, retries, and growing consumer lag that looks like a downstream problem until someone traces it back to shard capacity.

The Tuesday afternoon lag incident from the opening scenario wasn’t a Kinesis reliability problem. It was a capacity planning gap combined with a monitoring gap — nobody had provisioned for the marketing campaign’s traffic increase, and nobody was watching the one metric (IteratorAgeMilliseconds) that would have shown the problem building hours before it became visible to actual users.

Streaming infrastructure doesn’t fail loudly. It falls behind quietly, and the gap between “still working” and “critically behind” is measured in a metric most teams don’t dashboard until after their first incident.


Next in Series

Blog 9 - AWS MSK: Running Kafka Without Managing Kafka

Kinesis is AWS-native streaming. MSK is managed Apache Kafka — the same Kafka semantics, consumer groups, and ecosystem you’d run yourself, minus the broker management. For teams with existing Kafka investment or needing Kafka-specific capabilities, this is the alternative to everything covered in this article.

We’ll go deep on what “managed” actually means for MSK specifically, MSK Connect for the Kafka Connect ecosystem, and the concrete decision points that determine whether migrating from self-managed Kafka to MSK — or choosing MSK over Kinesis for a new pipeline — is the right call.


Comment Below

What’s the most subtle Kinesis capacity problem you’ve debugged — one that didn’t show up as an obvious error?

Was it a hot partition key concentrating load on a single shard while the rest of the stream sat idle? Consumer lag that built for hours before anyone noticed stale data downstream? A Firehose buffer configuration that seemed reasonable but quietly created a small-file problem across months of accumulated S3 objects?

And — what metric or signal finally revealed what was actually happening?


Tags: aws-data-engineering, amazon-kinesis, streaming, kinesis-firehose, kinesis-data-analytics, shards, real-time-data, dataforge