> Part of it was the CPU load on the database rendering dozens of 404s per second (which still required a database call)

That's one request every 80 ms which is an eternity in CPU time. How the hell can you not afford to check that something doesn't exist every 80 ms.

> part of it was that the thumbnail images were being queried over and over again with seemingly different parameters for no reason.

Is there a reason you are serving thumbnails for arbitrary parameters?