InterviewHubPRO
Section Overview
Q36

Question 36 of 60

Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)

60%
Databases & System Design•Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)

DynamoDB Partition Keys, Sort Keys & Hot Partitions:

In Simple Words:

  • Partition Key (HASH): Determines which physical storage partition data goes to.
  • Sort Key (RANGE): Orders items within the partition.
  • Hot Partition: Occurs when access heavily hits a single key, exceeding per-partition limits (1,000 WCU or 3,000 RCU).
typescript
// AWS SDK v3 DynamoDB Query using Partition Key (PK) and Sort Key (SK):
import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb";

const command = new QueryCommand({
  TableName: "AppTable",
  KeyConditionExpression: "PK = :pk AND SK begins_with(:skPrefix)",
  ExpressionAttributeValues: {
    ":pk": { S: "USER#101" },
    ":skPrefix": { S: "ORDER#" }
  }
});