# Key-Value Stores and DynamoDB

> Use key-value data stores like Redis as a primary store and DynamoDB for serverless-scale workloads. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/key-value-dynamodb
Last updated: 2026-11-28

Use key-value data stores like Redis as a primary store and DynamoDB for serverless-scale workloads.

Intermediate · about 5 hours · difficulty 3/5

Learn first: [NoSQL Families and When to Use Them](https://www.internhack.in/roadmaps/tracks/backend/nosql-fundamentals), [Server-Side Caching with Redis](https://www.internhack.in/roadmaps/tracks/backend/server-side-caching)

Key-value databases trade query flexibility for predictable speed: you fetch or write by key, and the system can spread keys across many machines.

### Redis beyond caching

You met Redis as a cache. It also works as a primary store for data with simple access patterns, using its data structures directly:

- **Hashes** for objects, **sorted sets** for leaderboards and time-ordered feeds, **sets** for membership, **streams** for event logs.
- Atomic commands like `INCR` and Lua scripts for counters and rate limiters.

Understand its persistence options (**RDB** snapshots, **AOF** logs) before trusting it with data you cannot lose.

### DynamoDB

Amazon's managed key-value and document database scales to huge throughput with no servers to run. Its model is strict:

- Every item has a **partition key** (and optionally a **sort key**). Queries must specify the partition key; scanning the whole table is slow and expensive.
- **Global secondary indexes** give you additional access patterns.
- **Single-table design** stores several entity types in one table with carefully designed keys like `PK = USER#42`, `SK = ORDER#2024-05-01`.
- Capacity is **on-demand** or **provisioned**, and hot partitions throttle.

### When they fit

Session stores, shopping carts, feature flags, user profiles fetched by id, IoT device state and serverless apps where you want zero database administration.

### Pitfalls

- Choosing DynamoDB before knowing your queries, then needing ad hoc filtering it cannot do efficiently.
- Low-cardinality partition keys (like `status`) that create hot partitions.

You are ready to move on when you can design a DynamoDB key schema for users and their orders that answers "orders for user X, newest first" without a scan.

## Key concepts

- **Redis data structures as primary data**
- **Redis persistence: RDB and AOF**
- **Partition and sort keys**
- **Global secondary indexes**
- **Single-table design**
- **Hot partitions and capacity modes**

## Mini project

Build a leaderboard with Redis sorted sets and an order history table in DynamoDB Local with a key design that supports two different query patterns.

## Check yourself

Why does DynamoDB punish you for not knowing your access patterns up front?

## Free resources

- [Amazon DynamoDB Developer Guide](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) (AWS)
- [DynamoDB best practices](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html) (AWS)
- [Redis data types](https://redis.io/docs/latest/develop/data-types/) (Redis)

Previous: [Document Databases with MongoDB](https://www.internhack.in/roadmaps/tracks/backend/mongodb) · Next: [Wide-Column Stores: Cassandra and ScyllaDB](https://www.internhack.in/roadmaps/tracks/backend/cassandra-wide-column)

## More in Beyond Relational: NoSQL and Search

- [NoSQL Families and When to Use Them](https://www.internhack.in/roadmaps/tracks/backend/nosql-fundamentals)
- [Document Databases with MongoDB](https://www.internhack.in/roadmaps/tracks/backend/mongodb)
- [Key-Value Stores and DynamoDB](https://www.internhack.in/roadmaps/tracks/backend/key-value-dynamodb)
- [Wide-Column Stores: Cassandra and ScyllaDB](https://www.internhack.in/roadmaps/tracks/backend/cassandra-wide-column)
- [Graph Databases with Neo4j](https://www.internhack.in/roadmaps/tracks/backend/graph-databases)
- [Time-Series Databases](https://www.internhack.in/roadmaps/tracks/backend/time-series-databases)
- [Full-Text Search Fundamentals](https://www.internhack.in/roadmaps/tracks/backend/full-text-search-basics)
- [Search Engines: Elasticsearch and OpenSearch](https://www.internhack.in/roadmaps/tracks/backend/elasticsearch-opensearch)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
