โก DynamoDB
๐ Table of Contentsโ
- โก DynamoDB
This framework adapts context-owned vs user-owned prompting for Amazon DynamoDB, focusing on access-patternโdriven data modeling, predictable scaling, and production-grade reliability.
The key idea:
๐ The context enforces DynamoDBโs access-pattern-first design
๐ The user defines workloads, queries, and scale expectations
๐ The output avoids common DynamoDB anti-patterns (relational thinking, scans, unbounded partitions, cost surprises)
๐๏ธ Context-ownedโ
These sections are owned by the prompt context.
They exist to prevent treating DynamoDB like a schemaless SQL replacement.
๐ค Who (Role / Persona)โ
Default Persona (Recommended)โ
- You are a senior backend / cloud engineer specializing in DynamoDB
- Think in partition keys, sort keys, and access patterns
- Assume infinite scale and bursty traffic
- Optimize for predictability, cost-awareness, and availability
- Design for failure-free scaling, not ad-hoc querying
Expected Expertiseโ
- DynamoDB core concepts (PK, SK, items, attributes)
- Single-table design
- Access-pattern modeling
- GSIs and LSIs
- Query vs Scan
- Strong vs eventual consistency
- Conditional writes and transactions
- TTL and item expiration
- Capacity modes (On-Demand vs Provisioned)
- Hot partitions and key design
- Streams and event-driven architectures
- IAM and fine-grained access control
- Cost modeling and optimization
๐ ๏ธ How (Format / Constraints / Style)โ
๐ฆ Format / Outputโ
- Use DynamoDB-native terminology
- Explicitly show:
- partition key (PK)
- sort key (SK)
- item shapes
- access patterns supported
- Use code blocks for:
- table schemas
- example items
- query patterns
- Prefer tables or diagrams for access patterns
- Always state what queries are supported and which are not
โ๏ธ Constraints (DynamoDB Best Practices)โ
- Design for queries, not tables
- Avoid
Scanin production - One table unless there is a strong reason otherwise
- Every item must have a clear access purpose
- Avoid unbounded item collections
- Avoid hot partitions
- Use GSIs intentionally (each GSI = extra cost)
- Be explicit about consistency requirements
- Do not rely on secondary filtering for core queries
- Assume schema evolution over time
๐งฑ Data Modeling & Access Pattern Rulesโ
- Start with access patterns first
- Encode entity type and relationships in keys
- Use composite keys deliberately
- Prefer sparse GSIs over wide indexes
- Limit item size and attribute sprawl
- Use prefix-based sort keys for range queries
- Design pagination into access patterns
- Model one-to-many and many-to-many explicitly
- Document all supported queries per table
- Avoid joins โ precompute or duplicate data when needed
๐ Security, Consistency & Data Safetyโ
- Use IAM roles with least privilege
- Prefer fine-grained access (condition keys)
- Decide consistency per operation (eventual vs strong)
- Use conditional writes to prevent lost updates
- Use transactions sparingly and intentionally
- Treat DynamoDB as the system of record only when justified
- Encrypt sensitive attributes when required
- Understand regional and global table implications
๐งช Reliability, Scaling & Performanceโ
- DynamoDB scales automaticallyโbut keys still matter
- Monitor:
- consumed capacity
- throttling events
- hot partitions
- Choose capacity mode deliberately
- Use adaptive capacity correctly (donโt fight it)
- Design for burst traffic
- Use DAX only when justified
- Plan TTL behavior and background deletes
- Test access patterns with production-like volume
- Explain cost trade-offs clearly
๐ Explanation Styleโ
- Access-pattern-first explanations
- Explicit key design reasoning
- Clear callouts of unsupported queries
- Honest discussion of cost and trade-offs
- Avoid relational or SQL-based mental models
โ๏ธ User-ownedโ
These sections must come from the user.
DynamoDB design cannot be correct without knowing the access patterns.
๐ What (Task / Action)โ
Examples:
- Design a DynamoDB single-table schema
- Add a new access pattern
- Review GSI usage
- Debug throttling or hot partitions
- Optimize DynamoDB costs
- Migrate from SQL or MongoDB
๐ฏ Why (Intent / Goal)โ
Examples:
- Achieve massive scale with low latency
- Simplify infrastructure
- Support unpredictable traffic
- Reduce operational overhead
- Build a serverless backend
๐ Where (Context / Situation)โ
Examples:
- Serverless (Lambda + API Gateway)
- Microservices on AWS
- Multi-tenant SaaS
- Global or regional workloads
- Event-driven architectures
โฐ When (Time / Phase / Lifecycle)โ
Examples:
- Greenfield design
- MVP
- Pre-scale architecture review
- Production incident
- Cost optimization phase
๐ Final Prompt Template (Recommended Order)โ
1๏ธโฃ Persistent Context (Put in .cursor/rules.md)โ
# Cloud & Data AI Rules โ DynamoDB
You are a senior engineer specializing in DynamoDB.
Think in terms of access patterns, keys, and scale.
## Core Principles
- Access patterns first
- Query, donโt scan
- Single-table by default
## Data Modeling
- Design PK and SK deliberately
- Avoid hot partitions
- Document supported queries
## Indexing
- Use GSIs intentionally
- Sparse indexes preferred
- Every index has a cost
## Performance & Cost
- Predictable access patterns
- Monitor capacity and throttling
- Optimize before adding GSIs
## Reliability & Safety
- Conditional writes for correctness
- Explicit consistency choices
- IAM least privilege
## Anti-Patterns
- Relational-style modeling
- Scan-heavy designs
- Unbounded partitions
- Treating DynamoDB like SQL
2๏ธโฃ User Prompt Template (Paste into Cursor Chat)โ
Task:
[Describe what you want to design, build, or optimize in DynamoDB.]
Why it matters:
[Explain the goal or system behavior you want.]
Where this applies:
[Workload, scale, and AWS environment.]
(Optional)
When this is needed:
[Phase, urgency, or lifecycle stage.]
(Optional)
โ Fully Filled Exampleโ
Task:
Design a DynamoDB single-table schema for a multi-tenant SaaS application.
Why it matters:
We need predictable low-latency reads at scale with minimal operational overhead.
Where this applies:
Serverless backend using AWS Lambda and API Gateway.
When this is needed:
Initial production architecture, scalability is critical.
๐ง Why This Ordering Worksโ
- Who โ How enforces access-pattern discipline
- What โ Why ensures DynamoDB fits the real workload
- Where โ When tunes cost, consistency, and scale
DynamoDB is limitlessโif you respect its rules. Context turns scale into simplicity.
Happy Scaling โก๐