How to serve a billion images a month on a budget

I wrote earlier this year about Lorem Picsum, a site that provides random placeholder images for use in design projects in the spirit of Lorem Ipsum, the classic jumbled-up latin passage used likewise for text. It's taken off. Creator David Marby explains what it's like to serve a billion images a month of a budget.

Processing images is very CPU intensive. As Lorem Picsum runs on a very small budget, to cope with all the requests as the service became more popular, we wanted to avoid doing so as much as possible. This meant adding caching to multiple layers of the architecture. We added two separate layers of caching: A CDN in front, as well as a second cache layer using Varnish Cache. To make the image processing as efficient as possible, we decided to use libvips, as it's very fast and resource-efficient.

As part of making Lorem Picsum as easy to use as possible, we've never required any registration, API keys, or enforced any usage limits. This has generally worked out well, but once in a while a high traffic site deploys production code calling our API, usually accidentally, which leads to [problems]