High-throughput eventually consistent counter system for DynamoDB achieving 2,000+ TPS using a hybrid best-effort and eventual consistency design.
An engineering project addressing DynamoDB's challenges with high-throughput atomic counters. DynamoDB uses optimistic concurrency control which can cause transaction failures under contention. Our hybrid solution combines a best-effort counter (immediate, may undercount but never overcounts) with an eventually consistent counter (processed asynchronously via DynamoDB Streams and Lambda). The best-effort counter serves as an immediate heuristic for enforcing creation limits, while the eventual consistency counter catches up in the background. This design achieves exactly-once processing guarantees through idempotency flags and transactional atomic operations.
2,000+ TPS
Throughput
Exactly-once
Processing
Self-healing
Recovery
Unlimited Lambda
Scalability
<0.5ms
Counter Latency
Zero new types
API Errors
Built a TypeScript API using Elysia on the Bun runtime with a DynamoDB single-table design. Resource creation immediately increments a best-effort counter and writes to DynamoDB with a counter_processed=false flag. DynamoDB Streams trigger Lambda functions that atomically increment the eventually consistent counter and set the flag. Deletion uses soft-delete (flag) followed by Lambda-driven decrement and hard-delete. Error handling uses a two-tier dead letter queue system. The entire stack is containerized with Docker using a local DynamoDB emulator for development.