📮 New blog post:
The Sneaky Costs of Scaling Serverless
https://www.zachleat.com/web/serverless-cost/
Chronicling a migration of the beefy 11ty Screenshots API to a new hosting provider.
Zach Leatherman 6060 replies 5454 likes2727 reposts Original on MastodonOriginal on BlueskyAlso posted to Mastodon.
60 replies
-
-
-
@jamesdoc you’re welcome!
@zachleat this was a very interesting read Zach.
At the company that I work for, we received a surprisingly high bill from Vercel and after looking closely into the usage breakdown we noticed that the number of used cache units is so so so high. Too high to be even possible taking into consideration our revalidation interval and number of pages. Unfortunately Vercel CS is not able to give us a detailed breakdown of where we spent these cache units 🤷♂️
PS. I love the term „convenience tax” !
@pawelgrzybek yeah, more data is needed to justify some of the numbers I was seeing. They didn’t compare with my experience on Netlify or AWS
@zachleat There are so many ways to do things in AWS! If you eventually want a friendlier first-party package/deploy story that isn't the result of clicking around the console, check out SAM. Also not sure how many requests per month are hitting it, but you could eliminate API GW in favor of a Lambda function URL and save those costs. Come on in, the water's fine!
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.html
https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html@james oh fascinating. I’ll definitely have a look at those—I’ve only just started!
https://sst.dev is pretty nice as well.
@jgchristopher @james very nice! I’ve also been pointed at https://www.serverless.com/ and https://arc.codes/ which seem like similar abstractions
@zachleat @jgchristopher Yep, both are solid. I choose SAM because it’s AWS-native CloudFormation without a third party abstraction or licensing/cost considerations. But totally understand that's not a priority for everyone - third party tools definitely do some heavy lifting for you.
@james @zachleat @jgchristopher fwiw Architect is a wrapper for the SAM transform and open governance so no licensing concerns
@brianleroux @zachleat @jgchristopher yeah arc.codes is great! licensing shade was only being thrown on serverless framework 😬
@james @zachleat @jgchristopher rightfully so. ironically but over the years we got a bunch of shade for being in a foundation. At least ppl get why now.
@james @zachleat I'd also recommend SAM CLI for deploying lambda functions. It is relatively easy to use and you can take the reigns in your hand with a Makefile. I'd still recommend API Gateway if you want to implement your own authorization mechanism which you can deploy in another lambda and configure it for your API Gateway resources. Makes it convenient to put OIDC introspection in front of multiple REST endpoints.
@zachleat query - you shared an estimated cost on Vercel, what is the estimated cost of Lambda?
@raymondcamden so far the projected usage is still under the free tier for the month!
@zachleat nice! i dont think you mentioned that, i would. (its also 99% possible you did and i missed it.)
btw, _damn_ good article!
@raymondcamden thank you! I just pushed a small note about the AWS cost
@zachleat @raymondcamden I'm over here with Cloudflare Pages, Digital Ocean for my admin, Supabase, B2, bunny.net, Echofeed, Feedpress, Plausible analytics 🙈
@raymondcamden @zachleat yeah, I quite like their workers stuff and I'm well below the paid threshold for those. I've got one for analytics, contact form, now playing display, schedule rebuilds and music tracking — 100,000 runs a day is super generous for the *tiny* scale I'm dealing with. 😅
@zachleat “ because usage is priced via GB-Hrs, 1 vCPU should use 1 GB of memory. Instead, 1 vCPU is 1.7 GB of memory and 1000 GB-Hrs is actually 588 Hours of usage.”
You know how washing powder people tell you “use one cup” but the cup they provide you has an almost invisible mark halfway up saying “1 cup” and if you fill the cup it’s actually 1⅔ cups? Yeah.
@sil ha! incredible parallel 🏆
@zachleat very nice! Small thing - was playing around and this syntax in your documentation always gives me 404
https://v1.screenshot.11ty.dev/:url/
eg
https://v1.screenshot.11ty.dev/https%3A%2F%2Fgov.uk/
it works if I add the other url params (size)
@zachleat also wondering if you considered Cloudflare, I agree AWS is painful
https://developers.cloudflare.com/browser-rendering/get-started/screenshots/
@joelanman a little bit! I know they have their own fork of puppeteer that might have worked nicely here https://github.com/cloudflare/puppeteer
@joelanman fixed, thanks!
@zachleat if this were Twitter Vercel staff would be all up in replies explaining what happened… but they aren’t, they never left Twitter.
To me the fact they Vercel and all thier staff were able to look past what X has become for the sake of their hype machine is a bad signal
@benschwarz …yeah. It isn’t just Vercel—a lot of the JS-dev ecosystem is that way. Definitely hurt my career when everything split.
@zachleat @benschwarz But we get quality over quantity over here ☺️
@zachleat I can use a boatload more 🤯 emoji if that helps?
@benschwarz the only engagement that performs a meaningful function on mastodon is boost 😅 (favorites are for good feelings only)
@benschwarz this.
@zachleat Serverless functions are essentially the good old PHP CGI model adapted to the cloud and given a hype name.
Just like PHP struggles with idle threads during async I/O, so does serverless functions.
Depending on which serverless function provider one uses it ranges from being autoscaled worker with a strict one payload at a time processing (and no prefetch of next item) to being fresh executions for each and every request.
@zachleat Whenever possible I would opt to run workers myself and work on dialing in how many simultaneous payloads and prefetched ones they should have to maximize throughput, latency and cost
@zachleat I remember reading up on that theory when I worked with RabbitMQ some 5-10 years ago, something like this: https://www.rabbitmq.com/blog/2012/05/11/some-queuing-theory-throughput-latency-and-bandwidth
Also get reminded of good old https://gearman.org/ which we eg used with our PHP setup on Flattr back in the days and could handle extreme spikes in activity without any spikes in cost – only spikes in queue lengths
@voxpelli @zachleat yes and you get guaranteed resources per request, and price per request, and incredible scaling capabilities. It’s absolutely not appropriate for every workload, but can adapt quickly and be very cheap. And despite some companies best efforts to downplay it, it’s often pretty trivial to move to a server execution model when it makes sense.
@voxpelli @zachleat I used to work in publishing and we would occasionally get viral successes. While the primary content is incredibly cachable. There was quite a lot of features that weren’t. Lambda helped us slice our server costs 90%. While the operational cost was higher during peaks. We only paid for it during peaks. And had very simple ops model.
@zachleat You can skip api gateway cost and save with lambda function URLs
(and to prevent "denial of wallet" attack, possibly set concurrency limit)
Other than that I've written few optimization tips:
https://codepasta.com/2024/04/19/optimizing-puppeteer-pdf-generation
BTW GCP cloud run makes this so much more easier with a simple Dockerfile
> Mind-boggling that the same service would use ~1276 GB-Hrs per month on Vercel and ~101 GB-Hrs on AWS. Mind-boggling that the same service would use ~1276 GB-Hrs per month on Vercel and ~101 GB-Hrs on AWS.
This is with all the caching in place, not the same workload hitting lambda, right?
In either case yes mind boggling, and I used to run the team that owned that.
@reconbot yeah, with caching—71% cache misses on the Vercel side. ~85% cache *hits* from CloudFront.
Found some stats:
28.8% cache hits on Vercel 😬
81.2% cache hits on CloudFront@zachleat money printer go brrr
@zachleat all CDNs are not created equal when it comes to cache eviction.
Yet another thing often selected because of some flashy feature or promise that has knock-on significant impact on origin load and financial implications 🙄
Remember folks: the difference between 95% and 90% cache hit ratio is a doubling of origin traffic!
@ryantownsend what‘s the difference between 90% and 28% 😬
@zachleat bankruptcy.
-
-
@zachleat Thanks! This is awesome! Keep it up!
Update after one billable month: the 11ty Screenshots service cost $1.95 on AWS 🏆
1.16M screenshots served 👀
86.2% cache hits@zachleat With this edit, you answered my question.