AWS DynamoDB — Primary Key and Secondary Index

Overview

Our team has mostly been using S3 as a storage for the data. In the new project, I had a chance to explore a AWS’s NoSQL service, DynamoDB. With defined use cases in the project, I was responsible for finalizing a schema.

In the next couple posts, I would like to share my design process that includes some interesting implementation of DynamoDB. But first, this is a short summary of two important concepts in DynamoDB — Primary Key and Secondary Indexes. This document contains the full details and some examples.

Primary Key

  • Primary key uniquely defines each item in the table
  • DynamoDB supports two different kinds of primary keys: partition key and composite key
  • Partition key is a simple primary key composed of a single attribute. DynamoDB uses the partition key’s value as input to an internal hash function. The output of the function determines the partition in which the item will be sorted
  • Composite key is composed of partition key and sort key. The item with the same partition key are stored together in sorted order by sort key value. Composite primary key gives flexibility when querying data.

Secondary Index

  • Secondary index lets you query the data in the table using an alternative key, in addition to queries against the primary key
  • DynamoDB supports two kinds of indexes: Global secondary index (GSI) and Local secondary index (LSI)
  • Global secondary index (GSI) is an index with a partition key and sort key that are different from the those on the base table
  • Local secondary index (LSI) is an index with the same partition key as the base table, but a different sort key

--

--

--

Software Engineer | Scala | Functional Programming

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Hash Tables or Hash Maps

Why Do Senior Developers Face a Higher Interview Rejection Rate?

people sitting around a meeting room table watching a man give a presentation

Progressive Web Applications — A Gentle Introduction

Medium API Test RestAssured

Now that Reason 9.5 gets VST support, time for an analysis!

CS373: William Shi

Location, Location, Location

Memory Leak analysis in java

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
mj park

mj park

Software Engineer | Scala | Functional Programming

More from Medium

Experimenting with AWS Lambda Cold Starts

AWS Managed Streaming for Apache Kafka : Streaming messages from producer to consumer using Amazon…

AWS Lambda Reserved Concurrency v/s Provisioned Concurrency Scaling

AWS — CDK(Cloud Development Kit)