r2 bill hit $214 from class a operations because i list the bucket per request Bill Breakdown
R2 was supposed to be the cheap part. 90GB stored, zero egress charges, I was budgeting maybe $2 a month for it.
Invoice came in at $214 and almost all of it is Class A operations. Working backwards from the per-million price that is roughly 47 million operations in a month.
Found it: my gallery page calls ListObjectsV2 on the bucket prefix to build the file list, on every single page view. About 1.6M page views a month, and the listing is paginated so heavy folders are several calls each. So every visitor is doing bucket listings that could have been one database query.
So it is my fault and I know the fix in the abstract - do not use object storage as a database - but I would like to hear how people actually structure this, because "the bucket is the source of truth" felt clean and now it costs more than my server.
@kraut_corner · last wk. · 2 replies
Short-term tourniquet before you rewrite anything: cache the listing.
Sixty seconds of staleness on a gallery is nothing and it removes about 99% of the operations immediately. You can then do the database version properly instead of at 2am.
Be aware the edge cache is per-location, so a 60s TTL across many colos is not one call a minute globally, it is one call a minute per colo that gets traffic. Still a ~99% cut, just not 100%.
Reply
Report
@dartfit_dana · last wk.
Worth stating explicitly for anyone skimming: this is a patch, not the fix. Caching a bad access pattern makes the bill survivable and leaves the design in place. Do the tourniquet today and the DB index this week, not this quarter.
Reply
Report