Working on social media previews today. Currently when twitter/telegram/mastodon/etc request the little page preview I spin up a headless chome browser and screenshot the page - all inline and on demand. This has problems:
I do this on the web servers
headless chrome is not a lightweight process
these requests can come in large batches in a short time frame
For awhile, this was DOSing SN until I put a rate limiter on it. That's not ideal though because:
in some cases it prevents the image preview from showing up if the requesting service doesn't intelligently retry
it's still a strain on the web servers
Instead what I want to do is transactionally queue a job to screenshot the page every time a post/page is updated, store the image in block storage (e.g. S3), and serve that. One problem with this is determining when to screenshot non-post pages like the homepage, recent, user profiles, top, etc. I guess I can daily screenshot those pages but it's relatively inelegant.
btw, I am doing the exact same thing on bitcoininflationindex.com. I use netlify for my frontend and use their "On-demand builders" to generate images which are cached on the edge.