"Every database needs a fixed set of columns, defined up front." That is true for a classic relational table, but not for Amazon DynamoDB. In DynamoDB only the primary key is fixed. Every other attribute can differ from one item to the next, which is why it is so popular for fast-moving application data.
What DynamoDB is
DynamoDB is a serverless key-value and document database. There are no servers, versions or storage volumes for you to manage: you create a table and start reading and writing. AWS describes its performance as single-digit millisecond latency at any scale, and a table has no practical size limit.
Tables, items and attributes
Three words cover the whole data model:
- A table is a collection of items, like a table in any database (for example Customers or Orders).
- An item is one record in that table, similar to a row. A table can hold any number of items.
- An attribute is one piece of data inside an item, similar to a field or column:
name,phone,status.
Attributes can be simple values (strings, numbers, binary, booleans) or nested maps and lists, up to 32 levels deep. So one item can hold an entire address object or a list of tags.
Because the table is schemaless apart from the key, item 1 can have a name and a phone while item 2 adds an address and a loyalty tier. Nobody has to run a migration to add a column. The flip side: your application, not the database, is responsible for keeping the data consistent.
The primary key
When you create a table you must choose its primary key, and you cannot change it later. It uniquely identifies every item: two items can never share the same key.
- A simple key is just a partition key, such as
customerId. - A composite key adds a sort key, such as
customerId+orderDate. Part 2 of this series covers how the two work together.
Key attributes must be a string, number or binary. Give DynamoDB the full key and it returns that item directly, without reading the rest of the table. That direct lookup is the heart of DynamoDB's speed.
The 400 KB rule
An item can be at most 400 KB, and that limit counts the attribute names as well as the values. Writes that go over it fail with a validation error. The standard pattern for anything large (PDFs, images, long transcripts) is to put the object in Amazon S3 and store its key or URL in the DynamoDB item. Short attribute names also help on big tables, since every name is stored in every item.
Where AI fits
Chat-based AI apps need to save conversation history and session state, read it back in milliseconds, and throw it away later. DynamoDB fits that well. Store each message as an item under its session ID, so one request fetches the conversation. Then add a time to live (TTL) attribute: DynamoDB deletes expired items automatically, typically within a few days of the expiry time, without consuming write throughput. Old chats clean themselves up.
Quick recap
- Tables hold items; items hold attributes.
- Only the primary key is fixed; everything else can vary per item.
- Items are capped at 400 KB: keep big files in S3 and store the link.