AWS Data Engineering
Real-Time Data Pipeline on AWS: Kinesis → Lambda → S3 → Athena
DataForge AWS Data Engineering Series - Blog 15 of 20
The dashboard showed real-time revenue. It was, in fact, showing revenue from six minutes ago, presented with a live-updating chart that implied second-by-second accuracy. Nobody had lied about this deliberately — the pipeline was built in pieces, by different people, over several months, and nobody had ever calculated the end-to-end latency across all four stages combined. Each individual piece was fast. The sum of four individually-fast pieces was six minutes.
When a flash sale caused a genuine anomaly — a payment processor failure that should have triggered an immediate alert — the alert fired six minutes after the failure started, because that’s how long it took data to travel through Kinesis buffering, Lambda batch processing, Firehose delivery buffering, and Athena’s own query latency before anyone’s dashboard reflected reality. Six minutes doesn’t sound catastrophic until it’s six minutes of a broken payment flow that nobody was looking at because the “real-time” dashboard hadn’t caught up yet.
This article builds the same pipeline correctly — every stage’s latency contribution made explicit, so “real-time” means something specific and measured, not an aspirational label on an architecture nobody actually timed end to end.
Let’s go deep.
TL;DR
A real-time pipeline on AWS assembling Kinesis, Lambda, S3, and Athena has a latency budget determined by the slowest deliberately-configured stage, not by any single component’s theoretical maximum speed. Understanding exactly what each stage contributes to end-to-end latency — and which configuration knobs trade latency for cost or reliability — is what separates a pipeline that’s genuinely near-real-time from one that’s real-time in name only.
By the end of this article you’ll be able to:
- Calculate the actual end-to-end latency budget across every stage of a Kinesis-to-Athena pipeline
- Configure each stage’s buffering and batching settings with explicit latency-vs-cost trade-offs understood
- Identify which stage is the latency bottleneck in an existing pipeline before optimizing the wrong one
- Recognize when this architecture’s near-real-time latency is sufficient versus when true sub-second processing requires a different pattern
Series context: This assembles Blog 8 (Kinesis), Blog 10 (Lambda), Blog 2 (S3), and Blog 12 (Athena) into one complete, measured pipeline — the first of two end-to-end architecture articles in this phase, alongside Blog 16’s event-driven batch pattern.

The Complete Pipeline, Stage by Stage
Before optimizing anything, the pipeline needs to be laid out with every stage’s actual mechanism visible — the same discipline the opening scenario’s team skipped.
Producer (application, IoT device, web event)
|
v PutRecord/PutRecords
Kinesis Data Stream (Blog 8)
| Shard-based, records available to
| consumers as soon as written
v
Lambda (Blog 10) — Kinesis event source mapping
| Batches records, invokes per batch,
| NOT per individual record
v
Kinesis Data Firehose (Blog 8) OR direct S3 write
| Buffers by size/time BEFORE delivering
| to S3 — this is a SECOND buffering stage,
| distinct from Lambda's batching
v
S3 (Blog 2)
| File lands, needs Catalog registration
| before Athena can see it
v
Glue Catalog registration (Blog 5/12)
| Crawler interval OR event-driven
| partition registration
v
Athena (Blog 12)
Query latency — even a fast, well-optimized
query has non-zero startup and execution timeThe critical realization the opening scenario missed: there are five distinct latency-contributing stages between “event happens” and “dashboard reflects it,” and at least three of them (Lambda batching, Firehose buffering, and Catalog registration timing) are configured independently by different engineers who each optimized their own piece without anyone calculating the sum.
How Latency Actually Accumulates: The Mechanism
This is the mechanism worth calculating precisely, because the opening scenario’s six minutes is the sum of specific, individually-reasonable configuration choices that nobody added together.
Stage 1: Producer to Kinesis
Latency: typically under 100ms for a healthy,
correctly-provisioned stream (Blog 8's shard
capacity discipline applies — a throttled shard
adds unbounded latency here instead)
Stage 2: Kinesis to Lambda (event source mapping)
Lambda's Kinesis integration doesn't invoke per
record — it batches based on BatchSize and
MaximumBatchingWindowInSeconds
If MaximumBatchingWindowInSeconds = 60:
Lambda waits up to 60 SECONDS to accumulate
a batch before invoking, even if only a few
records have arrived
Contributed latency: 0 to 60 seconds, averaging
~30 seconds for steady traffic
Stage 3: Lambda processing to Firehose
Lambda's own execution time (typically fast for
the kind of light transformation Blog 10
established as Lambda's correct role) — a few
hundred milliseconds
Stage 4: Firehose buffering to S3
Firehose buffers by BufferSizeInMBs OR
BufferIntervalInSeconds, whichever triggers first
If BufferIntervalInSeconds = 300 (5 minutes),
chosen specifically to avoid Blog 2's small-file
problem:
Contributed latency: 0 to 300 seconds,
averaging ~150 seconds
Stage 5: S3 to Glue Catalog registration
If using a scheduled crawler running every 15
minutes (Blog 5's inefficient pattern):
Contributed latency: 0 to 900 seconds,
averaging ~450 seconds
If using event-driven registration (Blog 5's
efficient pattern, Blog 14's platform-scale
version):
Contributed latency: typically under 30 seconds
Stage 6: Athena query execution
Latency: 1-5 seconds for a well-optimized query
against properly partitioned Parquet (Blog 2,
Blog 12's principles)
TOTAL, WORST REALISTIC CASE (scheduled crawler,
generous buffering everywhere):
30s (Lambda batch) + 150s (Firehose buffer)
+ 450s (crawler interval) + 5s (query)
= 635 seconds = ~10.5 minutes
TOTAL, OPTIMIZED FOR LOW LATENCY:
5s (Lambda batch, small window) + 10s (Firehose
buffer, small interval) + 20s (event-driven
registration) + 2s (query)
= 37 seconds
The opening scenario’s six minutes sits between these two extremes — some stages were tuned for cost efficiency (larger buffers, fewer files, per Blog 2’s small-file discipline), others were left at defaults, and nobody calculated the combined effect until an actual incident made the gap visible.
The Latency-vs-Cost Trade-off at Every Stage
Every buffering and batching parameter in this pipeline is a deliberate latency-vs-cost trade-off, not a default to leave untouched. This is Blog 2’s small-file principle and Blog 8’s Firehose discussion, made explicit as a tunable dial rather than a fixed setting.
Lambda batching window (MaximumBatchingWindowInSeconds):
Smaller window: lower latency, MORE Lambda
invocations (more invocations = more cost, and
more cold start exposure per Blog 10)
Larger window: higher latency, fewer invocations,
lower cost
Firehose buffer interval:
Smaller buffer: lower latency, MORE files
delivered to S3 (Blog 2's small-file cost problem
directly)
Larger buffer: higher latency, fewer/larger files,
cheaper downstream Athena scans
Catalog registration method:
Scheduled crawler: simple, but adds latency
bounded by the crawler interval, and costs
scale with pipeline count (Blog 14)
Event-driven registration: lower latency,
requires the Lambda-based pattern from Blog 14,
more implementation complexity
Athena query frequency:
Querying more often for "freshness" doesn't
reduce latency of the DATA — it just means more
frequent checks against data that's already as
fresh as the upstream pipeline made it. This is
a common confusion: increasing Athena polling
frequency does nothing if the bottleneck is
upstream buffering.
The principle underlying every one of these trade-offs: there is no configuration that gives you both minimum latency and minimum cost simultaneously — every dial in this pipeline moves one at the expense of the other, and the correct setting depends on what the actual downstream requirement is, not on leaving defaults untouched or copying a setting from a different pipeline with different requirements.
Choosing the Right Latency Target Before Configuring Anything
The opening scenario’s actual failure wasn’t a configuration mistake — it was the absence of an explicit latency requirement before configuration began. Different use cases genuinely need different points on this trade-off curve.
Use case Target latency Configuration
────────────────────────────────────────────────────────────────────
Executive dashboard, updated 5-15 minutes Larger buffers,
hourly review pattern scheduled crawler
acceptable
Operational monitoring, 1-3 minutes Moderate buffers,
"is the system healthy" event-driven
registration
Fraud/anomaly detection, Seconds Small/no buffering,
requiring immediate action Kinesis Data
Analytics (Blog 8)
instead of S3/
Athena for the
alerting path
specifically
Payment failure alerting Seconds Same as above —
(the opening scenario's this requirement
actual need) was never stated
explicitly, so
the pipeline was
built for dashboard
latency insteadThe opening scenario’s root cause, precisely stated: the pipeline was correctly built for “executive dashboard” latency requirements — nothing about its configuration was wrong for that use case. The payment failure alerting need was bolted onto the same pipeline without anyone recognizing it needed a fundamentally different latency target, requiring either a separate low-latency path (Kinesis Data Analytics triggering Lambda directly, bypassing S3/Athena entirely for this specific alert) or explicit acknowledgment that this pipeline could not meet that requirement.
Architecture Flow: The Complete Pipeline With Latency Annotated
Producer
| ~50-100ms
v
Kinesis Data Stream (Blog 8)
| Shard capacity must be correctly provisioned -
| throttling adds unbounded, silent latency here
|
+----------------------+
| |
v Low-latency path v Dashboard path
Kinesis Data Analytics Lambda event source mapping
(windowed SQL, no S3 (batching window: TUNE
round-trip needed) explicitly per use case)
| seconds | 5-60s depending on config
v v
Lambda/SNS Firehose (buffer: TUNE
(immediate alert) explicitly, Blog 2 trade-off)
| 0-300s depending on config
v
S3 (Blog 2's format/partition
principles)
|
v
Catalog registration
(event-driven: <30s,
scheduled crawler: up to
crawler interval, Blog 14)
|
v
Athena (Blog 12)
| 1-5s query execution
v
DashboardFailure Modes You’ll See in Production
Nobody calculating end-to-end latency across independently-built stages. The opening scenario. Each of four stages configured reasonably in isolation, by different people, at different times, with nobody summing the total — and the gap only becomes visible during an actual incident where the accumulated latency has a real consequence.
A low-latency requirement bolted onto a pipeline built for dashboard latency. A genuinely time-sensitive alerting need (fraud detection, payment failures) routed through the same S3/Athena pipeline built for hourly dashboard refreshes, because it was the existing pipeline and building a separate low-latency path felt like unnecessary duplication — until the latency gap has a real cost.
Firehose buffer tuned for cost efficiency without considering the specific consumer’s latency need. A well-intentioned optimization (larger Firehose buffer to reduce S3 file count, per Blog 2’s small-file guidance) applied uniformly across a pipeline serving both a low-urgency weekly report and a higher-urgency operational dashboard, degrading the dashboard’s freshness to satisfy the report’s cost efficiency.
Scheduled crawler chosen for simplicity, adding a hidden latency floor. A team defaults to a scheduled Glue crawler (simpler to set up than event-driven registration) without recognizing that the crawler interval sets a hard floor on data freshness regardless of how fast every other stage is — data can’t appear in Athena until the Catalog knows about it, no matter how quickly it landed in S3.
Increasing Athena query frequency to “get fresher data,” without addressing the actual bottleneck. A team notices dashboard data is stale and responds by having the dashboard poll Athena more frequently, not realizing the staleness originates in upstream buffering — polling a data source more often doesn’t make the data itself any fresher if it hasn’t arrived yet.
Lambda cold starts adding unpredictable latency to a low-traffic stream. A Kinesis-triggered Lambda function processing a lower-volume stream experiences infrequent invocations, meaning cold starts (Blog 10) contribute meaningfully to the batch latency in a way that’s invisible in load testing (which keeps the function warm) but real in production traffic patterns with gaps between invocations.
Trade-offs: What This Pipeline Optimizes For
This pipeline optimizes for:
- Cost-efficient near-real-time processing (minutes-scale latency) without standing infrastructure beyond Kinesis capacity
- Flexibility to tune each stage’s latency/cost balance independently based on actual downstream requirements
- Reuse of the same S3/Athena serving layer (Blog 12) for both real-time and batch consumers
This pipeline doesn’t optimize for:
- True sub-second latency — the S3-and-Catalog-registration path has an inherent latency floor that buffering tuning can reduce but not eliminate entirely
- A single “set it once” configuration — every stage’s buffering needs to be revisited as downstream latency requirements change or new consumers with different needs are added
- Automatic detection of latency requirement mismatches — nothing in this architecture warns you when a new low-latency use case is routed through a pipeline configured for a different latency target
The honest trade-off: this pipeline is the right architecture for near-real-time (seconds-to-minutes) requirements at reasonable cost. Genuine sub-second requirements need Kinesis Data Analytics or a direct Lambda/Kinesis alerting path that bypasses S3 and Athena entirely for that specific need — mixing both requirements into one pipeline, as the opening scenario did, produces a pipeline that serves neither well.
Real-World Constraints
Kinesis shard capacity must be correct for the latency budget to hold. Everything in this article’s latency calculation assumes Blog 8’s shard capacity discipline is already correctly applied — a throttled shard doesn’t just fail cleanly, it adds unbounded, growing latency that defeats every downstream buffering optimization.
Firehose Lambda transformation adds its own latency contribution. If Firehose is configured with inline Lambda transformation (rather than a separate upstream Lambda consumer), that transformation’s execution time and any cold start latency (Blog 10) becomes part of the buffering-stage latency calculation, not a separate line item.
Athena query result caching can mask staleness. If a dashboard tool caches Athena query results client-side or through a BI tool’s own caching layer, the effective end-to-end latency includes that cache TTL as an additional, often-overlooked stage beyond the five covered in this article’s calculation.
What This Means for the Rest of the Series
Blog 16 (Event-driven ETL pattern): the batch-oriented
counterpart to this
real-time pattern -
S3 events triggering
Step Functions instead
of continuous streaming
Blog 20 (Production checklist): includes an explicit
item for calculating and
documenting end-to-end
pipeline latency before
launch, directly addressing
this article's opening
scenario
Summary: The Engineering Lesson
“Real-time” is not a property of any single AWS service in this pipeline. It’s the sum of every buffering, batching, and registration decision made across Kinesis, Lambda, Firehose, S3, and Athena — and that sum is only ever as fast as the slowest deliberately-configured stage, regardless of how fast the others are.
The six minutes in the opening scenario weren’t a bug. They were the correct, predictable output of a pipeline where every individual stage was configured reasonably for a dashboard-refresh use case, and nobody added the stages together before a genuinely time-sensitive requirement was routed through the same path.
Before building this pipeline, calculate the latency budget explicitly, stage by stage, the way this article did — and match every buffering decision to the specific downstream requirement it needs to serve, not to whatever configuration was copied from a different pipeline with a different latency target.
Next in Series
Blog 16 - Event-Driven ETL on AWS: S3 Events → Step Functions → Glue
This article covered the continuous streaming pattern. Blog 16 covers the complementary batch pattern — pipelines that should run exactly when a file arrives, not on a fixed schedule and not continuously, assembling Blog 4’s S3 events, Blog 11’s Step Functions orchestration, and Blog 5’s Glue transformation into one complete, event-driven batch architecture.
Comment Below
What’s the gap you’ve found between a pipeline labeled “real-time” and its actual measured end-to-end latency?
Was it a dashboard confidently showing “live” data that was actually minutes behind, discovered only during an incident where the delay mattered? A well-intentioned cost optimization on one stage’s buffering that silently degraded a different consumer’s freshness requirement? A low-latency alerting need bolted onto a pipeline that was never built for it?
And — once you calculated the actual end-to-end latency, was the fix a configuration change, or did it require an entirely separate low-latency path?
Tags: aws-data-engineering, real-time-pipeline, amazon-kinesis, aws-lambda, kinesis-firehose, amazon-athena, latency-optimization, dataforge