2.1.4.3. DynamoDB Read/Write Capacity & Consistency Models
First Principle: DynamoDB's capacity modes (Provisioned/On-Demand) optimize cost and performance, while its consistency models (Eventually Consistent / Strongly Consistent) balance data freshness with latency.
Amazon DynamoDB allows you to choose how you manage your table's read and write throughput, impacting both performance and cost. It also offers different consistency models for reading data.
Key DynamoDB Capacity Models:
- Provisioned Capacity Mode:
- Concept: You specify the number of Read Capacity Units (RCUs) and Write Capacity Units (WCUs) your application needs.
- Best For: Predictable workloads with consistent traffic. Use DynamoDB Auto Scaling to automatically adjust provisioned capacity.
- Cost: Pay for provisioned capacity, whether used or not.
- On-Demand Capacity Mode:
- Concept: DynamoDB automatically adjusts its capacity based on your workload's actual demand.
- Best For: Unpredictable workloads, new applications, or workloads with spiky traffic.
- Cost: Pay for actual reads and writes, no minimum fees. Generally higher cost per unit than provisioned.
Key DynamoDB Consistency Models:
- Eventually Consistent Reads:
- Concept: Returns a response almost immediately, but the data might not reflect the results of a recently completed write. All copies of the data will eventually be consistent.
- Best For: Non-critical reads (e.g., product catalog display, user profile viewing) where immediate data freshness isn't paramount. More performant, lower latency.
- Strongly Consistent Reads:
- Concept: Returns the most up-to-date data, reflecting the results of all prior successful write operations.
- Best For: Critical reads where data freshness is essential (e.g., financial transactions, inventory checks). Can have higher latency and consume more provisioned throughput.
Scenario: You're developing a mobile gaming backend using DynamoDB. Leaderboard updates (writes) need to be immediately visible to all players. However, displaying a player's full profile (reads) can tolerate a few seconds of eventual consistency. The game experiences highly unpredictable traffic.
Reflection Question: How would you choose between Provisioned Capacity (with Auto Scaling) vs. On-Demand Capacity, and Eventually Consistent vs. Strongly Consistent Reads, to optimize DynamoDB capacity and consistency for this gaming application?