#Data Management Patterns
Patterns for managing data in cloud applications.
#Key Patterns
#Cache-Aside Pattern
diagram
Application ──▶ Cache? ──▶ Yes ──▶ Return cached
│
No
│
▼
Database ──▶ Update cache ──▶ Return#CQRS (Command Query Responsibility Segregation)
diagram
Commands ──▶ Write Model ──▶ Database
│
▼
Queries ◀── Read Model ◀── Events#Event Sourcing
Store all changes as events:
Event 1: AccountCreated { id: 123 }
Event 2: MoneyDeposited { id: 123, amount: 100 }
Event 3: MoneyWithdrawn { id: 123, amount: 50 }#Sharding
| Strategy | Description |
|---|---|
| Hash-based | Hash of key determines shard |
| Range-based | Key ranges per shard |
| Geographic | Location-based |
#Database Selection
| Use Case | Database Type |
|---|---|
| Transactions | PostgreSQL, MySQL |
| Documents | MongoDB |
| Key-Value | Redis, DynamoDB |
| Time Series | InfluxDB, TimescaleDB |
| Graph | Neo4j |
[!TIP] Pro Tip: Choose databases based on access patterns, not popularity!