003 - DynamoDB Single Table Design
ADR Metadata ACCEPTED
Date
2024-01-01
Deciders
Architecture Team
Context
Section titled “Context”The system requires high-performance reads and writes for tracking request status. We need to query by Request ID (Get Item) and also query by Client ID and Date (Query Collection). Using multiple tables in DynamoDB can lead to higher costs (provisioned throughput waste) and more complex application logic for joins (which don’t exist in DynamoDB).
Decision
Section titled “Decision”We will use a Single Table Design strategy in DynamoDB.
Table Schema:
- Partition Key (PK): Generic string (e.g.,
REQID#<ID>,CLIENT#<ID>). - Sort Key (SK): Generic string for entity types (e.g.,
METADATA,STEP#01).
Access Patterns:
- Get Request Metadata:
PK=REQID#123,SK=METADATA. - Get Request History:
PK=REQID#123,SK begins_with(STEP#). - List Requests by Client:
GSI1_PK=CLIENT#777,GSI1_SK=TIMESTAMP.
Consequences
Section titled “Consequences” ✓ Positive Consequences
- Performance: Single round-trip to fetch multiple related items (if modeled correctly).
- Cost: Shared throughput across different entity types.
✗ Negative Consequences
- Flexibility: Harder to change access patterns later compared to SQL.
- Learning Curve: Requires deep understanding of DynamoDB modeling.