# DynamoDB

DynamoDB is our NoSQL database for flexible metadata that changes frequently.

## What is DynamoDB?

AWS NoSQL database with flexible schemas. Perfect for data that evolves rapidly without migrations.

## Table: `item-info`

**File**: `studio_api/studio_api/dynamodb/item_info_handler.py`

Single table design with different item types.

## Access Pattern

```python
from studio_api.dynamodb.item_info_handler import item_info_handler

# Save clip metadata
item_info_handler.update_item_fields(
    item_id=clip_id,
    item_type="clip",
    fields={
        "audio_bpms": [120, 121, 119, 120],
        "audio_key_v1": "C major",
        "audio_genre_tags": ["pop", "electronic"],
    }
)

# Retrieve specific fields
data = item_info_handler.get_item_fields(
    item_id=clip_id,
    item_type="clip",
    fields=["audio_bpms", "audio_key_v1"]
)
# Returns: {"audio_bpms": [...], "audio_key_v1": "C major"}

# Delete fields
item_info_handler.delete_item_fields(
    item_id=clip_id,
    item_type="clip",
    fields=["audio_genre_tags"]
)
```

## Pros

✅ **Schema Flexibility** - Add fields without migrations

✅ **High Throughput** - Scales to millions of read/writes per second

✅ **No Downtime** - Add new fields instantly

✅ **Auto-Scaling** - Handles traffic spikes automatically

✅ **Good for ML** - ML features evolve rapidly

## Cons

❌ **No JOINs** - Can't query across item types

❌ **Eventual Consistency** - Default consistency model

❌ **Query Limitations** - Must know partition key

❌ **Cost** - More expensive than PostgreSQL for small datasets

## When to Use

### ✅ Use DynamoDB for:
- Large metadata schemas
- Data that changes schema frequently
- High-throughput read/write patterns
- Data that doesn't require relationships

### ❌ Don't use DynamoDB for:

import { Callout } from 'nextra/components'


  DynamoDB should not be used for:
  - Data needing complex queries or JOINs
  - Data with many relationships

