vtsflyV
Denoβ€’2y agoβ€’
1 reply
vtsfly

Using Deno.KV outside deno deploy environment, limit problem

Using Deno.KV with kubernetes(k8s) outside deno deploy environment is giving me rateLimit, too many requests error after only 200-300 requests in 2-3 hours. When l was using deno deploy it never happened.

l am using Server Sent Events, together with kv.watch to detect changes and update the other clients. Its a real time application. Here is how l am using kv with SSE:

export const handler: Handlers = {
  async GET(_req) {
    const kv = await Deno.openKv(`https://api.deno.com/databases/${DATABASE_ID}/connect`);

    return new Response(
      new ReadableStream({
        async start(controller) {
          for await (
            const [{ value: message }] of kv.watch([["maps", "couve", "teste", "1"]])
          ) {
            controller.enqueue({
              data: message,
              id: Date.now(),
              event: "message",
            });
          }
        },
        cancel() {
          console.log("cancel");
        },
      }).pipeThrough(new ServerSentEventStream()),
      {
        headers: {
          "Content-Type": "text/event-stream",
        },
      },
    );
  },
};


l checked Deno.kv limits and they are well above my usage. After 1-2 days with the error, kv comes back working again. l dont understand why is this happening if the read and write monthly limits are not being reached.
image.png
Was this page helpful?