DynamoDB is a cloud-based NoSQL database that stores information in a key-value format. As a non-relational database, it does not use structured tables like traditional relational databases, allowing for greater flexibility and scalability. This allows applications to quickly access and manage large amounts of data without performance issues.
Understanding DynamoDB’s core features is important for using it effectively in AWS-based systems. This post covers key DynamoDB concepts to help you build scalable and cost-efficient NoSQL solutions. 💡
Primary Keys
DynamoDB uses partition keys or composite primary keys (partition key + sort key) to uniquely identify records. 🔑
✅ Partition Key as the Primary Key
If a table has only a partition key, records are retrieved by directly referencing the key value.
📌 Example: A table storing video games, where the partition key is the game title:
Press enter or click to view image in full size
Here, each record is uniquely identified by Game Title, and fetching a record requires providing the exact primary key value. ✨
✅ Composite Primary Key: Partition Key + Sort Key
For more complex data structures, a table may include both a partition key and a sort key, forming item collections.
📌 Example: A table where the partition key is Developer, and the sort key is Game Title:
Press enter or click to view image in full size
This enables efficient Query operations, which retrieve multiple items from an item collection rather than scanning the entire table. ⚡
📚 Worth to check:
Core components of Amazon DynamoDB
Learn about the building blocks of DynamoDB your app will need. You'll discover the basics of tables, items…
docs.aws.amazon.com
📚 Alex Debrie — The DynamoDB Book
How to Access Data in DynamoDB
- Item-Based Actions (GetItem, PutItem, UpdateItem, DeleteItem) Work on single records. Require specifying the full primary key. Batch Operations (BatchGetItem, BatchWriteItem) Effectively perform multiple item-based actions. BatchGetItem supports up to 100 items, while BatchWriteItem supports up to 25 items per operation. 🚀
- Query API Action Retrieves multiple records within the same partition key = operates on item collection. Always requires specifying PK. Faster than Scan because it targets a specific subset of data.
- Scan API Action ⚠️ Reads the entire table, making it slow and expensive. Should be avoided unless absolutely necessary. 📌 Code Examples: AWS DynamoDB Query & Scan Examples
Secondary Indexes: Unlocking More Query Power
DynamoDB supports Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI), enabling flexible query patterns beyond the primary key.
Learn about Medium’s values
✅ Global Secondary Index (GSI)
Allows querying on non-primary attributes.
Uses a different partition key and optional sort key.
Supports eventual consistency by default.
Requires additional read/write capacity.
Use case: Fetching all orders by CustomerID in an e-commerce app.
✅ Local Secondary Index (LSI)
Uses the same partition key but a different sort key.
Reads can be either eventually consistent or strongly consistent.
Must be created at table creation.
Shares base table’s read/write capacity.
Use case: Fetching all blog posts by an author, sorted by date.
📌 Key Differences
--
DynamoDB Streams: Reacting to Changes in Real-Time
DynamoDB Streams allow you to respond to changes occurring in a DynamoDB table in real time. Every modification in the table is sent to a stream, which can then be filtered and processed further.
For example, the stream data can be linked to an EventBridge Pipe for event filtering and later on linked with AWS Lambda function to trigger automated actions based on updates.
Press enter or click to view image in full size
DynamoDB Streams can be integrated with multiple AWS services, including Lambda, Kinesis, EventBridge, SQS, and SNS, making them a powerful tool for event-driven architectures, logging, and replication.
Amazon DynamoDB Accelerator (DAX): Supercharge Your Reads
DAX is a caching service designed for DynamoDB, reducing read latency from milliseconds to microseconds. Ideal for applications with high read frequency. ⚡
Top comments (0)