back
165 comments
I dug into the internals of the local, SQLite version of this just now and wrote up some notes here: https://til.simonwillison.net/deno/deno-kv#user-content-deno...

The most interesting detail is probably the schema they're using for that:

    CREATE TABLE queue (
      ts integer not null,
      id text not null,
      data blob not null,
      backoff_schedule text not null,
      keys_if_undelivered blob not null,
      primary key (ts, id)
    );
    CREATE TABLE queue_running(
      deadline integer not null,
      id text not null,
      data blob not null,
      backoff_schedule text not null,
      keys_if_undelivered blob not null,
      primary key (deadline, id)
    );
    CREATE INDEX kv_expiration_ms_idx on kv (expiration_ms);
Is it not normally bad practice to have 2 tables with basically identical fields and move rows between them?

Isn't that exactly what indexes were designed for?

> I find this particularly interesting in terms of open source business models: they're baking a core feature into their framework which their SaaS platform is uniquely positioned to offer as a global-scale upgrade.

That’s quite novel, but I also find it a bit unnerving. They gotta commercialize of course, but they didn’t have to go fully closed. They could’ve just used a different license (BSL, PolyForm..) for the scaling layer.

I think what Deno is aiming for here is actually very forward thinking.

I'm using Go for the first time this year and some aspects of the language are very C like. Of the list of things that isn't C like (e.g. GC allowing one to return what look like stack allocated pointers from functions) there is the obvious inclusion of things like `map[string]string`. I bring this up because it struck me that inventing a language in 2023+, it would seem almost insane not to have built in syntax for the language to handle map types.

And so it seems logical that a web-server focused eco-system would start to garner libraries and even language syntax (maybe one day) for the kind of primitives we frequently use on web-servers. I mean, I can't even recall the last time I worked on a distributed web server that didn't have a KV store as a cache, or a locking mechanism, or even an ad-hoc queue. A distributed system without a KV store feels vaguely isomorphic to a computer language without a map type. It is such a Swiss army knife kind of technology.

One potential issue is that Deno is going alone down this path. Currently, I don't feel confident that the new features they are adding will be available on competing platforms. Even if they open source the API (it is on a `Deno` namespace), I'm not sure it will just work on AWS if I wanted to switch out FoundationDB for e.g. Redis.

For that reason, I feel I want to avoid Deno. Even if the syntax and exposed features are really attractive, I'm worried about becoming locked in and then having to do a lot of surgery to code to make it deployable on multiple cloud infrastructures. That is a requirement from a lot of clients. E.g. maybe I want to sell to Oracle or Salesforce one day but they mandate I have to run my systems on-prem. I'm now on the hook trying to figure out how to adapt whatever available KV store they have to the features I'm using from the `Deno` package.

It is a double edged sword. Maybe they will succeed in pushing forward this vision to a broader audience. For now I'll probably remain cautious.

In this case, they've also documented the remote connection protocol: "KV Connect" https://github.com/denoland/deno/tree/main/ext/kv#kv-connect

I kicked the tires on this with a pure TS implementation of the protocol called kv-connect-kit that gives you the KV client api in any Javascript runtime (including Cloudflare workers, which does not have anything Deno namespace related)

- github: https://github.com/skymethod/kv-connect-kit

- npm: https://www.npmjs.com/package/kv-connect-kit

- deno/x: https://deno.land/x/kv_connect_kit

- demo: https://keyspace.deno.dev/

protocol seems to works as described on the tin, and it would be pretty straightforward to write another backend

I disagree. Tying a language runtime to a specific KV interface which is tied to a specific hosted service is the opposite of forward thinking. In fact the tech industry has made a lot of progress away from vendor locked-in stacks, and this just reminds me of those.

What is really the difference between Deno.KV being shipped as part of the runtime vs adding an `import KV` statement at the top of the file (which could come from Deno or wherever else you want)?

And what are the chances that the Deno team is going to ship bindings for any language besides their own?

If Google started adding Google Cloud specific primitives natively to Go would you call that forward thinking as well?

I love Deno but I'm cautious on adopting for the same reasons. It seems like Deno can only win if they fully support their hosting competitors as well. At the same time, they will need to be as-good or better at hosting as the industry leaders. Alternatively Deno could decide to drop their own hosting and offer a multi-cloud solution with a slim margin over their hosting partner adapter. With this path, Deno wouldn't have to directly compete as a hosting provider.
Deno is just trying to compete with other JS/TS SaaS with this. Vercel/NextJS has a KV service now; Cloudflare has it; in other cases it's Firebase.

I contend that this is not actually forward thinking, but monetising Deno as a SaaS, which every man and his dog is doing in the JS world lately with their 'cloud' offerings (reselling AWS with a framework). That's why there is a pricing page attached to this.

If Deno's KV depends on FoundationDB then they're hardly going to build adapters over other databases - switching DB tech is always a massive ordeal because they all have different use-cases and performance characteristics.

> e.g. GC allowing one to return what look like stack allocated pointers from functions

I think this is due to having escape analysis and SSA rather than having a GC.

Postgres connector actually supports encoding and decoding map[string]interface{} to json and jsonb data types, quite cool.
> Leveraging public cloud infrastructure has traditionally demanded sifting through layers of boilerplate code and intricate configurations, often monopolizing a significant chunk of the developer’s time and energy.

I don't buy this line of reasoning. At the end of the day we are building infrastructure that needs to be reliable. Spending 30 minutes to set up an SQS queue (proven technology) doesn't sound as bad as putting all my trust in a toy queue that Deno built "on top of SQLite / FoundationDB". Is the 30 minute setup cost and added "developer experience" really worth the risk? How often are you setting up queues anyway.

I think this depends on who you are.

As a hobbyist programmer, I don't use the big providers like AWS and Google because they seem rather complex? Maybe it's not so bad if you're used to them.

I also like to make each project independent, as its own repo on GitHub. Ideally, a web app would be easy for anyone else to launch, as their their own independent web app, using a separate domain name, because I don't want to be responsible for their data.

(This is sort of the Sandstorm use case.)

"Try it out locally and get a Deno Deploy account if you want to use it for real" seem like reasonable install instructions?

Many people don't have experience with AWS or SQS and even those that do will still need to think about it. Deno is taking a batteries included approach which means the Dev can just import something and go. If someone provided equivalent libraries for the cloud then I'm sure people would adopt them. In the case of Deno I'm sure they've identified a common problem many Devs in their ecosystem have and are tackling it by bundling in a good solution.
Hot take: I don't think that people should even use queues any more. It's like using raw HTTP2, or managing threads.

Use a workflow engine which abstracts queues for you so you can "just write code" without managing jobs/schedules/state/retries.

https://www.inngest.com/blog/how-durable-workflow-engines-wo...

(disclaimer: I'm biased as I'm an author of a workflow engine)

By that logic no one should ever launch anything new, because it is a "toy project" by default and only AWS is proven?
How do you know it's a toy queue?
I don't recall SQS taking anytime to set up queues, at least when using Celery (python task queue). IIRC you just name it in your code and use it.
To extend this into more productive territory, there is no reason I should have to use either the Deno version or AWS; it should be an interface that can be implemented so that I can choose whatever makes sense, including my own implementation.
> How often are you setting up queues anyway.

Very infrequently. Even more infrequently as we move to IAC and use terraform or even cloudformation.

> at least once semantics.

> user code.

A past life has taught me that users will never properly understand at-least-once semantics. Anytime you redeliver messages, you will get a flurry of user complaints and breakage.

Either you do the impossible and invent a way to do exactly-once semantics. Or you should always redeliver 0.1% of all messages, just so that users don't come to depend on messages being delivered once.

Early SQS basically did this. I'm not sure if this was intentional or not but it quickly taught me to respect redelivery.
If messages need to be idempotent, I definitely recommend creating integration tests to ensure this from the sending side :-)
I'm currently using Deno deploy and found it to be fantastically performant and dumb simple for my lone wolf project. I'm experienced in AWS development in larger teams and it is nice to see a move away from complexity for a change where you can easily set something up without having to think about setting it up at all. The DNS stuff was just dead simple as well and automatic ssl certs was super nice. I have 0 complaints for what this is trying to be and am excited for the road map.
Unless I'm missing something, it looks like each Deno.openKv() instance only gets a single queue.

For the local version you could get multiple queues by calling Deno.openKv("db-2.db") with different SQLite file paths each time, but that feels like a lot of overhead for a pretty common need.

I guess this is a Deno architectural style thing - maybe when you build complex apps on Deno it's expected that you'll have a microservice style architecture where lots of different scripts work together, each of them with their own KV store and hence their own queue?

You are right, there's only a single queue at the moment.

One of the core devs has confirmed this on their discord: https://discord.com/channels/684898665143206084/115671428253...

Quoting here:

> Correct. Currently a single queue is supported. You could multiplex multiple types of messages on the single queue though.

Pricing?

I thought Deno was some sort of node.js replacement. What am I missing and can I use this either locally and/or self hosted without paying for it?

(on the off chance the devs read this) I can see pain in the future for the currently excellent KV ergonomics around access control --- is the solution just "implement it in userland and don't write bugs" or is there anything planned?
I'm excited about the recent Jupyter support and this queues.. Super cool stuff.

But I won't write servers in Deno and put them to production in my own servers. (I don't like serverless)

You see, Deno(and Bun)'s business model is built around serverless (Deno deploy). And Deno deploy is ANOTHER runtime.

It's clear with KV and queues... Locally and if you self host, you have a barely working version backed by another tech...

This means you're self hosting a version of Deno that's different from the majority of the Deno customer base.

How many people will use Deno to run servers on their own hardware? Since that number is low, then I'd rather use Node.

I find deno to be very exciting. Viable business model, great ergonomics, glorious lack of bullshit configuration busywork.
I wonder how this differs from BroadcastChannel[1] which Deno already implements and DenoDeploy seems to support.

[1]: https://docs.deno.com/deploy/api/runtime-broadcast-channel

I don't know if Ryan and the rest of the Deno team are lurking here, but given "Anchored on the robust capabilities of FoundationDB" what I think would be absolutely fricking cool is to get full access to the underlying FoundationDB engine, which would surface the "model any data model you want the way you want it" capabilities of FoundationDB directly to Deno developers.

In case anyone wonders what this would make possible out of the box: https://apple.github.io/foundationdb/design-recipes.html

I actually do quite like the overall idea of having a unified API at the language level that a (configurable) runtime can provide implementations for. Sure, in some cases an API might not be easy to abstract over due to underlying concerns, but in a lot of cases it does work.

It does show a level of understanding by the language creator that they know how the language can and probably should be used - I like how KV defaults to SQLite locally and takes on new meaning in a hosted environment. I haven't seen, but as long as you can actually override the behavior to use your own KV/queue technology (so long as it satisfies the interface) I see absolutely no issue with this.

There is a huge benefit where the code always looks the same for common things we all need to do. I wouldn't mind seeing other languages take an overall stab at this so there is some choice other than JavaScript.

Why not instructions on how to use it with FoundationDB so that we can host it on our company infrastructure?
Very timely... I'm almost finished porting WakaQ (my custom background task queue to replace Celery) from Python into TypeScript to power background tasks for a new Next.js website. I'm using T3 not Deno so I wouldn't have used Deno Queues, but it's a core part of every web app so makes sense they would build this into their stack.

Some questions:

* Looks very powerful, but at the core is it just one single queue? Does Deno.openKv() create a new queue or re-use the same queue every time it's called?

* Usually I need multiple queues of different priority, so when bottlenecks happen the highest priority jobs run first.

* Maybe they guarantee infinite worker capacity so you don't need queue priorities? No bottlenecks if you can pay for the jobs you enqueue?

Under the hood, does DenoKV implement an abstraction that specializes locally to SQLite and to Deno Deploy in the cloud? Or are DenoKV local and DenoKV cloud two separate products with a common public API?
What happens to the mantra that "database as a queue is harmful"[1]? Of course Amazon teams internally use DynamoDB for all kinds of queues, which implies that we get to do a lot of things easily if we get a super robust storage solution. So, I guess the question is really whether FoundationDB can be used as a backend for queues.

[1] https://www.google.com/search?q=Use+database+as+a+queue+is+h...

I like how updating the data and enqueueing a message can be part of a single transaction. That's indeed pretty powerful.

A bit of an aside, but not sure we want at-most-once delivery for email.

Isn't deno running locally no your self-hosted instance? How are they charging?

  Enqueuing a Message: Each enqueue action translates into a KV write operation.

  Receiving a Message: Every received message entails a KV write, and a single request charge.
I would be really curious to know. Are they only talking about Deno Deploy in the cloud, with FoundationDB? Is this "open core"?
> Leveraging public cloud infrastructure has traditionally demanded sifting through layers of boilerplate code and intricate configurations, often monopolizing a significant chunk of the developer’s time and energy. Our goal is to distill these intricacies into user-friendly primitives, enabling developers to design, refine, and launch their projects with unmatched speed.

I really like this

This is amazing syntax. If you are looking for a self-hostable version of this, that can run deno but also python, go, and bash, with primitives similar to airflow and more (retries, cache, suspend, approval steps), check out windmill: https://github.com/windmill-labs/windmill

    With grand promises rode the ploy
    Venture capital, ahoy!
    We make a lovable product to capture audience
    Vendor lock them at the earliest convenience
    Hey look at our awesome developer experience
    Add ANSI and emojis and comments saying it’s genius
    Some next level tech, plebs just don’t get it
    Next round of funding, we’ve already spent it
    I took the big dough, got puppets and framed it
    R-O-I is bad though but layoffs gon’ fix it
    Never mind the drama *cough* are ya gon’ install it
    Run it, ship it, kill yourself with working on it
    Entangle your business with it
    Tell the client to deal with it
    Bring it to the big wig
    Get ’em to sign off on it
    Crown your own sh*t
    Dogfood is tasty, ain’t it
Can we deploy both deno kv and queues on our own foundation db cluster?
I feel its odd for a compiler/language toolchain to have a cloud offering. I understand the motivations but 20% of the article was about their Deno Deploy product and how to calculate API costs...

I understand its only when using their cloud and there is a local implementation, but I just couldn't imagine using a feature in LLVM, for example, where if you were to upload the binary to a specific cloud it would use a different implmentation that costs behind the scenes.

It just feels odd to me. I guess it's kind of cool. Maybe different clouds can implement the underlying KV and then this becomes cross-cloud with different underlying benefits without changing the code. But I'm not entirely sure how I feel about this.

On the topic of Deno's cloud deployment and Deno KV, does it offer a reasonable user story for caching? Or is that something you're expected to handle yourself (for now)?
Deno is amazing for backend.

Is there any full stack solution other than Fresh?

I never liked Agenda (Persisted delayed task queue using MongoDB). This example[1] using Deno Queues & KV is easy enough to be a replacement for Agenda.
How is this different than using RabbitMQ? Can anyone tell me what’s the benefit of choosing this one over some other message queues or even kafka?
I don't want my programming language to "implement" task queues and charge me for it. What is this

edit: people seem to be getting hung up on the "runtime" v "programming language" distinction. I'm not sure why--it's weird to me that this is "part of the language + runtime" at all. Clearly, reasonable people can disagree about that, but hopefully on points more substantive than pedantic

If tomorrow, someone started a for-profit company making a faster Python runtime and introduced features like this, it would be weird, and it would feel as pointless to me as Deno is