Lesson 1 of 5 Operational and Purpose-Built Databases

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.

ElementMeaning
Partition keyShould have high cardinality (e.g. customer ID) so load spreads evenly
Sort keyEnables 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.

How DynamoDB keys organise items. The partition key, customer ID, decides which partition holds an item, so many distinct customers spread the load. The sort key, order date, orders items within a partition, so one query returns a customer's orders between two dates. A global secondary index offers a different key for another access pattern.
The items are illustrative; highlighted items match the query.
Sort into groups

GSI or LSI?

Exam skills 2.4.1 · 2.1.2

Decide whether each statement describes a global or a local secondary index.

Log in to try this activity Interactive activities are free with an account.

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.

Scenario questions

DynamoDB capacity

Exam skills 2.1.2 · 1.1.9

Choose the DynamoDB setting for each situation.

Log in to try this activity Interactive activities are free with an account.

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.

OptionWhat it does
DynamoDB StreamsItem-level changes, including TTL deletions, for 24 hours, for Lambda or Kinesis pipelines
Export to S3Full or incremental exports from point-in-time recovery for Athena or Glue, using no table capacity
Zero-ETL integrationsReplicate data to Redshift and OpenSearch

The following diagram compares the ways of getting the table's data out.

Ways to get the orders table out for analytics. Scanning the table with a script consumes read capacity and can throttle the application. Export to S3 uses point-in-time recovery data and no table capacity; DynamoDB Streams feeds near-real-time pipelines, including TTL deletions; and zero-ETL integrations replicate to Redshift or OpenSearch. The team uses incremental exports for the lake.
Export to S3 requires point-in-time recovery (PITR).
Match the pairs

DynamoDB to analytics

Exam skills 2.1.5 · 1.1.2

Match each requirement with the way to get DynamoDB data out.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

OptionEffect on the tableFreshness
Scan the table with a scriptConsumes read capacity; can throttle the applicationAs often as it runs
Export to S3 (requires point-in-time recovery)NoneFull or incremental exports, e.g. hourly
DynamoDB Streams with Lambda or KinesisNoneNear real time
Zero-ETL integration with Redshift or OpenSearchNoneNear 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.

Check yourself

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.