DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Five Layers Between Your AI Agent and a Production Outage
  • Building an AI Agent That Responds to Real-Time Events With AWS Bedrock, Kinesis, DynamoDB, and S3
  • Building a Zero-Cost Approval Workflow With AWS Lambda Durable Functions
  • AWS Managed Database Observability: Monitoring DynamoDB, ElastiCache, and Redshift Beyond CloudWatch

Trending

  • Spring Boot's Hidden Secret for Configuration: EnvironmentPostProcessor
  • Securing AI Agents in Production: A Developer’s Guide To Prompt Injection, RAG Leaks, and Tool Abuse
  • Avoiding AI Debt as a Team
  • From Phone Menus to Workflows: The Quiet Engineering Behind Voice Agents That Act

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. How We Cut DynamoDB Ingestion Reads With an S3 Hash Pre-Filter

How We Cut DynamoDB Ingestion Reads With an S3 Hash Pre-Filter

Learn how to reduce Amazon DynamoDB read costs in batch ingestion using S3 fingerprints and deterministic hashing with Apache Flink.

By 
Navaprasad Maram
·
Nov. 24, 26 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
0 Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

The Setup

Our team runs a customer data platform: a single source of truth for customer profile data, serving a high-volume read application programming interface (API) and ingesting changes from hundreds of upstream systems. The storage layer is Amazon DynamoDB in an entity–attribute–value (EAV) layout: the partition key is the entity ID, the sort key is the attribute name, and each item holds an attribute value plus a source version—the upstream update timestamp carried on that event.

Ingestion runs on Apache Flink — hundreds of pipelines, one per source. Some sources stream changes continuously; others are batch, publishing once a day. Because Flink handles both modes, all of them share one codebase, with JOLT (a JSON-to-JSON transformation library) handling per-source transformations declaratively, so onboarding a new source is mostly configuration.

Each pipeline does a read-before-write for every incoming record: fetch the entity's stored attributes, compare versions, and discard the event if its version is older than what's stored — that's our idempotency guard. If the version is newer but the values haven't changed, discard anyway, because a write that changes nothing is a write capacity unit spent on nothing.

That last rule is the irony this article is about. The check we built to save write costs is itself a read. And reads, it turned out, were where the money was going.

The Problem: The Reads Weren't Coming From Where We Thought

When DynamoDB read costs climbed to the point of demanding attention, everyone's first suspect was the obvious one: the read API, the thing serving thousands of requests per second. We dug through the access logs expecting to find a hot consumer or an inefficient query pattern.

The API wasn't the problem. The ingestion was. Every one of those hundreds of pipelines was faithfully doing its read-before-write on every record it received — and the volume of records they received had nothing to do with how much data was actually changing.

The reason was a design principle on the batch side. Batch sources build daily events from a data lake, and the natural way to do that is to emit the complete entity—a Person event carries firstName, lastName, phoneNumber, everything—for every entity, every day. A full snapshot, not a changelog. From the source's perspective, that's simple and robust. From ours, each batch snapshot triggered a DynamoDB fetch of the stored attributes, even when none of the attributes we had onboarded had actually changed.

Our analysis showed how concentrated the activity was: around 90% of batch events carried changes to only about 10% of the source data. That is not the same as saying 90% of DynamoDB reads were avoidable. For our filter, the relevant question was narrower: did any of the attributes we actually onboarded change? That distinction matters when estimating how many read-before-write checks can safely be skipped.

The Thought Process: Three Options, Two Rejected

Option 1 — fix it upstream. The cleanest fix is for sources to publish only what changed, so we asked. Some were willing. But even a willing source couldn't fully solve it: a source entity has N attributes, and we typically onboard only a subset. The source can't tailor its change detection to our subset — so when an attribute we never onboarded changes, they still (correctly, from their view) publish an event, and we still pay to discover it's a no-op for us. Upstream cooperation helped at the margins; it couldn't be the answer. The filter had to live on our side, and it had to be aware of what we onboarded, not what the source produced.

Option 2 — keep the filter state in Flink. Flink has first-class managed state, checkpoints, and savepoints. A per-entity fingerprint in managed state could avoid a remote lookup. We rejected that option for reasons specific to our operating model—not because Flink state is generally unreliable. Across hundreds of jobs, we had experienced offset resets and cases where fingerprint state was lost or had to be rebuilt. That didn't corrupt writes, but it silently returned affected pipelines to full DynamoDB read volume until their cache warmed up. We wanted the cost optimization to survive each job's lifecycle without special restoration steps.

Option 3 — externalize the fingerprint to S3. For each daily batch event, compute a hash over only the attributes we've onboarded. Look up the previously stored fingerprint in S3, keyed by entity name and ID. A match can allow the pipeline to avoid the DynamoDB read; a missing fingerprint or mismatch takes the original read-before-write path. This is a batch-only pre-filter, not a replacement for the downstream version and value checks. Its safety depends on how the fingerprint is maintained relative to committed DynamoDB state.

There is more to “hash the attributes” than choosing a digest function. The input needs a stable field order and value encoding, with an explicit distinction between a missing field and a null value. The projection must include every onboarded attribute and exclude source-only fields. Otherwise, equivalent events create unnecessary mismatches—or a relevant change is left out of the comparison entirely. A collision-resistant hash helps with accidental collisions, but it can't fix an inconsistent projection.

Why S3, of All Things

Using S3 for per-entity lookups sounds backward until you look at what the daily batch workload actually needs:

  • It's a batch. These pipelines process daily snapshots; nobody is waiting for a sub-millisecond answer. S3 GET latency isn't free, and request volume still affects total runtime, but this workload has more room to make that trade-off than a real-time API. We left streaming pipelines untouched.
  • It's cheap where it counts. S3 GET requests can be substantially cheaper than the DynamoDB capacity needed to fetch an entire EAV entity in this workload. But the comparison includes S3 PUTs, object storage, GET rates, and batch duration — not just one request price. The filter pays off only when the avoided DynamoDB reads outweigh those added costs.
  • It's independent of job state. An S3 fingerprint persists across Flink restarts, redeployments, offset resets, and rescaling. That separated the cost optimization from the operational lifecycle of hundreds of individual jobs.
  • Failure handling matters. A missing or unreadable hash can fall through to the usual DynamoDB check. A stale hash is not automatically harmless: if it matches a later event after DynamoDB's value has changed, the pipeline could discard a valid update. The safe invariant is that a fingerprint used to skip a read must correspond to a confirmed committed projection, with explicit handling for retry, replay, concurrent updates, and reconciliation. A collision-resistant hash makes accidental collisions unlikely; it does not solve S3–DynamoDB synchronization errors.

The result was a substantial reduction in ingestion read pressure. A qualifying fingerprint match bypasses the DynamoDB fetch altogether, so read demand no longer has to follow every daily snapshot a source publishes. The source-data 90/10 pattern motivated the change, but it is not a measured 90% reduction in read requests or dollars saved; those outcomes depend on the actual match rate and the additional S3 request and storage costs.

To evaluate the economics of this pattern, we'd compare the actual fingerprint match rate, DynamoDB read requests or consumed read capacity, S3 GET/PUT and storage charges, and total batch duration across similar daily runs. Those numbers — not the raw 90/10 input skew — determine the net benefit.

The batch-only read path, before and after the pre-filter:

path what happens in batch ingestion

Before

Daily snapshot → DynamoDB entity read → version/value comparison → write or discard.

After: fingerprint lookup

Daily snapshot → project onboarded attributes → deterministic hash → look up S3 fingerprint.

Trusted match

Skip the DynamoDB read, provided the fingerprint represents confirmed committed state.

Miss or mismatch

Run the normal DynamoDB read-before-write checks; keep the fingerprint aligned with confirmed state.


The Takeaway

Three lessons we'd offer anyone running read-heavy ingestion against a pay-per-request store:

Follow the bill to the actual caller. Our read costs looked like an API problem because the API was the visible reader. The logs said otherwise. Cost work that starts from assumptions optimizes the wrong component with great precision.

A guard has a cost of its own. Read-before-write is a sensible idempotency and no-op-suppression pattern, but every guard evaluation is billed. When batch sources republish largely unchanged data for the attributes you actually store, the guard becomes much of the workload. The answer isn't to remove the guard; it's to put a cheaper, correctly synchronized filter in front of it—in our case, a hash over onboarded attributes, which no upstream source could tailor to our subset.

Match the store to the workload's tolerance, not to reflex. S3 as a key-value lookup violates every low-latency instinct — and was exactly right for a batch path that tolerates latency and rewards durability and cost. The cheapest read is the one you never make; the second cheapest is the one you make against the cheapest store that's good enough.

Amazon DynamoDB Filter (software)

Opinions expressed by DZone contributors are their own.

Related

  • Five Layers Between Your AI Agent and a Production Outage
  • Building an AI Agent That Responds to Real-Time Events With AWS Bedrock, Kinesis, DynamoDB, and S3
  • Building a Zero-Cost Approval Workflow With AWS Lambda Durable Functions
  • AWS Managed Database Observability: Monitoring DynamoDB, ElastiCache, and Redshift Beyond CloudWatch

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook