Bird
0
0

You want to design a DynamoDB table to store user activity logs. Each user can have multiple logs per day. Which key design is best to efficiently query all logs for a user on a specific day?

hard📝 Application Q15 of 15
AWS - DynamoDB

You want to design a DynamoDB table to store user activity logs. Each user can have multiple logs per day. Which key design is best to efficiently query all logs for a user on a specific day?

APartition key: UserId, Sort key: ActivityDateTime
BPartition key: ActivityDateTime, Sort key: UserId
CPartition key: UserId_ActivityDate, Sort key: ActivityTime
DPartition key: ActivityType, Sort key: UserId
Step-by-Step Solution
Solution:
  1. Step 1: Understand query needs

    You want to query logs by user and by specific day efficiently.
  2. Step 2: Design keys for efficient queries

    Combining UserId and ActivityDate as partition key groups logs per user per day. Using ActivityTime as sort key orders logs within that day.
  3. Final Answer:

    Partition key: UserId_ActivityDate, Sort key: ActivityTime -> Option C
  4. Quick Check:

    Composite partition key groups user-day logs [OK]
Quick Trick: Combine user and date in partition key for day queries [OK]
Common Mistakes:
  • Using ActivityDateTime as partition key alone
  • Swapping partition and sort keys
  • Not combining keys to match query pattern

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes