Should I store generated images or regenerate them on demand?

Storage costs pile up
Cheap API calls might not justify storage. A 2MB image costs pennies to generate but months of storage could exceed generation costs. CDN delivery costs more. This works against storing everything indefinitely.
Regeneration wastes time
User-facing requests need fast delivery. Regenerating on every view adds latency. If the same user requests the same image twice, regeneration is slower than serving cached.
The middle ground
Store images with high reuse probability—user avatars, profile pictures, saved designs. Regenerate low-reuse images—one-off sample outputs, API test runs, draft previews. Set storage expiration: keep generated content 30 days, then delete unless explicitly saved by a user.
Query patterns matter
If you generate 1,000 unique images monthly with no repeats, storage wastes money. If you generate 100 images and serve them 10,000 times, storage saves money. Analyze your actual request patterns before deciding.