DynamoDB Tables

Understanding how DynamoDB organizes data is the first step to designing a working database. Tables, items, and attributes form the backbone of every DynamoDB application. This topic gives you a practical, hands-on understanding of each component.

What Is a DynamoDB Table?

A table is a named collection of data. You create one table for each type of entity in your application. An e-commerce app might have a Products table, a Users table, and an Orders table.

Think of a table as a very smart filing cabinet. You label the cabinet with a name, and then you place labeled folders (items) inside it. The cabinet does not dictate what goes into each folder — each folder can hold different content.

Table Names

DynamoDB table names must follow these rules:

  • Between 3 and 255 characters long
  • Only letters, numbers, underscores, hyphens, and dots are allowed
  • Case-sensitive: Users and users are different tables
  • Must be unique within the same AWS region and account

What Is an Item?

An item is a single record stored inside a table. It is comparable to a row in a spreadsheet, but without the constraint that every row must look the same.

Each item must contain the table's primary key. Beyond that, the item can have any attributes you choose — or none at all, other than the key.

Example: A Library Book Catalogue

TABLE: Books
┌─────────────────────────────────────────────────┐
│ ITEM 1                                          │
│   BookID: "B001"       ← Partition Key          │
│   Title: "The Alchemist"                        │
│   Author: "Paulo Coelho"                        │
│   Language: "English"                           │
├─────────────────────────────────────────────────┤
│ ITEM 2                                          │
│   BookID: "B002"       ← Partition Key          │
│   Title: "Godan"                                │
│   Author: "Munshi Premchand"                    │
│   Language: "Hindi"                             │
│   Pages: 432           ← Extra attribute        │
├─────────────────────────────────────────────────┤
│ ITEM 3                                          │
│   BookID: "B003"       ← Partition Key          │
│   Title: "Wings of Fire"                        │
│   Author: "APJ Abdul Kalam"                     │
│   Awards: ["Padma Vibhushan", "Bharat Ratna"]   │
└─────────────────────────────────────────────────┘

Item 2 has a Pages attribute that Item 1 does not. Item 3 has an Awards list that neither of the others has. DynamoDB handles this naturally — there is no error for missing or extra attributes.

Item Size Limit

Each item in DynamoDB can be a maximum of 400 KB in size. This size includes all attribute names and values combined. For most use cases, 400 KB is more than enough. For storing large files like images or videos, use Amazon S3 instead, and store only the file's URL as a string attribute in DynamoDB.

What Is an Attribute?

An attribute is a single piece of information within an item. It has a name and a value. For example, "Language": "Hindi" is one attribute with the name Language and the value Hindi.

Top-Level vs Nested Attributes

Top-level attributes sit directly inside an item. Nested attributes sit inside a Map (a type of attribute). Both are valid and useful.

ITEM: Employee
{
  "EmployeeID": "E101",           ← Top-level attribute
  "Name": "Kavita Singh",         ← Top-level attribute
  "Department": "Engineering",    ← Top-level attribute
  "ContactInfo": {                ← Top-level Map attribute
    "Phone": "9876543210",        ← Nested attribute
    "Email": "kavita@example.com" ← Nested attribute
  }
}

Schema Flexibility in Practice

DynamoDB's schema-free nature means you can evolve your data model without downtime. In a SQL database, adding a new column to a table with millions of rows requires a migration that can lock the table for minutes or hours. In DynamoDB, you simply start including the new attribute in new items. Old items that lack the attribute are not affected.

Example: Adding a Feature Gradually

Suppose you add a LoyaltyPoints feature to your app. You can add LoyaltyPoints as an attribute to new users immediately and add it to existing users over time — with zero migration or downtime.

Creating a Table: What You Must Define Upfront

Despite being schema-free, you must define these three things when you create a DynamoDB table:

  1. Table Name — what you call the table
  2. Primary Key — which attribute(s) uniquely identify each item
  3. Capacity Mode — how DynamoDB allocates read and write throughput

Everything else — attribute names, attribute types for non-key fields — you define on the fly as you insert items.

How Tables Are Accessed

Each DynamoDB table belongs to a specific AWS region. If your application runs in the ap-south-1 (Mumbai) region, your DynamoDB tables should also be in that region for the lowest latency. Data stored in one region is not automatically available in another region unless you configure Global Tables.

Multiple Tables vs Single Table Design

New DynamoDB users often create one table per entity type — a Users table, an Orders table, a Products table. This works well for small applications.

Experienced DynamoDB designers often use a Single Table Design — one table that holds all entity types, differentiated by key patterns. This advanced pattern reduces cost and improves performance. The Design Patterns topic at the end of this course covers it in full.

Summary

ComponentDescriptionAnalogy
TableNamed container for all items of one typeFiling cabinet
ItemOne record inside a table; must have a primary keyLabeled folder in the cabinet
AttributeA name-value pair inside an item; can be nestedA sheet of paper inside the folder

Leave a Comment

Your email address will not be published. Required fields are marked *