
Handling 350k Requests for $3 using Lambda - karakanb
https://levelup.gitconnected.com/handling-350k-requests-for-3-using-lambda-c258ace3da58
======
merty
This isn’t actually one of those solutions where Lambda shines, pricing wise.

I would simply trigger a Lambda function once a minute (or every X minutes)
using CloudWatch to fetch the latest articles and save them to an S3 bucket
which I would expose and cache using CloudFront or any other CDN service.

This would lead to:

\- No Lambda costs as it would be covered by the monthly free tier of 1M
requests.

\- No storage costs as the size of the stored data would be extremely small.

\- Really fast responses as the “response” would actually be a static file
cached at the CDN.

\- The only parameter defining your cost would be your CDN of choice, which
would cost somewhere between free and as low as $10/TB. For a project like the
one in the article, that’s hundreds of millions of requests for just $10.

~~~
rumanator
> No Lambda costs as it would be covered by the monthly free tier of 1M
> requests.

That's far from the full picture. AWS Lambdas are charged by units of
computational resources that are expressed as multiples of 64MB of RAM used
per 100ms, each rounded up to the next value and with a minimum charge of
128MB of RAM used. So you are only charged a fixed fee per request if all your
requests are short-lived and barely use any computational resources. Long-
lived processing tasks that require a bit of RAM are charged multiple times
the value of a single request.

~~~
merty
You’re right, I should have mentioned that as well.

I didn’t go into those details because I was strictly talking about the
project in the article and the compute time limit would not be exceeded for
this project either.

400,000 GB-s is free every month, and even if the Lambda function ran for
2,592,000 seconds (equals to a month, way more than enough) using 128 MB of
RAM (again, more than enough for a task like this), it would only use 324,000
GB-seconds.

------
vander_elst
It's like 0.13qps on average. Assuming a constant load and no spikes, a
raspberry pi should also be able to handle this load, it would be nice to
compare the performance

~~~
rubyn00bie
My Raspiberry PI model 3 would do roughly[1] ~250 req/s with an Elixir server
I wrote. 350k @ $3 requests seems kind of expensive to me to be honest.

~~~
Klinky
Is your pi at an AWS data center? How much to co-host it at an AWS-grade data
center?

Sure a self-hosted pi is cheaper, but that's an apples vs oranges comparison.

~~~
rubyn00bie
The question wasn't about a PI in a data center was it? It was about how does
this compare to a raspberry pi.

I'd even question whether or not the application needs to be in an "AWS-grade
datacenter" since it does 1 query every 10 seconds but sure...

I'd be more than willing to bet hertzner's cheapest VPS (~$3.25?) would do
over a million[1] requests per month pretty easily and they're inside a data
center which is a pretty apples to apples comparison.

My point is that the cost per request is high, regardless of data center or
not. That's a lot of money for such a low volume of requests.

[1] Which is still only a request like every 2 seconds.

~~~
heartbeats
I don't understand why you're getting downvoted. If you're serving simple
content, the bottleneck is going to be the network card or disk, every time.
In this case, you have static content: a well-written web server (not nginx,
but mongoose or similar) can easily handle enough requests to saturate a
gigabit uplink on a first gen Raspberry Pi.

Not that it has a gigabit uplink. But handling 100k req/s is trivial for a
well-written server.

------
SahAssar
Seems like a better argument for not using FaaS after reading it all.

It's also filled with "once you've done X Y is simple!" like:

> Once you have the template ready, you can simply deploy your code by
> running: serverless deploy

which is true for all automatable tasks. The same can be said for any VM or
shared hosting.

~~~
unethical_ban
That completely misses the point of FaaS.

Devs don't want to manage VMs. Patching, gold loads, SSH configs, k8s, so on.
You write code, you deploy, and you pay only when the function executes. It
scales as much as you want it to, as much as it needs to, and quicker even
than EC2.

There are very clear benefits to FaaS. It is certainly not for everyone, esp.
if you already have a well functioning deployment pipeline.

~~~
brintnc
> Devs don't want to manage VMs. Patching, gold loads, SSH configs, k8s, so on

Which devs?

I'm a developer and I enjoy most of these things. Working with k8s is a
pleasure, managing VMs can be quite simple (and more often than not, is). I
don't do much patching, but I "SSH" into our k8s pods quite frequently. I've
never thought, gee I wish I had a lambda to simplify this. I know I _also_
don't represent all devs, but I'm never seen this comment made outside of it
being an argument supporting FAAS.

~~~
erikerikson
K8s can be great but at a largish retailer (billions in yearly revenue) it
took a team of engineers on the better end of the company's talent pool to
manage the clusters. Those salaries can buy a lot of serverless service usage
and according to uptime metrics better reliability. On top of it the teams
adopting serverless generally had higher velocity. At scale there were a few
use cases that needed to economize but... Largely not.

------
fabioyy
3$ for 350k request is VERY expensive

~~~
blantonl
Couple points here in this specific case

1) Lambda costs were shown as actually 50 cents for all this. 2) API Gateway
was the balance of the cost, and actually isn't needed in this customer's use
case. Lambdas can be placed behind application load balancers which are
significantly less expensive.

Author also mentions other downsides such as "vendor lock-in," however his
lambdas were written in NodeJs and it would be trivial to move his code to
some other NodeJs delivery mechanism such as Fargate or ECS cluster.

The benefit here is his deployment with the ServerLess framework got him his
MVP very quickly on a very scalable environment with minimal management.

~~~
shaneprrlt
API Gateway is the definite gotcha with serverless architectures. Whenever
someone tells me how cheaper serverless is, I figure they haven't actually
dived in to see how many AWS resources besides Lambda are required for a
production deployment.

It is convenient in several use cases, but for an endpoint or even an entire
API that is going to receive a lot of load, managing servers is the more
economical approach.

If you need to get a one-off endpoint built that won't receive any significant
amount of load, I think a serverless solution is great. But I wouldn't use it
as my primary API architecture. Like most things in tech, there's no silver
bullet. Context matters, and the best approach depends on many factors.

I still recall this article by the creator of ipify on how he's able to
receive upwards of 30 billion requests per month on Heroku for a fraction of
the cost of API gateway: [https://blog.heroku.com/scaling-ipify-to-30-billion-
and-beyo...](https://blog.heroku.com/scaling-ipify-to-30-billion-and-beyond)

~~~
blantonl
I run 8 different production API endpoints, all on Lambda, directly through
Application Load Balancer instead of API Gateway, and they served 510 million
requests last month for about $200.

Those API endpoints took me about a day to deploy using serverless deployment
tools. They economically scale between extremely varied workload requirements.
There are no complaints on my end.

~~~
rumanator
> and they served 510 million requests last month for about $200.

In EC2, which is not cheap at all, that's between the monthly cost of one
m2.2xlarge and m3.2xlarge instance, or two m2.xlarge instances, or 3 t3.large,
or 7 t3.medium.

In other words, you can operae a small cluster on AWS for that price tag.

------
ulucs
Based on my experience here, figuring out how to run your service very cheaply
is quite simple:

1\. Set up a somewhat convoluted, definitely not efficient, but kind-of cheap
setup

2\. Write a blog post bragging about it

3\. Submit on HN

4\. Take notes as HN users inevitably tell you how to run your setup for much
cheaper, while even providing double-checked rate estimates (you wouldn't want
someone commenting that your estimates were wrong, would you?)

~~~
rahimnathwani
It's just a specific implementation of
[https://meta.m.wikimedia.org/wiki/Cunningham%27s_Law](https://meta.m.wikimedia.org/wiki/Cunningham%27s_Law)

------
whalesalad
(This comment is unrelated to the use of lambda, and more of a note to the
author)

The author comments that they prefer the light mode to their own dark mode. I
think that the dark mode would benefit greatly from being designed (color
wise) bottom-up as a dark mode, versus just trying to toggle certain things to
be darker.

The big tell is that the lines separating each row of content appear to be the
same color in both areas. This tells me that the color of the line is not
determined based on the color behind it (either via transparency, via color
manipulation manually, or via dynamic color manipulation from a tool like sass
(ie, opacity(), darken(), etc...)

I do agree w/ the author that light mode looks better. I also tend to prefer
dark mode UIs. I think that by mindfully revisiting color a lot of the visual
noise will go away and result in a more pleasant experience.

tl;dr dark mode is not just inverting certain light colors to dark, it should
be done with more care.

------
shoo
I have a silent low-power ex-thin-client box sitting in my living room that is
used to perform batch jobs. It's been running for about 2.5 years, cost about
$26 to buy the hardware second hand, and maybe costs around $20 / yr in
electricity. Internet is $0 as I'd pay for that anyway and it doesn't need
much bandwidth. It executes about 85,000 batch jobs every fortnight, so call
that about 5.5 million jobs total. So that's about 72k jobs to the dollar.
Handwaving 1 request as being comparable work to 1 batch job, the lambda setup
described here is doing about 117k requests to the dollar. I'm massively over-
spending!

The box is currently using about 10% cpu (postgres processes) and has 2 gb of
memory available. I guess I over-provisioned and should go looking for some
customers to onboard onto my "cloud" to get better utilisation and help
amortise my operating costs.

------
chasers
Cloudflare is $0.50 per million.

~~~
ignoramous
$5 minimum though with 128MB RAM and upto 10m reads and 1m writes to their
globally distributed KV store, plus free bandwidth and upto 50ms of CPU time
(not wall-time). Also, something like API Gateway for routing requests isn't
necessary with Cloudflare but options like RateLimiting and Firewall incur
additional charges (which, imo, are quite expensive but might be necessary if
one hits a certain scale, at which point, one might run their own cluster,
instead: It isn't as difficult anymore to setup servers worldwide behind
anycast).

------
sonikudi
IMHO this is poorly researched article. Couple of things mentioned as
disadvantages of serverless are already solved in the market. 1\. You can use
serverless framework or other framework available in market instead of doing
everything in GUI 2\. Its easy in most cases to invoke locally by using
serverless invoke local --function functionName.You don’t have to redeploy.
3\. For monitoring you can create different Dashboards on AWS. Also a great
solution is integration to Datadog or you can create alerts for specific
number of errors or number of invocations and forward it to specific email
address.

------
blacklion
I dream, that, maybe, sites which have something like "news feed" could export
content not only in human-readable HTML/CSS/JS but, maybe, some machine-
readable format too?

And such plugins, software products and extensions, as Devo will consume this
unambiguous and common format, and will not need custom APIs, APIs keys,
backends, HTML scraping & parsing and all custom work for each site they
support, but one common way for all sites?

Is it possible on our technological level, or it is wild dream?

OH, WAIT! RSS!

------
jayd16
If the author is already making an extension, could they have the extension
set the security policy for these sites and simply display them in iframes? No
cost at all.

~~~
wackget
They're not actually displaying the websites; they're pulling the top stories
via each site's API and rendering them locally.

------
kladskull666
I could tell you how I have handled millions of requests on a free AWS tier
ubuntu system, but its not interesting enough. Just like this...

------
moltar
That’s just 8 requests per minute. Can do that easily on a $2.50 vultr VPS.
Beat that :D

~~~
blacklion
What you will do, if you are on vacations (or it is your sleep time, whatever
time you prefer to sleep) and there are 100-fold increase in requests die to
some reasons?

There are three ways:

(1) You use $2.50 VPS (or Raspbery Pi on your home link, it, really, will be
enough for 8 rpm too) and you are Ok that everything collapses and your
product/service will be unavailable for long (by current Internet standards)
time: from several hours to several days.

(2) You use $40-$100 VPS or dedicated server and pay every month for 8 rpm :-)

(3) You sue something serverless and pay much more than $2.50 only for this
surge.

Each way have its own upsides and downsides, and it is impossible to say which
is better based only on «8 rpm» information without whole context.

------
jessmay
Can the extension not make the http requests to get this info? Am I missing
the need for a backend for this type of work?

~~~
jccooper
As mentioned in the article, some of the data sources use API keys which the
author didn't want to make available to end users.

------
7532yahoogmail
Title needs a rate ... 350k requests/month.

Ok: the rest of the article was great. Thanks

------
treyhuffine
Friend link (no paywall):
[https://levelup.gitconnected.com/handling-350k-requests-
for-...](https://levelup.gitconnected.com/handling-350k-requests-for-3-using-
lambda-c258ace3da58?source=friends_link&sk=2e3ce7eeb3e83ccad61b9dc2547aec1e)

~~~
ignoramous
archive:
[https://web.archive.org/web/20200228185628/https://levelup.g...](https://web.archive.org/web/20200228185628/https://levelup.gitconnected.com/handling-350k-requests-
for-3-using-
lambda-c258ace3da58?source=friends_link&sk=2e3ce7eeb3e83ccad61b9dc2547aec1e&&gi=efd7fec1574d)

------
danols
Is there anyone but me who uses the premium article on medium.com as a filter
for what is NOT worth my time?

I believe in the tech space the majority of readers who write in depth worth
to read articles are not incentivised by a few dollars kickback from their
hard work from medium.com. They often write it for personal profile
enhancement or company blog marketing reasons and want to reach maximum
audience and will keep it free for all.

The problem nowadays though is that medium.com is often able to trick them by
making the article premium through deceptive ui even when that is not their
intention. Just look at the googlecloud medium blog and you constantly see
premium articles there which seems bizarre.

~~~
jeremyjh
I use medium.com as a filter in general.

~~~
agumonkey
I use HTTP

------
marknadal
Huh, 350K for $3 is good?

I'm handling Millions for $0 :/ with my
[https://github.com/amark/gun](https://github.com/amark/gun) .

~~~
Dylan16807
Does that mean you don't run any peer servers yourself? Is that recommended?

~~~
marknadal
Not any that I have to pay for yet! :)

