DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Lessons from Migrating an Oracle Database to AWS RDS
  • Designing a Blog Application Using Document Databases
  • Relational DB Migration to S3 Data Lake Via AWS DMS, Part I
  • NoSQL for Relational Minds

Trending

  • Docker Model Runner: Streamlining AI Deployment for Developers
  • Internal Developer Portals: Modern DevOps's Missing Piece
  • Unlocking AI Coding Assistants Part 2: Generating Code
  • The 4 R’s of Pipeline Reliability: Designing Data Systems That Last
  1. DZone
  2. Data Engineering
  3. Databases
  4. DynamoDB PrimaryKey, HashKey, SortKey (RangeKey)

DynamoDB PrimaryKey, HashKey, SortKey (RangeKey)

Let's check out DynamoDB and explore PrimaryKey, hashKey, and SortKey. Also take as look at a visual.

By 
Tomer Ben David user avatar
Tomer Ben David
·
Aug. 28, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
24.3K Views

Join the DZone community and get the full member experience.

Join For Free

Last week, I came across DynamoDB. Over the past few years, I have been fascinated by how the industry went from relational to NoSQL to NewSQL and then spread to all directions, collapsing into MySQL/Postgres, etc. The whole thing is both funny and fascinating.

From my past experience, whenever we used a KV store, we paid big time. Scalability comes with a check, you pay for losing features, and you gain by having high performance, so you have to tradeoff — Economy 101.

Anyway, I started reading about DynamoDB, which is a managed KV store, and noticed that there is complexity and powerfulness in its key structure and in its indexing. It took me some time to learn how it’s keysiness is working out and it took me some time to get how indexing works. I’m still unsure whether I got it or not. I want to share with you my visual understanding of it:

There are 3 basic building blocks or terms you should get familiar while first learning about DynamoDB, your data resides at:

  1. Table
  2. Item
  3. KV Attribute.

This is a 3 level hierarchy. It first belongs to a table (some use a single table), then to an item, and then your internal actual data values are in internal KV-attributes inside items.

You can fetch an item or items by its primary key. The way to fetch multiple items by a primary key query (which sounds weird at first), is to specify the hash key and then a range on the range key.

It’s as if your key is split in two.

  • Part 1: You have to specify it fully

  • Part 2: You can specify a range on it

More visually, as it's complex, this is the way I see it:

So, what is happening above? Notice the following observations. As we said, our data belongs to Table, Item, and KVAttribute. Then, every item has a primary key. The way you compose that primary key is meaningful to how you can access the data.

If you decide that your PrimaryKey is simply a hash key, then great! You can get a single item out of it. If you decide, however, that your primary key is hashKey + SortKey, then you could also do a range query on your primary key because you will get your items by (HashKey + SomeRangeFunction (on range key)). So, you can get multiple items with your primary key query.

Note: I did not refer to secondary indexes.

Hopefully some fog was cleared! Let me know your thoughts in the comments. 

Relational database

Opinions expressed by DZone contributors are their own.

Related

  • Lessons from Migrating an Oracle Database to AWS RDS
  • Designing a Blog Application Using Document Databases
  • Relational DB Migration to S3 Data Lake Via AWS DMS, Part I
  • NoSQL for Relational Minds

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!