Modelling DynamoDB Data and Exporting It for Analytics
This lesson explains Amazon DynamoDB, a serverless key-value and document database with single-digit millisecond latency at any scale, which is designed around access patterns known in advance, and how its data reaches analytics.
Learning outcomes
After completing this lesson, you will be able to:
- Design partition keys, sort keys and secondary indexes.
- Choose between on-demand and provisioned capacity.
- Expire data with TTL.
- Move data to analytics with Streams or export to S3.
Keys and indexes
A DynamoDB table is designed around its keys. The partition key decides which partition stores an item, so it should have high cardinality, many distinct values such as a customer ID, to spread traffic evenly; a key with few values creates hot partitions that throttle. An optional sort key orders items within a partition, enabling range queries, such as a customer's orders between two dates, and hierarchies.
Indexes support other access patterns. A global secondary index (GSI) uses an entirely different partition and sort key, can be added at any time, and is eventually consistent with the table. A local secondary index (LSI) keeps the table's partition key with a different sort key and must be created with the table. The following table summarises the elements.
| Element | Meaning |
|---|---|
| Partition key | Should have high cardinality (e.g. customer ID) so load spreads evenly |
| Sort key | Enables range queries and hierarchies, e.g. a customer's orders between two dates |
| Global secondary index (GSI) | Different keys for other access patterns; added any time; eventually consistent |
| Local secondary index (LSI) | Same partition key, different sort key; created with the table |
Single-table design stores several entity types in one table with generic key names, serving many access patterns efficiently.
The following diagram shows items grouped by partition key and ordered by sort key.

GSI or LSI?
Capacity and performance
DynamoDB offers two capacity modes. On-demand mode scales automatically with traffic and charges per request, which suits unpredictable or spiky workloads. Provisioned mode sets read and write capacity in advance, optionally with auto scaling, and is cheaper for predictable, steady traffic.
Throttling usually comes from hot partitions rather than from too little total capacity: DynamoDB spreads data across partitions by partition key, so when one key receives most of the traffic, its partition is throttled while others sit idle. High-cardinality partition keys prevent this. For read-heavy workloads that need microsecond latency, DynamoDB Accelerator (DAX) is an in-memory cache in front of the table.
DynamoDB capacity
Time to live (TTL)
TTL deletes items automatically, at no cost, once a timestamp attribute has passed, typically within a few days. Use it for sessions, temporary data and retention rules.
Getting data out for analytics
DynamoDB is built for fast key lookups, not analytical scans, so data is moved elsewhere for analytics. DynamoDB Streams records every item-level change, including deletions by TTL, for 24 hours, and Lambda or Kinesis-based pipelines process them in near real time. Export to S3 writes a full or incremental copy of the table from its point-in-time recovery data, which uses none of the table's read capacity, for querying with Athena or Glue. Zero-ETL integrations replicate the table to Redshift or OpenSearch continuously, without pipelines. The following table summarises the options.
| Option | What it does |
|---|---|
| DynamoDB Streams | Item-level changes, including TTL deletions, for 24 hours, for Lambda or Kinesis pipelines |
| Export to S3 | Full or incremental exports from point-in-time recovery for Athena or Glue, using no table capacity |
| Zero-ETL integrations | Replicate data to Redshift and OpenSearch |
The following diagram compares the ways of getting the table's data out.

DynamoDB to analytics
Getting DynamoDB data into the lake
An application stores orders in DynamoDB. Analysts want to query them in Athena, and the export must not consume the table's capacity or slow the application.
| Option | Effect on the table | Freshness |
|---|---|---|
| Scan the table with a script | Consumes read capacity; can throttle the application | As often as it runs |
| Export to S3 (requires point-in-time recovery) | None | Full or incremental exports, e.g. hourly |
| DynamoDB Streams with Lambda or Kinesis | None | Near real time |
| Zero-ETL integration with Redshift or OpenSearch | None | Near real time, no pipeline to manage |
The team uses incremental exports to S3 for the lake. Old session items are removed with TTL, which deletes them at no cost, and the deletions appear in the stream for any consumer that needs to know.
How are old DynamoDB items deleted automatically at no cost?
Show answer
With Time to Live (TTL), which deletes items after the time in a chosen attribute.
Exam Tips
Remember for the exam
- Throttling on a hot partition is fixed with a higher-cardinality partition key.
- A new query pattern on an existing table calls for a GSI.
- To expire old items automatically at no cost, use TTL.
- To analyse DynamoDB data without affecting the table, export it to S3 or use zero-ETL to Redshift.
- To react to item changes in a pipeline, use DynamoDB Streams with Lambda.
- Microsecond read latency calls for DAX.