Question #6 of 60•Databases•Hard• ~3 min read

How does Amazon DynamoDB implement Partition Keys, LSIs, and GSIs?

Executive Takeaway

Analyze DynamoDB's data distribution mechanics, sorting ranges, and the cost/consistency differences between Local (LSI) and Global Secondary Indexes (GSI).

Architectural Breakdown & AnalysisFAANG Aligned

DynamoDB is a fully managed wide-column NoSQL database. Scaling seamlessly to petabytes requires understanding its partitioning and index architecture:

1. Primary Key: Partition Key (PK) & Sort Key (SK)

  • Partition Key (Hash Key): Hashed by DynamoDB to route items to physical storage partitions. Even distribution prevents hot partitions.
  • Sort Key (Range Key): Determines physical storage order within a partition, enabling range queries (begins_with, between).

2. Local Secondary Index (LSI)

  • Shares the same Partition Key as the base table, but uses a different Sort Key.
  • Shares read/write capacity units (RCU/WCU) with the base table.
  • Supports Strongly Consistent and Eventual Consistent reads.
  • Must be defined at table creation time.

3. Global Secondary Index (GSI)

  • Defines a completely new Partition Key and Sort Key.
  • Spans across all partitions with no size limits.
  • Requires dedicated provisioned RCU/WCU. If GSI writes throttle, parent table writes throttle too.
  • Supports Eventual Consistency only due to asynchronous replication.
WARNING — GSI Cost Optimization

Only project necessary attributes into GSIs. Projecting ALL attributes duplicates storage costs and multiplies write throughput consumption.

Key Architectural Comparison

DynamoDB Key / IndexPartitioning ScopeSort CapabilitiesConsistency OptionsThroughput Billing
Partition Key (PK)Determines physical storage partition.Hash match (=) only.Strong or Eventual.Base Table RCU / WCU.
Sort Key (SK)Physical row order within partition.Range queries (begins_with, between).Strong or Eventual.Base Table RCU / WCU.
Local Secondary Index (LSI)Same PK as base table; different SK.Range queries on new attribute.Strong or Eventual.Shares Base Table capacity (10 GB max limit).
Global Secondary Index (GSI)Completely new PK and SK.Global range queries across all items.Eventual Consistency Only.Dedicated provisioned RCU / WCU (Unbounded).
Previous QuestionWhich authorization and session mechanisms are required in distributed microservices?Next Question Which database should you choose for User Data, Transactions, Logs, and Analytics?

Continue Learning on Being SDE

Explore deep-dive system architecture modules, low-level object-oriented designs, and interview cheat sheets.