Amazon Kinesis Data Streams

Amazon Kinesis Data Streams is a durable, replayable, horizontally-scaled streaming service that ingests and stores real-time data for custom consumers. Unlike Data Firehose (which delivers streams to sinks), Data Streams exposes a raw stream that many applications can consume independently — the AWS analogue to Apache Kafka. Both provisioned (fixed shard count) and on-demand (auto-scaling, no shard math) capacity modes are available.


Core Concepts:


Key Features:


Common Use Cases:


Service Limits & Quotas:


Pricing Model:


Code Example:


import boto3, json, time

kinesis = boto3.client("kinesis", region_name="us-west-2")

# Producer
kinesis.put_record(
    StreamName="events",
    Data=json.dumps({"user": 42, "action": "click", "ts": time.time()}),
    PartitionKey="user-42",
)

# Consumer (simple shard iterator pattern; KCL is recommended for production)
shard_id = kinesis.describe_stream(StreamName="events")["StreamDescription"]["Shards"][0]["ShardId"]
it = kinesis.get_shard_iterator(
    StreamName="events", ShardId=shard_id, ShardIteratorType="LATEST"
)["ShardIterator"]

resp = kinesis.get_records(ShardIterator=it, Limit=100)
for rec in resp["Records"]:
    print(json.loads(rec["Data"]))
  


Data Streams vs. Firehose vs. MSK:


Common Interview Questions:

When would you choose On-Demand over Provisioned mode?

On-Demand removes shard math and auto-scales to bursty traffic — ideal when load is unpredictable or for new streams without baseline data. Provisioned is significantly cheaper at steady, well-understood throughput.

What is Enhanced Fan-Out and when is it worth the cost?

EFO gives each registered consumer a dedicated 2 MB/s push channel via HTTP/2, eliminating contention with other consumers and reducing latency to ~70 ms. Worth it when multiple consumers need low latency or high throughput concurrently; otherwise the standard pull-based model is cheaper.

How do you choose a partition key?

Pick a high-cardinality, evenly-distributed attribute (user ID, device ID). Low-cardinality keys (e.g., country code) cause hot shards and throttling. If ordering doesn't matter, use a random UUID.

How does Lambda integrate with Kinesis Data Streams?

Via an Event Source Mapping that polls the stream and invokes Lambda with a batch. Tunables: batch size, batch window, parallelization factor (multiple Lambdas per shard while preserving partition-key ordering), tumbling windows, and on-failure destinations.

What's the difference between Kinesis Data Streams and MSK?

Both are durable streaming platforms. Data Streams is fully managed AWS-native with simpler ops; MSK is managed Apache Kafka with full Kafka API compatibility and ecosystem (Connect, Streams, Schema Registry). Choose MSK when you need Kafka tooling or are migrating from on-prem Kafka.

How do you guarantee exactly-once processing downstream?

Kinesis itself provides at-least-once delivery. Build idempotency into consumers — track a sequence number or record key in DynamoDB to deduplicate before side effects. Flink and KCL provide checkpointing primitives that simplify this.