Using workers KV vs SQL Database

Hello CF community,

I am building my first serverless app. Traditionally I am used to SQL/NoSQL databases, typically a MEAN stack.

I know there is a(n unsupported) repo that supports using workers and SQL but my concern with that would be performance. I would really like to use workers to run a JS/TS application but the data storage is a deal breaker if KV is not an ideal solution for some of the functions of the application. Azure has support for DB operations with their serverless solutions but I feel like using a separate DB host and then workers scripts will cause too much latency and way higher execution times.

Some of the data my application would need to store is
-User information (name, email, passwords)
-Purchases - an array of products that the user account owns
-Gameplay data - statistics from matches of games
-Content information (relations of paths to the static file storage, ex. profile pictures)
-Historic information (basic logging of some activities)
-Session data

I know that purchases, gameplay data, and content information are good use cases, but I don’t think user information will be ideal due to the ~30-60 second propagation time. Registering a new account or changing a password should be instant.

Does anybody have experience building a serverless app with similar use cases? I’m interested to see how these can be accomplished using only KV or a combination of a traditional DB.

And if any staff is here - are there any plans on implementing a full DB solution for workers at some point in the future? It would make it way less tempting to run the whole thing on Azure/AWS.

If you’re going to do stuff with a ■■■■-ton of requests, using a VPS would be easier and cheaper. Workers aren’t suitable for every use-case and there’s a chance you invest time and effort into creating something you’d do faster on standard server with too little gains.

That said, if you’re already outgrown VPS, then there’s a lot of potential to scale effortlessly with Workers if you can build it.

A big blocker for real-time data is that the KV (database) isn’t instant, it can take up to 30 seconds before it’s available (readable) globally. That said, you CAN use it to sign up users and they can instantly login - but they cannot instantly login from china if registering in EU for example.

You may take a look at this:

But the latency should be not as good as Workers KV.

Hi @mason.curry1,

You may want to take a look at Durable Objects to help with storing things like user information. Having a Durable Object per user is a very natural mapping as long as the rest of your app can also fit into either KV or Durable Objects.

Otherwise the best you can do today is to connect to external databases that support requests over HTTP, like Aurora Serverless on AWS, CosmosDB on Azure, or Spanner on Google, but you’re right that locality is a reasonable concern. There are also more widely distributed options out there like FaunaDB that make latency from your Workers to the DB less of an issue.

I can’t make any specific promises, but we’ll continue to work on expanding and improving the options for more traditional data storage :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.