Databases

Amazon DynamoDB

A fully managed AWS key-value and document database with predictable latency and automatic scaling.

What it is

DynamoDB is a serverless NoSQL service from AWS. You do not manage servers: you create a table and AWS scales it and distributes data. Latency is typically single-digit milliseconds.

Each item has a partition key and optionally a sort key. Global and local secondary indexes give extra access patterns. Billing modes: on-demand or provisioned capacity.

The model demands designing access patterns up front, as in Cassandra. There are no joins and transactions are limited. In return you get huge scale with no administration.

Use it when

  • Serverless apps on AWS Lambda with predictable latency.
  • High loads with simple key-based access patterns.
  • You do not want to administer a database.

Avoid it when

  • Complex ad hoc queries and analytics: a SQL database.
  • You need portability across clouds: the service is tied to AWS.

Key concepts

Partition / sort key
The item's primary key and ordering inside a partition.
GSI / LSI
Secondary indexes for other access patterns.
Capacity modes
On-demand or provisioned (RCU/WCU).
Single-table design
Several entities in one table around access patterns.

Example

Querying a user's orders by partition key.

Interview questions

  1. 1. How does Query differ from Scan?

    Query reads items by partition key efficiently. Scan walks the whole table, slow and costly, so avoid it on the production path.

  2. 2. What is a hot partition?

    When a large share of traffic hits one partition key and runs into its limits. Fix it with a better key distribution.

  3. 3. Why single-table design?

    To fetch related entities in one query with no joins. The cost is a more complex model that is hard to change.

Comparisons with this technology

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).