| Users / Operations | 100 | 10,000 | 1,000,000 | 100,000,000 |
|---|---|---|---|---|
| Number of saved states (mementos) | ~100-1,000 | ~10,000-100,000 | ~1M-10M | ~100M+ |
| Memory/storage usage | Low (MBs) | Moderate (GBs) | High (TBs) | Very High (PBs) |
| Access latency for restore | Instant | Milliseconds | Seconds | Minutes or more |
| System complexity | Simple | Moderate (needs indexing) | High (sharding, archiving) | Very High (distributed storage) |
| Backup and archival needs | Minimal | Required | Critical | Essential with tiered storage |
Memento pattern in LLD - Scalability & System Analysis
The first bottleneck is the storage and memory required to keep all mementos. Each saved state can be large, and as users or operations grow, storing all snapshots becomes expensive and slow. This affects both the system's memory and disk usage, and slows down retrieval times.
- Compression: Compress mementos to reduce storage size.
- Incremental snapshots: Save only changes (deltas) instead of full states.
- Archival storage: Move old mementos to slower, cheaper storage.
- Sharding: Distribute mementos across multiple storage nodes.
- Cache recent states: Keep only recent mementos in fast memory for quick access.
- Limit history depth: Restrict how many states are saved per user or object.
Assuming each memento is ~100 KB:
- At 10,000 mementos: ~1 GB storage needed.
- At 1,000,000 mementos: ~1000 GB (1 TB) storage needed.
- At 100,000,000 mementos: ~10 TB storage needed.
Requests per second depend on how often users save or restore states. For 1,000 concurrent users saving every 10 seconds, ~100 QPS write load.
Bandwidth depends on memento size and frequency. For 100 QPS at 100 KB each, ~10 MB/s bandwidth needed.
Start by explaining what the Memento pattern does: saving and restoring object states. Then discuss how storing many states can grow storage and memory needs. Identify storage as the first bottleneck. Suggest practical solutions like compression, incremental snapshots, and archival. Finally, mention trade-offs like limiting history depth to balance performance and resource use.
Your database handles 1000 QPS for saving mementos. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Implement caching and compression to reduce load, then add horizontal scaling with sharded storage to distribute the increased write traffic.
