choosing between DO and KV
Hi friends, I am going to have a service with few writes but large amounts of reads (billions per month). I need low latency but also the price to not explode. I am not sure what to pick because of the pricing of the two services. KV is $.50 per million while DO is $.15 but charges duration too. I would just be reading a JSON value.
Thoughts I've had:
1. I could just use raw KV, with the worker charge it would be $1 per million
2. I could read from a durable object then store the data locally using the cache API
3. I could read from KV then store using the cache API to avoid the KV price
What would you pick? Thank you!
8 Replies
I created this code... I am trying to do the same... Cache, and then DO primary but fallback to KV if DO has to many requests...
I asked in the #durable-objects chat if this is a good idea 🙂
to be honost... I generated the code using gpt-4 lol. But could have created it myself
So with one DO (costing 4.5 excluding reads and writes), it should be able to handle 259.200.000 requests a month (based on 100 requests a second). So sharding it with like 8ish should give you enough to scale it and keep the costs down?
I saw that $4.50 thing someone said, where does that come from? I thought the DO just charges while processing a request
If you have a DO active for the entire month (for instance, if you have a websocket connected to it. It doesn't stay active if you just send a request once in a while), the total charge comes out to about $4.50 for the duration. For it to stay active that long you will also need to send some amount of requests, but those are really dependant on the application.
@zegevlier what of the 3 options would you do in my situation? 🙂
DO charges 0.15/million for the request + 0.20/million "read units" which are 4kb chunks. If whatever you're reading is larger than 4kb, you'll be cheaper off with "raw" KV. Additionally, DOs are single-threaded and in only one location, but I think you already realised that. If you're dealing with billions of reads per month, number 3 will absolutely be your best bet currently. You will have to set the cache time to something reasonable if you want updates to appear quickly though.
Also worth noting that one of the people on the KV team said recently that they're not a fan on the "cache in front of KV" method. From what I gathered this was mostly because it's unnecessarily hard to manage. They said they were looking at potentially changing KVs pricing model to reduce the need for this in the future.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yea that's what I meant 😄, sorry for the confusion