Bird
0
0

You are designing a single DynamoDB table to store customers and their orders. Which key design allows efficient retrieval of all orders for a customer and quick access to a specific order?

hard🚀 Application Q8 of 15
DynamoDB - Access Patterns and Query Optimization
You are designing a single DynamoDB table to store customers and their orders. Which key design allows efficient retrieval of all orders for a customer and quick access to a specific order?
APartition key: <code>ORDER#<orderId></code>, Sort key: <code>CUSTOMER#<customerId></code>
BPartition key: <code>CUSTOMER#<customerId></code>, Sort key: <code>ORDER#<orderId></code>
CPartition key: <code>ORDER#<orderId></code>, Sort key: <code>DATE#<orderDate></code>
DPartition key: <code>CUSTOMER#<customerId></code>, Sort key: <code>DATE#<orderDate></code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify query patterns

    We need to fetch all orders for a customer and also a specific order quickly.
  2. Step 2: Analyze key design

    Using PK as 'CUSTOMER#' groups all orders under one partition; SK as 'ORDER#' uniquely identifies each order.
  3. Step 3: Benefits

    This design supports querying all orders by customer and retrieving a specific order by SK.
  4. Final Answer:

    Partition key: CUSTOMER#, Sort key: ORDER# -> Option B
  5. Quick Check:

    Check if design supports both query patterns efficiently [OK]
Quick Trick: PK groups customer orders; SK uniquely identifies orders [OK]
Common Mistakes:
MISTAKES
  • Using order ID as PK prevents grouping orders by customer
  • Using date as SK alone does not uniquely identify orders
  • Reversing PK and SK roles reduces query efficiency

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes