Core NoSQL Concepts
Foundational concepts of distributed serverless database models.
Document vs. Key-Value
NoSQL uses flexible models. Document stores (Firestore/Cosmos) serialize records as hierarchical JSON objects. Key-Value stores (DynamoDB) store records as flat attributes queryable by a primary key.
Partitioning & Sharding
Scale horizontally by spreading data across multiple physical storage partitions. Routing nodes use a hash of the Partition Key to instantly locate the record without full-table scans.
Consistency Modes
NoSQL trades consistency for speed. Eventual consistency serves reads faster but might return stale data. Strong consistency guarantees the absolute latest write but increases latency.
Real-time Subscriptions
Listen to database changes in real-time. Firestore provides native SDK listeners. DynamoDB and Cosmos DB offer Change Streams that trigger Lambdas or Azure Functions on every insert/update.
Secondary Indexing
Querying on fields other than the partition key requires secondary indexes (GSIs in DynamoDB, automatic indexing in Firestore/Cosmos DB). Essential for complex agent task queries.
TTL & Cache Eviction
Time-to-Live automatically evicts records after a specific timestamp. Crucial for purging short-term session state, token caches, and execution scratchpads without costs.
Comparing NoSQL Options
Comparing AWS DynamoDB, GCP Firestore, and Azure Cosmos DB.
Setup Guide
Get your database SDK dependencies installed and configured.
DynamoDB (AWS)
Firestore (GCP)
Cosmos DB (Azure)
Usage Examples
Comparing write and read operations across the databases in Python.
Best Practices
Essential practices for designing scalable cloud NoSQL storage.
🔑 Partition Key Strategy
- • Avoid "hot partitions" by choosing high-cardinality keys like
session_id - • Do not use dates or constant strings as partition keys
- • Use composite keys (e.g. partition key + sort key) to query historical ranges
- • Restrict scan operations; use explicit key queries instead
💡 Query Design
- • Model data based on query patterns, not relational structures
- • Design indexes (GSI/LSI) specifically for your application filter routes
- • Avoid excessive indexes to save on write capacity costs
- • Leverage projections to return only required attributes
💰 Cost Optimization
- • Enable auto-scaling or on-demand provisioning for serverless
- • Define a TTL attribute on sessions to auto-cleanup data
- • Cache frequently accessed items in Redis to reduce reads
- • Use batch APIs (
BatchWriteItem, etc.) for bulk data inserts
Frequently Asked Questions
Which NoSQL database is best for AI agent memory?▶
Does DynamoDB support vector similarity search?▶
What is Single-Table Design in DynamoDB?▶
PK and SK) rather than
separate schemas. This guarantees that all required view data can be fetched in a single
request, optimizing read capacity.How do I handle transactions in serverless NoSQL?▶
TransactWriteItems, Firestore has transactions via the client,
and Cosmos DB supports multi-document transactions using stored procedures written in
JavaScript. However, transactions consume more capacity units and should be used sparingly.