What's the latency for KV and D1?
I'm debating on just using D1 with a table of key-value pairs, but I was told the latency for KV is significantly less than D1 for repeat lookups.
I'm wanting to do a lookup as a part of every request, so the answer is important here, but I haven't been able to find any data.
How long does it take to load a value from KV? And how long does it take to load a value from a D1 table?
6 Replies
I'd recommend looking at https://developers.cloudflare.com/workers/platform/storage-options/ rather than having performance as the only factor, they're pretty different solutions.
KV is eventually consistent, with two central stores, and caches at the edge on read.
D1 is built on Durable Objects so it has 1 central store, with no read replicas/caching (currently).
I know the other differences, and none are particularly relevant to my use case. The biggest factor right now is cost, and D1 is a fraction of the cost of KV. Since I can't find a metric on latency, it really does boil down to how much am I paying for how much improved latency.
At edge sounds like KV would be fastest, but I'd really like to know the SLAs or data for the latencies. 🤔
I don't think any of them have any SLAs for latencies.
It all depends where you're running your Worker, and where your DO/D1/R2 instance is.
DO/D1/R2 instance in APAC accessed from APAC is faster than KV cold reads, since KV doesn't have a central store in APAC.
Caching is something you can do yourself with all of them using the Cache API
Is there documentation for where the 'central stores' are for each API?
Nope, just regions
KV has one in EU and one in NA
Regions is what I mean. Are they documented anywhere?
I think I'd love to geolocate the API so that users get KV or D1 depending on which has the fastest response times for the region. Sounds fun tbh.
I guess more specifically, I think I'll use KV unless D1 has a service in that region, but idk where the services are located.