DynamoDB Streams

Captures events in DynamoDB tables in near real-time, in the order they occurred. Each DynamoDB event is represented by a stream record. Monitored events:
  • A new item is added to the table
  • An item is updated
  • An item is deleted from the table
DynamoDB Streams
AWS docs

Core components

A table consists of items, where each item has a primary key (a unique identifier) that distinguishes it from all other items. In addition to the primary key, each item can have its own attributes. DynamoDB Core Components
AWS docs

Reading Data

There are 4 operations to read data: GetItem, BatchGetItem, Query, Scan. Reading Data in DynamoDB
AWS docs

Writing Data

  • PutItem/DeleteItem - Write or delete a single item. The primary key is the only required attribute.
  • BatchWriteItem - Write or delete up to 25 items in one request.
  • UpdateItem - Modify one or more attributes in an item. The primary key is the only required attribute.
AWS docs

Partitions

A partition is an allocation of storage for a table, backed by solid-state drives (SSDs) and automatically replicated across multiple Availability Zones within an AWS Region. You don't have to manage partitions; DynamoDB handles it automatically. DynamoDB Partitions
AWS docs

Read Consistency

DynamoDB provides read-committed isolation, ensuring that read operations always return committed values for an item. Reads will never show a view of an item from a write operation that did not ultimately succeed. However, read-committed isolation does not prevent modifications to the item immediately after the read operation.
  • Eventually consistent reads (default for DynamoDB) - The results of a recently completed operation may not be guaranteed. Over a short period, the response will eventually reflect the most recent data.
  • Strongly consistent reads (supported on tables and LSI) - Returns the most up-to-date data.
Strongly consistent reads always query the leader node (the first node in the write operation). Eventually consistent reads query any node (replica or leader), which may result in outdated data if the value was updated on the leader but not yet propagated to the replicas. DynamoDB Read Consistency
AWS docs

Transactions

You can group up to 100 actions in one call and submit them as a single all-or-nothing operation.
  • TransactionWriteItems operation can have - Put, Update, Delete and ConditionCheck actions.
  • TransactionGetItems operation consists of Get actions.
AWS docs

DynamoDB Accelerator

DynamoDB Accelerator is an in-memory caching service designed to improve DynamoDB performance. DAX addresses three core use cases:
  • Reduces response times for eventually consistent reads.
  • Simplifies operations and application complexity with a fully managed, API-compatible service.
  • For read-heavy or bursty workloads, DAX improves throughput and reduces costs by decreasing the need to overprovision read capacity units.
  • A DAX cluster handles GetItem, BatchGetItem, Query, and Scan operations.
DynamoDB Accelerator (DAX)
AWS docs

Backup and Restore

DynamoDB offers two types of backup:
  • Point-in-time recovery: Fully managed recovery points for up to 35 days, with per-second granularity. Costs are based on table size.
  • On-demand backups: Full table backups for long-term retention and archiving.
AWS docs

Throughput Capacity

On-Demand Capacity Mode
  • Pay only for what you use.
  • Set maximum read and write throughput per table to control costs.
  • Throttling may occur if throughput exceeds twice the previous peak within a 30-minute window.
Provisioned Capacity Mode
  • Pay for provisioned throughput.
  • Use auto-scaling to adjust the provisioned level based on utilization.
  • Reserved capacity offers discounts for 1 or 3-year upfront commitments on reads and writes.
Warm Throughput
  • Proactively scale read and write capacity to prevent throttling.
  • Available for reads, writes, or both.
  • Applies to on-demand and provisioned tables and incurs an additional charge.
AWS docs

Service Quotas

  • Read Capacity Unit (RCU): 1 strongly consistent read per second, or 2 eventually consistent reads per second, for items up to 4 KB in size.
  • Write Capacity Unit (WCU): 1 write per second for items up to 1 KB.
  • Table Size: No limit.
  • Number of Tables: Initial quota of 2500 tables per AWS Region.
  • Page Size for Query or Scan: 1 MB per page; if exceeded, the `LastEvaluatedKey` property is returned for the next page.
  • Local Secondary Indexes (LSI): Up to 5 per table.
  • Global Secondary Indexes (GSI): Default quota of 20 per table.
  • Item Size: Maximum of 400 KB.
AWS docs

Expressions

Use expressions to specify which attributes to read from an item, write data when a condition is met, specify how to update an item, define queries, and filter the results of a query:
  • Projection expression: Specify which attributes to retrieve using GetItem, Query, or Scan.
  • Condition expression: Use built-in functions and logical evaluations to specify which items to update with PutItem, UpdateItem, and DeleteItem operations.
  • Filter expression: Filter the items returned by a Query operation.
AWS documentation

Atomic Counter

The UpdateItem operation can be used to implement an atomic counter—a numeric value that is incremented or decremented with each UpdateItem call. Key points:
  • Non-idempotent updates: If an UpdateItem operation fails, the counter might still be updated, resulting in slight over-counting or under-counting.
  • Increment flexibility: You can specify a positive or negative increment value with each call.
AWS documentation

Primary key

A primary key is a unique attribute required for each item in a table. There are two types of primary keys:
  • Partition key - A simple primary key that consists of a single attribute.
  • Partition key and sort key - A composite primary key consisting of two attributes. The combination of the partition key and sort key must be unique across the table. The partition key determines the physical partition where the item will be stored, while the sort key provides additional flexibility for retrieving items.
AWS docs

Secondary indexes

One or more secondary indexes can be created on a table, offering more flexibility when querying data. AWS creates a copy of the table data to build the index. There are two types of secondary indexes:
  • Global secondary index (GSI) - An index with a partition key and sort key that can differ from those of the table.
  • Local secondary index (LSI) - An index that uses the same partition key as the table but has a different sort key.
AWS docs

Global Tables

Automatically replicates tables across multiple AWS Regions.
  • TTL (Time-to-Live) is automatically replicated to other regions.
  • Replication is completed within seconds.
  • Each region's table has an independent stream.
DynamoDB Global Tables
AWS docs

Global Secondary Index

A global secondary index includes a subset of attributes from the base table, organized by a different primary key. The index key does not need to include any of the table's key attributes and can have a different schema. Attribute projections:
  • KEYS_ONLY: Each index item contains only the table's partition and sort key values, plus the index key values.
  • INCLUDE: In addition to the attributes in KEYS_ONLY, the index includes specific non-key attributes.
  • ALL: The index includes all attributes from the source table.
Global Secondary Index (GSI)
AWS docs

Local Secondary Index

A local secondary index allows an additional sort key for the same partition key. Attribute projections:
  • KEYS_ONLY: Each index item contains only the table's partition and sort key values, plus the index key values.
  • INCLUDE: Includes specific non-key attributes in addition to KEYS_ONLY attributes.
  • ALL: The index includes all attributes from the source table.
Local Secondary Index (LSI)
AWS docs

LSI vs GSI

LSI vs GSI In general, choose LSI if you:
  • Require strongly consistent reads.
  • Want to avoid additional charges (writes to a GSI consume the write capacity units of both the base table and the GSI).
  • Plan to use the same partition key.
Choose GSI for all other use cases.
AWS documentation