Sitemogging: A Hacker News Front Page Project Built on Cloudflare
主持人:Jilles Soeters
原定直播时间 10月1日,13:00 - GMT-4 13:30
English
转录文本 (测试版)
Last Friday I shared SiteMogging.com on Hacker News and within no time it had the number three spot on the front page and it stayed there for a while.
So the last few days I was pretty nervous.
I thought I was going to be cooked financially, ruined, bankrupt.
Front page on the Hacker News, hug of death. Turned out that wasn't the case.
Actually it was pretty cheap. Now what is SiteMogging.com? It's a website where two sites compete with each other for aesthetics judged by Workers.ai, the Jemma 4b model.
Let me actually tell you how much it cost me. We'll start with Workers.
Here are the requests for the past few days and as you can see there's 181k requests and almost 300k sub requests with zero errors.
Here's the peak 83k around this time.
This total amount of requests cost me zero dollars. Zero. I am on the workers' pay plan so I do pay five dollars a month but all this would also fit in the free plan just FYI.
Next was Workers.ai. Workers.ai is what I use for judging two websites.
We had nearly 8,000 calls to this LLM. Let me just show you the cost.
93 cents. That's crazy right? 7 .5 million tokens but what is also really cool is I could just see the logs and I can see the results.
How much each invocation cost me, how really cool stuff.
AI gateway, freaking powerful. Total right now is 93 cents.
Pretty good. Next when we take screenshots we have to store those screenshots somewhere so I'm storing those in R2 and R2 gives us 10 gigabytes free out of the box and unlimited egress.
Unlimited egress. Okay zero dollars for egress.
Let's look at the R2 bucket. 1.3 gigabytes. Well within the free plan so this cost me zero dollars.
Now you might be wondering how do we even get those screenshots?
We get those with browser runs. Spins up a browser on our edge network and then takes a screenshot which we then store in R2.
Now how much did this cost me?
Let's let's have a look. We had a total 5,300 sessions and 28 browser hours. We charge per browser hour nine cents.
You get 10 for free so those are prorated. The total I paid for browser rendering was one dollar and 61 cents.
Crazy. Okay next where do we store the results of this mogging competition?
You guessed it. We store those in D1 and D1 is our serverless SQLite database which you get five gigabytes for free.
Let's go to D1. 274 million rows read and only six megabytes of storage used so we are still well within the free plan.
This cost me zero dollars.
Next whenever you start a new mogging competition this gets put on a queue.
I did a video on queues you can find it on my profile. Anyway I use queues because a screenshot could fail or AI could fail and then we can just retry it.
However I probably should have used workflows.
That was my bad. I'm not perfect.
I made a mistake. I used queues. I should have used workflows but you're going to do 12k billable operations still well within the free range so again zero dollars.
Next is durable objects. Durable objects. I use this as a state coordinator for jobs.
When you kick off a mogging job there's a durable object that coordinates the state.
Probably could have done this with workflows and not use durable objects but I was having fun.
I used 13,000 gigabyte seconds well within the free tier.
This also zero dollars. Okay next there's some bot protection that you can see here.
You can't just spam sidemogging .com with a bunch of requests because of turnstile.
Now how much did that cost me? Zero dollars. Turnstile is free. It's awesome.
I almost add it to every website and finally turnstile prevents bots but what about humans that just want to spam me?
Well there we got rate limiting. Rate limiting.
Underrated feature by the way. Let me show you. Look how easy is that. You add a rate limiter.
Give it a namespace. You say what's the limit and what's the period and then you just give it a key and that's it.
So the key is the user's IP in this case.
Free. Again free. The total that we ended up with $1.61 for browser run.
93 cents for worker's AI. That totals $2.54.
It's crazy. Just wanted to share this with you because you sometimes hear Hacker News hug of death or the Reddit hug of death.
That's just not an issue. Everything kept working.
Thousands of people on the website. We had over 8,000 people submit websites and that's how much sidemogging.com cost me.
I'm very happy with it.
Just wanted to do this quick video. Hope was useful. See you later.
