Giới Thiệu
Khoảng 2 tuần trước chúng tôi so sánh performance và cost của Cloudflare KV và Upstash Redis. Lần này xem Deno KV — key-value store native Deno chạy trên global edge network của Deno.
Deno KV tương tự kiến trúc Upstash Redis: cả hai có primary region nơi all writes gửi đến rồi replicate đến các region khác. Reads served từ region gần client nhất. Nhiều khác biệt features vì Redis có nhiều features KV không có, nhưng tập trung vào simple reads/writes.
Hai benchmark khác nhau, đều dùng Deno Deploy chạy code. Cả hai trường hợp KV store và Redis đều bật all available read regions.
- Invoke từ 20 regions quanh thế giới dùng planetfall.io.
- Invoke từ single region với load cao hơn nhiều.
Sau đó so sánh kết quả, bàn trade-offs và pricing.
Benchmark Setup
- 1000 keys
- 4 KB - 64 KB data size (random)
- 60s TTL all keys
- 20 regions invoke function
- ~10 requests/giây
Chọn keyspace nhỏ để đảm bảo cache hits mà không cần crank RPS quá cao.
Code
Function đơn giản: read từ Redis, read từ KV, return latencies để evaluate.
// main.ts
app.get("/test", async (c) => {
const key = Math.floor(Math.random() * 1_000).toString()
const minValueSize = 4 * 1024
const maxValueSize = 64 * 1024
const data = randomBytes(minValueSize, maxValueSize)
const ttlSeconds = 60
const beforeRedis = performance.now()
const redisResponse = await fetch(Deno.env.get("UPSTASH_REDIS_REST_URL")!, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${Deno.env.get("UPSTASH_REDIS_REST_TOKEN")}`,
},
body: JSON.stringify(["GET", key])
})
const redisLatency = performance.now() - beforeRedis
if (!redisResponse) {
await fetch(Deno.env.get("UPSTASH_REDIS_REST_URL")!, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${Deno.env.get("UPSTASH_REDIS_REST_TOKEN")}`,
},
body: JSON.stringify(["SET", key, data, "EX", ttlSeconds])
})
}
const kv = await Deno.openKv()
const beforeKV = performance.now()
const kvResponse = await kv.get([key])
const kvLatency = performance.now() - beforeKV
if (!kvResponse.value) {
const setRes = await kv.set([key], data, { expireIn: ttlSeconds })
console.log({ setRes })
}
return c.json({ redisLatency, kvLatency })
})
Kết Quả - Global Latency
Sau 30 phút, kết quả. Latency đo từ function trên Deno Deploy đến store, không bao gồm network roundtrips invoke function.

Click image for full size
| Deno KV | Upstash Redis | |
|---|---|---|
| P90 | 265ms | 76ms |
| P99 | 494ms | 94ms |
Deno KV chậm đáng kể khi read data. Suy nghĩ đầu: có thể họ chưa đủ read regions phân phối toàn cầu. Thời điểm benchmark, họ có gpc-us-east4, gpc-asia-southeast1, gcp-europe-west3, gcp-southamerica-east1, gcp-us-west2.
Có thể significant số request phải cross multiple regions fetch data → high latency, loại bỏ advantage Deno control cả compute và storage trong cùng cloud/datacenter. Upstash chạy trên AWS, all requests Deno→Redis cross cloud provider borders.
Single Region
Test theory: benchmark thứ 2 invoke từ single location (home) qua Frankfurt. Cả Deno KV và Upstash Redis đều có read replica tại gcp-europe-west3 và eu-central-1 (GCP và AWS).

Click image for full size
Cả hai fast hơn scenario này, nhưng Deno KV vẫn chậm hơn Upstash Redis. Latencies single region, delta so với global latency trong ngoặc:
| Deno KV | Upstash Redis | |
|---|---|---|
| P90 | 132ms (-133) | 16ms (-60) |
| P99 | 154ms (-340) | 26ms (-68) |
154ms tốt hơn 494ms, nhưng giả định all traffic từ single region — ngược với ý tưởng global edge network. Nếu chạy global API, traffic từ khắp nơi, mọi request cần data KV sẽ bị chậm bởi điều này.
Pricing (Giá Cả)
Cả Deno và Upstash bill chủ yếu theo usage. Cả hai có good free tiers để try không pay.
| Deno KV | Upstash Redis | |
|---|---|---|
| Flat Cost | $20/tháng (thêm read regions) | FREE |
| Storage | $0.50 / GB | $0.25 / GB |
| Reads | $1 / Million / 4kb | $2 / Million (bất kể size) |
| Writes | $2.50 / Million / 1kb | $2 / Million (bất kể size) |
| Bandwidth | $0.50 / GB | $0.03 / GB |
Khác biệt chính: pricing Deno không transparent như mong đợi — cần biết request size để tính cost. Upstash không vấn đề này: all requests billed same. Mặc định Upstash read/write up to 1MB/request, cho tăng limit với flat fee.
Bottom line: nếu read > 8kb/request, Upstash likely cheaper.
Kết Luận
Dùng Deno KV khá tốt vì same platform; không manage separate account, không extra setup. Tuy nhiên performance và cost nowhere near Upstash. Cũng limited trong khả năng. Set/get là common operations nhưng không phải tất cả Redis. Xem examples để tìm ideas/use-cases Redis.
Ghé Discord hoặc X để hỏi/đề xuất.