- Newest
- Most votes
- Most comments
Several of these problems share a root cause, and the fix order matters — some of what you're considering becomes unnecessary once earlier changes land.
Start here: aggregate inside the Lambda invocation
You're already receiving batches from the Event Source Mapping and processing them record by record. Folding records for the same entity in memory before touching DynamoDB costs nothing in added latency, because the batch has already been assembled.
With a batch of 1,000 records for one hot entity, that's 1,000 writes collapsed to one. For SUM/COUNT this is lossless — they're commutative and associative, so in-batch folding doesn't disturb ordering semantics.
This is the largest single lever available and it's independent of everything below. The freshness cost is bounded by your existing batch window, not by a new buffering layer.
A constraint worth checking before you commit to atomic ADD
You mention each read performs a decrypt and that you've hit KMS rate limits. That pattern suggests client-side encryption rather than DynamoDB's SSE.
If so, UpdateItem … ADD won't work on your aggregate attributes — DynamoDB can't do arithmetic on ciphertext it can't read.
The way out is per-attribute crypto actions. Numeric counters and sums rarely need confidentiality; mark them SIGN_ONLY (so they remain tamper-evident) and reserve encryption for attributes that genuinely need it. That restores ADD, eliminates the read entirely, and removes the read-path KMS calls in one move.
If it turns out you're on SSE with a customer-managed key, this isn't a problem at all — but then the KMS throttling has a different cause worth chasing separately. Either way, enable data key caching.
Your 60 WCU is mostly item size, and that's fixable
Two things are inflating it.
Multiple round-trips per record. One UpdateItem can update many attributes atomically — SET a = a + :1, b = b + :2 ADD c :3, d :4 in a single call. If you're issuing roughly five operations per record, consolidating takes 60 WCU to 12.
The bounded history living in the hot item. This is the bigger issue. A 12 KB item costs 12 WCU on every write, because write capacity is charged on item size, not on how much of it changed. You're paying to rewrite the history every time a counter moves.
Split them:
PK = tenantId:entityId, SK = "AGG" → scalars only, a few hundred bytes
PK = tenantId:entityId, SK = "HIST#<ts>" → one item per history entry, write-once, TTL
The aggregate update drops to 1 WCU. History becomes append-only — no read-modify-write, no contention — and bounding is handled by TTL rather than application logic.
Combined with the consolidation above: 60 WCU → roughly 2 (one aggregate update, one history append). Same partition, 30× the throughput.
Why are you seeing ConditionalCheckFailedException at all?
This one is worth pausing on. Your partition key keeps every record for an entity on one shard, and you have one invocation per shard. That should mean no concurrent writers to a given item — in which case optimistic concurrency is protecting against something that shouldn't be happening.
Collisions suggest one of:
- Parallelization factor above 1 on the ESM
- A retry overlapping an invocation that hasn't actually finished
- Shard splits or merges producing transient overlap during resharding
- More than one ESM attached to the stream
If there's genuine concurrency you don't know about, you may also have duplicate processing — which matters independently of throttling. Worth confirming before optimising around the symptom.
Note that once you move to ADD, you don't need the version attribute for correctness, but you probably do want idempotency against replay. A condition on a monotonic sequence number (ADD counters :delta with ConditionExpression: lastSeq < :seq) gives you that without a read.
Noisy neighbour
Given this is one known high-volume tenant, I'd reach for cell isolation before anything cleverer: route that tenant to its own stream at the producer. Hard isolation, no filtering overhead, no shared read budget, and the contractual volume becomes a capacity planning problem for one stream rather than a fairness problem across all of them.
EventBridge Pipes with tenant filtering is the right fallback if you can't change producer-side routing. Each Pipe is an independent consumer with its own iterator, so the light lane isn't blocked behind heavy records at the processing layer — filtered records are discarded before invocation. The caveat is that the light lane still has to traverse the heavy tenant's records to reach its own, so you'll want enhanced fan-out to give each consumer its own read budget rather than sharing the shard's 2 MB/s.
Shuffle sharding solves a different problem — many tenants whose volume you can't predict, where you want to bound the probability that any two heavies collide. With a single identified heavy tenant it's more machinery than the situation warrants.
Write sharding: probably not yet
Key-salting with scatter-gather reads is the standard answer when one logical key genuinely exceeds 1,000 WCU, and it's correct for SUM/COUNT. But it costs you read amplification and the ability to read a consistent snapshot of the aggregate.
Before taking that on, work out your actual per-entity rate. The partition cap binds on single items, not on tenant volume. If the heavy tenant's tens of thousands of records per second spread across thousands of entities, the per-entity rate is modest and the changes above will clear it. If it's genuinely one entity at that rate, shard it — but confirm which world you're in first.
Worth considering strategically
If running aggregates are the core of this system, Managed Service for Apache Flink is built for exactly this shape: stateful windowed aggregation with checkpointing, holding state in the stream processor and flushing to DynamoDB at a rate you choose. It turns the write-amplification problem into a configuration decision rather than something you engineer around in Lambda.
That's a larger change than the above and I wouldn't lead with it — but if you find yourself building increasingly elaborate buffering inside Lambda, it's the thing that buffering is reimplementing.
Suggested order
- Fold per-entity aggregates within the batch
- Confirm the encryption model, and mark aggregate attributes
SIGN_ONLYif client-side - Split the history out of the hot item
- Consolidate to one
UpdateItemper entity per batch, with a sequence-number condition - Move the heavy tenant to its own stream
- Measure per-entity rates, and only then decide on write sharding
Steps 1 and 3 together should give you one to two orders of magnitude before you touch the stream topology at all.
One correction to the answer above: SIGN_ONLY won't make UpdateItem ... ADD work if you're using the DynamoDB Encryption Client. SIGN_ONLY attributes are covered by the item signature. A server-side ADD changes the value without re-signing, so the next read fails signature verification.
Attributes you mutate server-side have to be DO_NOTHING, which means they're not signed. That also applies to a lastSeq attribute used for the idempotency condition. If you need tamper-evidence on the aggregates, you have two options:
- Keep the counters in a separate plaintext item with IAM-level protection, and leave the encrypted item for the data that needs it.
- Switch to DynamoDB's built-in encryption at rest with a KMS key. It works with
ADDand the read path no longer makes per-item KMS calls from your code.
On the noisy-neighbor side, I wouldn't rely on enhanced fan-out with EventBridge Pipes without checking first. Look at the Kinesis source parameters in the Pipes docs. A Lambda event source mapping on a registered enhanced fan-out consumer is the documented route. You can add per-tenant event filtering on that mapping to build the same lane. Moving the heavy tenant to its own stream is still the cleaner option.
Relevant content
asked 3 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago
