EnorexaEnorexa
Back to blog

Cloud

DynamoDB Streams and Lambda: Killing the Poison Pill Loop That Freezes Shards

November 7, 20262 min readBy Enorexa Team

A single unhandled TypeError: Cannot read properties of undefined (reading 'tenantId') in your Lambda consumer will quietly freeze an entire DynamoDB stream shard. DynamoDB Streams preserve strict in-order processing per partition key. That guarantee sounds pristine on an architecture diagram. In production, an unexpected payload turns into an infinite retry loop that blocks thousands of upstream transactions behind it.

Why In-Order Processing Becomes a Distributed Deadlock

Engineers migrating event-driven state from traditional message buses assume stream consumers behave like standard SQS queues. They do not. When a Lambda invocation processing a batch of records throws an unhandled exception, AWS will re-deliver the exact same batch repeatedly until the records reach their 24-hour retention limit. Meanwhile, iterator age spikes from 42 milliseconds to 18 hours. Downstream inventory syncs stall, user audit feeds go silent, and your CloudWatch dashboard turns crimson. The root failure is rarely network instability; it is almost always an unversioned migration script writing unexpected null values into the NewImage attribute.

Configuring BisectBatchOnFunctionError and Dead-Letter Destinations

Fixing this requires configuring your Event Source Mapping with aggressive defensive switches instead of relying solely on application-level try-catch blocks. Set BisectBatchOnFunctionError: true. When a batch of 100 records throws an error, Lambda recursively splits the batch into two 50-record chunks and re-invokes. It repeats this bisection down to the single offending record. Pair this directly with MaximumRecordAgeInSeconds: 3600, MaximumRetryAttempts: 2, and an explicit SQS failure destination (OnFailureDestination). Your healthy 99 records process in sub-second time, while the corrupted payload routes directly to an isolated quarantine queue alongside its full invocation metadata.

Isolating Schema Drift Before It Reaches CloudWatch

Once the poison pill arrives in your dead-letter SQS queue, manual redrive scripts are a massive drain on on-call engineers. At Enorexa, we build automated quarantine triage pipelines that parse failed stream records, match payload anomalies against declared Zod contracts, and notify engineering teams with exact diffs before data consistency degrades. If stream lag or brittle event consumers are draining your infrastructure budget, talk to us about building resilient, production-hardened cloud pipelines.