Updated: 2023-09-01
6 min read
[aws dynamodb]


Fast and flexible NoSQL database service for performance with millisecond latency at any scale

How DynamoDB works


Amazon DynamoDB pricing

When you use the DynamoDB service, you are charged for reading, writing, and storing data in DynamoDB tables, as well as any additional features you enable. DynamoDB supports two resource provisioning modes that correspond to specific billing schemes for processing read and write operations on your tables: on-demand and with preparation. Click the following links to learn more about the billing options for each provisioning mode

Use Cases

Type: Key-value

Ecommerce Websites, gaming websites etc.


  • Global tables are useful for having multiple copies of tables in different region.
  • All DynamoDB tables are encrypted at rest using an AWS owned CMK by default.
  • Items - in DynamoDB is similar in many ways to rows, records, or tuples in other database systems. Each DynamoDB table contains zero or more items. An item is a collection of attributes that is uniquely identifiable for each record in that table.
  • Attributes - Each item is composed of one or more attributes. Attributes in DynamoDB are similar in many ways to fields or columns in other database systems.
  • Each item in the table has a unique identifier, a primary key, or a partition key that distinguishes the item from all of the others in the table. The primary key consists of one attribute.
  • Primary key
  • Partition key
  • Partition key and sort key (range attribute)
  • A primary key can either be a sinale-attribute partition key or a composite partition-sort key.
  • Both partition and sort keys attributes must be defined as type string, number, or binary.
  • Global secondary index - a partition key and a sort key that can be different from those on the base table; query at table level across all partitions; eventual consistency:
    • Different partition key and sort key from base table
    • Only eventually consistent
    • Can be created after table is created
    • Using a random prefix for the GSI partition key enables to have high cardinality for the partition key
  • Local secondary index - same partition key as the base table, but a different sort key: query on a single partition; eventual or strong consistency:
    • Same partition key, different sort key from base table
    • Eventual and strongly consistent
    • Should be created when creating a table
  • Calculate RCU (read capacity unit) & WCU (write capacity unit):
    • 1 RCU = 2 eventual consistent read of 4 KB, 1 strongly consistent read of 4 KB
    • 1 WCU = 1 write per second for data for an item as large as 1 KB.
  • DynamoDB Streams is an optional feature that captures data modification events in DynamoDB tables. The data about these events appears in the stream in near real time and in the order that the events occurred.
  • Queries or scan on GSI consume RCU on index not on table
  • Consistency:
    • Auto scaling
    • Storing session state could be on elastic cache or dynamodb
    • Provisioned throughput - ProvisionedThroughputExceededException
    • Reserved capacity, On-demand, Burst. Adaptive
    • On-demand backups, point-in-time recovery
  • Best practices when using Scan in dynamodb - Use parallel scan
    • to control the amount of data returned per request use the Limit parameter. This can help prevent situations where one worker consumes all the provisioned throuahput at the expense of all other workers
    • DynamoDB does not support item locking, and conditional writes are perfect for implementing optimistic concurrency.

DynamoDB vs Aurora

Amazon DynamoDBAmazon Aurora
Was developed by Amazon in 2012Was developed by Amazon in 2015.
It is hosted, scalable database service by Amazon with data stored in Amazon cloudIt is MySQL and PostgreSQL compatible cloud service by Amazon
It does not provide concept of Referential Integrity. Hence, no Foreign KeysIt provides concept of Referential Integrity. Hence, no Foreign Keys
Eventual Consistency and Immediate Consistency are used to ensure consistency in distributed systemImmediate Consistency is used to ensure consistency in distributed system
Its Primary database models are Document store and Key-value storeIts Primary database model is Relational DBMS
It does not support Server-side scriptingIt supports Server-side scripting
It supports sharding as partitioning methodPartitioning can be done with horizontal partitioning
It does not support SQL query languageIt supports SQL query language
It supports replication methodsIt supports only one replication method – Master-slave replication
It does not offer API for user-defined Map/Reduce methods. But maybe implemented via Amazon Elastic MapReduceIt does not offer API for user-defined Map/Reduce methods

DynamoDB supports different consistency models when performing reads:

  • Eventually, consistent reads may not always reflect the latest data if there was recently write activity on the table. Since the data in this scenario rarely changes, eventually consistent reads, which are cheaper than strongly consistent reads, can be tolerated.

DynamoDB Partition Key


Introduction to DynamoDB


AWS Database Blog



A developer is designing a web application that allows the users to post comments and receive in a real-time feedback.

Which architectures meet these requirements? (Select TWO.)

  1. Create an AWS AppSync schema and corresponding APIs. Use an Amazon DynamoDB table as the data store.
  2. Create a WebSocket API in Amazon API Gateway. Use an AWS Lambda function as the backend and an Amazon DynamoDB table as the data store
  3. Create an AWS Elastic Beanstalk application backed by an Amazon RDS database. Configure the application to allow long-lived TCP/IP sockets.
  4. Create a GraphQL endpoint in Amazon API Gateway. Use an Amazon DynamoDB table as the data store.
  5. Enable WebSocket on Amazon CloudFront. Use an AWS Lambda function as the origin and an Amazon Aurora DB cluster as the data store

AWS AppSync simplifies application development by letting users create a flexible API to securely access, manipulate, and combine data from one or more data sources. AWS AppSync is a managed service that uses GraphQL to make it easy for applications to get the exact data they need.

AWS AppSync allows users to build scalable applications, including those requiring real-time updates, on a range of data sources, including Amazon DynamoDB. In Amazon API Gateway, users can create a WebSocket API as a stateful frontend for an AWS service (such as AWS Lambda or DynamoDB) or for an HTTP endpoint.

The WebSocket API invokes the backend based on the content of the messages it receives from client applications. Unlike a REST API, which receives and responds to requests, a WebSocket API supports two-way communication between client applications and the backend.

1, 2