1---
2name: storage
3description: Choose and architect storage systems for applications with the right tradeoffs.
4metadata:
5 source: https://skillmd.com/skills/modbender/storage
6 clawdbot:
7 emoji: 💾
8 os:
9 - linux
10 - darwin
11 - win32
12---
13
14## Object vs Block vs File
15
16- Object storage (S3, R2, GCS) for immutable blobs: images, videos, backups, logs — cheap, scales infinitely, but no partial updates
17- Block storage (EBS, Persistent Disks) for databases and apps needing filesystem semantics — faster, but tied to single instance
18- Network file systems (NFS, EFS) when multiple instances need shared filesystem access — convenient but latency and cost add up
19- Default to object storage for user uploads — block storage for database files only
20
21## When SQL vs NoSQL
22
23- SQL when you need joins, transactions, or complex queries — fighting against NoSQL for relational data wastes months
24- Document stores (MongoDB, Firestore) for nested/variable schemas where you always fetch the whole document
25- Key-value (Redis, DynamoDB) for simple lookups by ID at massive scale — not for complex queries
26- Time-series databases (InfluxDB, TimescaleDB) for metrics with timestamp-based queries — regular SQL struggles with retention policies
27- Start with PostgreSQL unless you have a specific reason not to — it handles JSON, full-text search, and scales further than most assume
28
29## Local vs Cloud Storage
30
31- Local disk for ephemeral data: temp files, build artifacts, caches — assume it disappears on restart
32- Cloud storage for anything that must survive instance termination — never store user data only on local disk
33- Local SSD for databases in production — network-attached storage adds latency to every query
34- Hybrid: local cache in front of cloud storage for frequently accessed files
35
36## CDN Patterns
37
38- Put CDN in front of static assets always — origin requests are slower and more expensive
39- Set long cache TTLs with versioned URLs (`style.abc123.css`) — cache invalidation is slow and unreliable
40- CDN for dynamic content only if latency matters more than freshness — adds complexity for marginal gains
41- Edge caching for API responses works but cache keys get tricky — start simple, add only when needed
42
43## Upload Handling
44
45- Never accept uploads directly to app server disk in production — use presigned URLs to cloud storage
46- Set file size limits at load balancer level, not just application — prevents memory exhaustion attacks
47- Generate unique keys for uploads (UUIDs) — user-provided filenames cause collisions and path traversal risks
48- Validate file types by content (magic bytes), not extension — extensions are trivially spoofed
49
50## Data Locality
51
52- Keep compute and storage in same region — cross-region data transfer adds latency and cost
53- Replicate data to regions where users are, not where developers are
54- Multi-region storage adds complexity — single region with backups elsewhere usually sufficient
55- Database read replicas in user regions for read-heavy workloads
56
57## Retention and Lifecycle
58
59- Define retention policy before storing data — "keep everything" becomes expensive and legally risky
60- Automate deletion of temporary data — manual cleanup never happens consistently
61- Tiered storage for aging data: hot → warm → cold → archive — but check retrieval costs before archiving
62- Separate storage for logs vs business data — different retention, different compliance requirements
63
64## Cost Traps
65
66- Egress fees dominate cloud storage costs — calculate before choosing provider
67- Many small files cost more than few large files — batch small writes when possible
68- Minimum storage duration on cold tiers — early deletion still charges full period
69- API request costs matter at scale — millions of LIST operations add up
70
71## Backup Strategy
72
73- 3-2-1 rule: 3 copies, 2 different media types, 1 offsite — cloud counts as one location
74- Test restores regularly — untested backups are not backups
75- Point-in-time recovery for databases — daily snapshots lose a day of data
76- Version important files — deletion or corruption often discovered late