KV vs DO
I've been building workers and leveraging KVs to create dynamic content. However, I've come to the realization that how I'm using one of my KVs is super susceptible to race condition issues, so I started looking at DOs.
My question is, are there any "gotchas" I should be concerned with when using DOs? Any "it costs more because it uses more ___" or alike? Would using both essentially "double" in transaction availability (not literally but assuming it were balanced) since they each have their own pool?
It doesn't seem like too much to transition parts from KV to DO, but I also know I'd be flying blind with DOs without a helper script to query/output, so I'm also curious how y'all handle that.
8 Replies
Assuming you are just using as a dumb KV store, you shouldn't need to worry much about Wall Clock billing, though it is a factor in pricing.
Also, note request throughput is not as high, since each DO is single-threaded. You can mitigate this a bit by using multiple DOs, but each DO can only handle ~1k rps(depending on amount of load)
it'll be a small load. it's only calculating votes from top.gg API as well as a cron that checks them every 5 mins.
so when a user votes, it updates the timestamp and adds to their counter. KV can probably handle it as-is for a while, but I also don't want to have to deal with moving the data lol
I guess the real issue would be vote webhook and cron triggering at the same time and one of them not updating as a result
You could probably move the cron into the DO too, if that makes a difference
oh wait I think I misunderstood. I thought DOs were a different storage container of sorts. I didn't realize it's just an engine that sits between workers and the KV or SQLite. I guess my mention of "increased transaction availability" was way off then lol
A DO is basically a unique Worker instance, accessible via ID, that has attached SQLite/KV storage
Gotcha. So my worker currently takes webhook requests for every time someone clicks "Vote" on the bot listing (can only vote once every 12H). The cron runs every 5 mintes to see if the 12H has lapsed for anyone, then perform actions. It also resets vote streaks if they don't vote within an alloted timeframe (say 24H).
The nice thing about DOs here is that you can schedule separate crons for each user, instead of needing to iterate through all users in a cron handler
And you can even just not schedule an event if it isn't needed, so if the user hasn't done anything in the last 24 hours, there isn't a reason to fire an alarm at all
that's what I wanted to do, scheduled jobs. Cron seemed overkill but my only option (hadn't researched enough)