AWS Series — All about DynamoDB
Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale.
It is a fully managed database and supports both document and key-value data models.
Its flexible data model and reliable performance make it a great fit for mobile, web, gaming, ad-tech, IoT, and many other applications.
- Stored on SSD storage
- Spread across 3 geographically distinct data centers
- Eventually consistent reads(default)
- Strongly consistent reads
Difference between Eventually Consistent Reads and Strongly Consistent Reads
Eventually — Consistency across all copies of data is usually reached within a second. Repeating a read after a short time should return the updated data. Best read performance.
Strongly — A strongly consistent read returns a result that reflects all writes that received a successful response prior to the read.
DynamoDB Accelerator (DAX)
- Fully managed, highly available, in-memory cache
- 10x performance improvement
- Reduces request time from milliseconds to microseconds — even under load
- No need for developers to manage caching logic
- Compatible with DynamoDB API calls
In traditional cache, the application query the cache and if it does not find the result, it would then call the Database and get the data and also populate the cache with the fetched data for future queries for the time it lives in.

With DAX, we have an application that directly queries the DAX and it communicates with the DynamoDB if the data is not present in DAX. It will bring the data out and then it will cache it in DAX itself. So your application is always connecting to DAX and it need not worry about going back to DynamoDB and query then feed to the cache. This is much more streamlined process.
On-Demand Capacity
- pay-per-request pricing
- Balance cost and performance
- No minimum capacity
- pay more per request than with provisioned capacity
- Use for new product launches
Security
- Encryption at rest using KMS
- site-to-site VPN
- Direct Connect (DX)
- IAM policies and roles
- Fine-grained access
- CloudWatch and CloudTrail
- VPC Endpoints
DynamoDB Transactions
ACID for Databases — Methodology of databases
- Atomic — All changes to the data must be performed successfully or not at all
- Consistent — Data must be in a consistent state before and after the transaction
- Isolated — No other process can change the data while the transaction is running
- Durable — The changes made by a transaction must persist.
ACID with DynamoDB
DynamoDB transaction provide developers atomicity, consistency, isolation and durability (ACID) across 1 or more tables within a single AWS account and region.
You can use transactions when building applications that require coordinated inserts, deletes or updates to multiple items as part of a single logical business operation
ACID basically means all or nothing. Transaction succeeds across 1 or more tables otherwise it fails across all tables
Use cases —
- Processing financial transactions
- Fulfilling and managing orders
- Building multiplayer game engines
- Coordinating actions across distributed components and services
Points to remember about transactions —
- We get 3 options for reads: eventual consistency, strong consistency and transactional
- 2 options for writes : standard and transactional
- Upto 25 items or 4 MB of data
Saving your data with DynamoDB Backups
with On-Demand Backup and Restore, we can do
- Full backups at any time
- Zero impact on table performance or availability
- Consistent within seconds and retained until deleted
- Operates within same region as the source table
With Point-in- time Recovery (PITR)
- Protects against accidental writes or deletes
- Restore to any point in the last 3 days
- Incremental backups
- Not enabled by default
- Latest restorable: 5 minutes in the past
Taking Your Data Global with DynamoDB Streams and Global Tables
What is DynamoDB Streams?

- Time ordered sequences of item-level changes in a table
- Stored for 24 hours
The data or the sequences are broken up into shards. Shard is a bunch of data that has sequential sequence numbers. So every time we make a change to a dynamoDB table, that data is going to be stored sequentially in a stream record which is broken to shards. It changes the data when insert, update and delete a record that gives us a FIFO time sequence. Those changes are stored in a dynamo DB stream and to make it manageable, we just basically split those sequences up into shards and you can also combine with Lambda functions for functionality like stored procedures in traditional databases.
What is Global Tables?
This is a Managed Multi-Master, Multi- Region replication. This is great for globally distributed applications.
It is based on DynamoDB streams. It should be turned on with Multi-region redundancy for disaster recovery or high availability. It is built into Dynamo DB natively. So we don’t have to rewrite applications. We can go into console and turn it on.
Replication latency is under 1 second in most cases.
Go To AWS Management Console > Database > DynamoDB

click on create table

Give the table name and the partition key and you can choose the type of key. this would be the unique identifier for the record like customer ID etc

Leave the default settings

Create the table. Open the created table and click on Explore table items

You can see the records. Now go to Actions > create item

We can see the primary key and give it an unique value. To add new attribute, click on Add new Attribute

You can select the type of attribute you add.

Click on create item after entering the attributes and values. This will add the data to our table.
Let us see how we can spread dynamoDB across multiple regions.
Go to the table and click on the Global Tables tab and click on Create Replica

We can choose the replication region

For enabling replica, we need DynamoDB Streams to be turned on. this would be in the Exports and streams tab.
We can select the region and create replica. Go to the location and you can see the table. Now create a new item in one region, and go to the other region, you will find the item which is replicated.
Points to Remember —
- Globally distributed applications
- Based on DynamoDB streams
- Multi-region redundancy for disaster recovery or high availability
- No application rewrites
- Replication latency is less than 1 second