Blog >

Building a Real-Time Analytics Pipeline on AWS with Kinesis

Posted by Hadi @draft1 | July 21, 2026

Building a Real-Time Analytics Pipeline on AWS with Kinesis

A real-time analytics pipeline on AWS typically combines Amazon Kinesis Data Streams, a processing layer, and a storage or serving tier to move data from ingestion to insight in under a few seconds. This architecture has become the default choice for teams that need to act on events — fraud signals, clickstreams, IoT sensor readings, or application logs — before the moment passes. In this article you'll learn how to design, build, and operate a production-grade Kinesis pipeline, including the trade-offs between competing services, concrete configuration choices, and the operational gotchas that only show up after launch.

What Is a Real-Time Analytics Pipeline?

A real-time analytics pipeline is a chain of services that ingests, transforms, and queries streaming data with end-to-end latency measured in milliseconds to low seconds, rather than the minutes or hours typical of batch ETL. On AWS, the canonical stack layers are: ingest → stream → process → store → serve. Each layer can be swapped independently, which is both the power and the complexity of the pattern.

Choosing the Right Kinesis Service

AWS offers three distinct Kinesis products, and picking the wrong one is the most common early mistake.

Amazon Kinesis Data Streams (KDS) gives you a durable, ordered, replayable log of records. Producers write records up to 1 MB each; each shard supports 1,000 PUT records/sec and 1 MB/sec ingest, plus 2 MB/sec read per consumer. Data is retained for 24 hours by default, extendable to 365 days. You manage shard count (or enable On-Demand mode, which scales automatically up to 200 MB/sec by default).

Amazon Kinesis Data Firehose (now branded as Amazon Data Firehose since the 2023 rename) is a fully managed delivery service. It buffers records and writes them in micro-batches to S3, Redshift, OpenSearch, or Splunk. The minimum buffer interval is 60 seconds, which means it is not sub-second — but it requires zero infrastructure management.

Amazon Managed Service for Apache Flink (formerly Kinesis Data Analytics) lets you run Apache Flink 1.18+ applications against a KDS or Kafka source with exactly-once semantics and stateful windowed aggregations.

Service Latency Management overhead Replay Best for
Kinesis Data Streams ~70 ms p99 Medium Yes (up to 365 days) Custom consumers, fan-out
Data Firehose 60 s – 15 min Very low No S3/Redshift delivery
Managed Flink ~100 ms p99 High Via KDS source Stateful aggregations
MSK (Kafka) ~5 ms p99 High Yes (configurable) Kafka-native workloads

Choose KDS when you need sub-second latency and multiple independent consumers. Choose Firehose when you just need reliable delivery to a data lake. Choose Managed Flink when you need windowed joins, sessionization, or complex event processing.

Designing the Ingestion Layer

Producers write to KDS using the Kinesis Producer Library (KPL), the AWS SDK PutRecord / PutRecords API, or the Kinesis Agent for log files. For high-throughput web applications, the KPL is preferred because it aggregates small records into larger ones (up to 1 MB) and uses asynchronous batching, dramatically reducing per-record cost and improving throughput.

Partition keys determine shard assignment. A poor partition key — such as a single static string — routes all traffic to one shard, creating a hot shard that throttles at 1 MB/sec. Use high-cardinality keys: user ID, device ID, or a hash of the event type plus timestamp. For truly uniform distribution, append a random suffix and strip it downstream.

For IoT workloads, AWS IoT Core can route MQTT messages directly to KDS via IoT Rules, eliminating a custom ingestion service entirely.

Processing: Lambda vs. Managed Flink vs. Custom ECS

Once data is in KDS, you need a consumer. Three patterns dominate:

AWS Lambda with KDS event source mapping is the simplest option. Lambda polls the stream, invokes your function with a batch of records (up to 10,000 records or 6 MB per batch), and checkpoints automatically. Cold starts add latency, and Lambda's 15-minute execution limit means it is unsuitable for long-running stateful aggregations. It works well for stateless enrichment: lookup a DynamoDB table, validate a schema, forward to another service.

Amazon Managed Service for Apache Flink is the right tool when you need windowed aggregations — for example, counting unique users per 5-minute tumbling window, or detecting when a sensor reading exceeds a threshold three times within 60 seconds. Flink maintains state in managed RocksDB, checkpoints to S3, and restarts cleanly after failure. The trade-off is operational complexity: you write Java, Python, or SQL, manage parallelism settings, and tune checkpoint intervals (typically 30–60 seconds for production).

Custom consumers on Amazon ECS or EKS using the Kinesis Client Library (KCL 2.x) give you the most control. KCL handles shard enumeration, lease management, and checkpointing to DynamoDB. This is the right choice when your processing logic is too complex for Lambda and you want to avoid the Flink learning curve.

Storage and Serving Layer

Processed records typically land in one or more of these targets:

  • Amazon S3 + AWS Glue + Amazon Athena: The data lake pattern. Firehose delivers Parquet files to S3; Glue crawlers update the catalog; Athena queries with standard SQL. Cost-effective for ad-hoc analysis but query latency is seconds to minutes.
  • Amazon DynamoDB: For per-entity state that needs millisecond reads. A Flink job can maintain a rolling aggregate (e.g., "total spend in last 30 minutes per user") and write it to DynamoDB, which an API then reads synchronously.
  • Amazon OpenSearch Service: For full-text search and time-series dashboards via OpenSearch Dashboards (formerly Kibana). Firehose has a native OpenSearch delivery target.
  • Amazon Redshift with Streaming Ingestion: Since 2022, Redshift can ingest directly from KDS using a materialized view, with latency around 5–10 seconds. This is the fastest path to SQL analytics without a separate processing tier.
  • Amazon Timestream: Purpose-built for time-series data (IoT, DevOps metrics). Supports automatic data tiering between in-memory and magnetic storage.

End-to-End Example: Clickstream Analytics

Imagine you run an e-commerce platform and want to detect users who are about to abandon their cart — defined as "added an item but had no further events for 10 minutes."

  1. Ingest: Your frontend sends events via a REST API backed by API Gateway + Lambda, which calls PutRecords to KDS. Partition key = user_id.
  2. Process: A Managed Flink application reads from KDS. It maintains a session window keyed on user_id. If the window closes (10-minute gap) and the last event was add_to_cart, it emits an abandonment event.
  3. Act: The abandonment event goes to a second KDS stream. A Lambda consumer reads it and calls Amazon Pinpoint to send a push notification or email.
  4. Store: Firehose delivers raw events to S3 in Parquet format, partitioned by year/month/day/hour. Athena queries power a daily dashboard in Amazon QuickSight.

This architecture achieves sub-30-second detection latency from user action to notification, with the historical data available for batch ML training in S3.

Operational Considerations

Monitoring: Enable Enhanced Shard-Level Metrics in KDS (additional cost, ~$0.015 per shard-hour as of 2026). Key metrics: GetRecords.IteratorAgeMilliseconds (rising iterator age = consumer falling behind), WriteProvisionedThroughputExceeded, and ReadProvisionedThroughputExceeded.

Scaling: In provisioned mode, resharding takes 30 seconds per split/merge and is limited to one operation every 30 seconds. On-Demand mode handles burst automatically but costs roughly 2× provisioned at sustained high throughput. Model your expected peak before choosing.

Cost levers: Extended data retention (beyond 7 days) costs $0.023 per shard-hour. Enhanced fan-out consumers cost $0.015 per shard-hour plus $0.013 per GB retrieved. These add up quickly at scale — audit them quarterly.

Security: Encrypt KDS at rest with AWS KMS (SSE-KMS). Use VPC endpoints (PrivateLink) so producer traffic never traverses the public internet. Apply least-privilege IAM: producers need only kinesis:PutRecord; consumers need kinesis:GetRecords, kinesis:GetShardIterator, and kinesis:DescribeStream.

Key Takeaways

  • A real-time analytics pipeline on AWS follows a five-layer pattern: ingest, stream, process, store, and serve — each independently replaceable.
  • Kinesis Data Streams is the right ingest layer when you need sub-second latency, replay, and multiple consumers; Data Firehose is better when you only need reliable delivery to S3 or Redshift.
  • Hot shards caused by low-cardinality partition keys are the most common production failure mode — use high-cardinality keys from day one.
  • Managed Flink handles stateful windowed aggregations that Lambda cannot; the trade-off is a steeper operational learning curve.
  • Redshift Streaming Ingestion is the fastest path to SQL analytics (5–10 s latency) without a separate processing tier.
  • Monitor IteratorAgeMilliseconds as your primary consumer health signal; a rising value means your consumer is falling behind the stream.
  • Extended retention and enhanced fan-out are powerful features but carry per-shard-hour costs that compound at scale — model them before enabling.

Frequently Asked Questions

How many shards do I need for my Kinesis Data Stream?

Each shard supports 1 MB/sec ingest and 2 MB/sec egress. Divide your peak ingest throughput in MB/sec by 0.8 (leaving 20% headroom) to get your starting shard count. If you have multiple consumers, multiply the egress requirement by the number of standard consumers, or use Enhanced Fan-Out to give each consumer its own 2 MB/sec pipe without competing.

What is the difference between standard and enhanced fan-out consumers?

Standard consumers share the 2 MB/sec read throughput per shard across all consumers using polling (GetRecords). Enhanced Fan-Out consumers use HTTP/2 push delivery and each receive a dedicated 2 MB/sec per shard, at additional cost. Use Enhanced Fan-Out when you have three or more concurrent consumers on the same stream.

Can I use Kinesis with Apache Kafka clients?

Not directly — KDS uses its own API, not the Kafka protocol. If you need Kafka client compatibility (for existing Kafka producers or connectors), use Amazon MSK (Managed Streaming for Apache Kafka) instead. MSK and KDS can coexist in the same pipeline if needed.

How do I handle duplicate records in a Kinesis pipeline?

KDS guarantees at-least-once delivery, so duplicates are possible, especially after retries or resharding. Implement idempotency in your consumer: assign each record a unique ID (include it in the record payload), and deduplicate using a DynamoDB conditional write or a Flink exactly-once sink. Managed Flink with checkpointing provides exactly-once processing semantics end-to-end when paired with compatible sinks.

What is the maximum record size in Kinesis Data Streams?

A single record can be at most 1 MB (after Base64 encoding). The PutRecords API accepts up to 500 records per call with a combined size limit of 5 MB. If your events are larger, compress them (gzip typically achieves 5–10× reduction for JSON) or split them before writing to the stream.

How does Kinesis pricing compare to MSK for a medium-scale workload?

At medium scale (say, 10 shards, 730 hours/month), KDS provisioned mode costs roughly $15/month for the shards plus data charges. MSK with two kafka.m5.large brokers costs approximately $200–$250/month regardless of throughput. KDS is more cost-effective at low-to-medium throughput; MSK becomes competitive above roughly 500 MB/sec sustained or when Kafka ecosystem tooling (Kafka Connect, Schema Registry) is required.

Can I replay historical data through my Kinesis pipeline?

Yes, as long as the data is within the retention window (24 hours by default, up to 365 days with extended retention enabled). Trim the shard iterator to AT_TIMESTAMP or AT_SEQUENCE_NUMBER and replay from that point. For data older than the retention window, you must replay from your S3 archive using a batch job that writes back to KDS or processes the data directly.


Draw this in seconds with draft1. Describe your architecture in plain English and draft1 generates an editable AWS/cloud diagram plus documentation — no dragging boxes around. Try it free.

Draw this in ~20 seconds

Describe your own version of this architecture and draft1 generates an editable draw.io diagram — boxes, arrows, labels, the lot.

Generate this diagram free ➔

Free demo — no signup. Then 3 free diagrams with an account, no card.