Introducing Workers KV
blog.cloudflare.com
blog.cloudflare.com
Currently this isn't a great way to serve content because the values are limited to 64k, you have to infer content-type (which makes your URLs ugly), etc. So I don't recommend it. We'll come up with something better in the future. :)
One great example of why this would matter to me - could workers ever institute a coordinated rate limiting function using this KV store?
By combining those with KV to do global coordination on a more course time scale, I think you could.
Seriously, if you're new to that domain go read:
https://aphyr.com/posts/333-serializability-linearizability-...
Workers don't have the concept of processes. The unit of compute is an individual event -- e.g. handling an individual HTTP request. So we'd have to augment it a bit, but we can probably come up with something useful.
https://en.wikipedia.org/wiki/Compare-and-swap
It might be straightforward to do this with an ETag like Firebase:
https://firebase.googleblog.com/2017/07/introducing-conditio...
Not sure what this would require on their backend though.
(This logic is not quite in production yet but should be within a week or two.)
You're right for some use cases though.
It can work for simple apps but there's a long way to go before any serious enterprise system will be hosted entirely on a FaaS system like Workers.
At the point that CF replaces the origin, it is the origin.
The confusion in your query is the idea that "origin" is a rigid, fixed concept rather than flexible.
Would also be great if CF could do websocket / sse fanout at the edges - if I have a couple million websockets connected on ws.cf.com/key1 and I update the value, would be great if the new value could be broadcast. That would help with a lot of media / real-time / sports games, apps and websites.
The more specific cases include opening ticket sales for movies in India - for some big movies tickets are sold out really quickly, so there'll be hundreds or thousands of people with browsers / phones open on a seat layout and they all need to see which seats are being sold in real-time.
Then there's broadcasting stock market movements and tips to thousands of traders in real-time.
The only existing solutions that seem really scalable are fanout.io - others like pusher.com and pubnub.com have pricing that's not conducive to serving a large number of simultaneous users / broadcasting. Fanout.io gets this right, but would be nice to have cheaper alternatives / make it a commodity.
Given that the CF nodes do support websockets, I assume they terminate and re-create new connections to origins as well - so the nodes are capable of holding a large number of websockets open, right? Can Workers intercept websockets / stream data into them? And given that the KV store is capable of propagating new values to all the nodes, there could be a way expose incoming change notifications on keys, which would handle this use case. Could also implement as continuous addition of new timestamps keys, prefixed with a topic.
If you can accept up to 10s of latency, I agree that KV could solve the 'pushing events' problem for you. (A tuple store is semantically equivalent to message passing, and it will get easier when we support range queries).
Low latency requirements also tend to be geographical, I think - stock markets are mostly specific to a single country, examples like ticketing are usually specific to a single city / edge. For general news being broadcast globally, that kind of latency is fine.
Hi! Fanout founder here. I’m glad you like our way of doing things. If you need better pricing for high volume we are always willing to discuss.
I’m not sure you’d want to maintain a WebSocket inside of a CF worker. At least I can’t see that helping with cost. Execution time limits would get you too. IMO connection management belongs as a separate layer in front of the worker, so workers are only woken when things happen.
And on that note, of course you can use Fanout together with Cloudflare Workers today. At the moment this requires making raw API calls but we plan to update our server libs for CF compatibility soon.
Hi! Wasn't expecting you to show up like this. Re. pricing for high volume, I'm sure enterprises and publishers could afford it, I'm trying to see if it's possible to offer free or very cheap service to individuals with large audiences. So not so much that I want a high volume discount, I'm trying to figure out a way to make it one or two orders of magnitude cheaper, enough that pricing is no longer relevant. Self hosting Pushpin is an option, but CF might be easier to work with.
> I’m not sure you’d want to maintain a WebSocket inside of a CF worker. At least I can’t see that helping with cost. Execution time limits would get you too.
The CF edges already hold / passthrough websockets - whether the Workers API is conducive to controlling them is the question, but we know it already allows streaming - doesn't seem like big jump from there. And for my purposes one-way streaming is enough, so might not even need to change the API. And based on the current billing model it seems like only CPU time is billed (?) - so if the socket is waiting most of the time it's still cost effective. And connection management itself would still be outside the scope of the worker - I'm saying the worker's event loop should behave exactly the way it would if I using the streaming feature right now to make a 1000 slow network requests from the worker and streamed the responses out as the worker received them. Only the protocol would change.
Even still, handling millions of simultaneous connections, with each connection in its own worker in a multi-tenant execution environment in order to save money sounds crazy. :) The operating cost (and thus the price) of a purpose-built system like ours should be lower than that of a generalized system. I think your easiest path is to just tell us your preferred pricing model.
From the cloudflare side I'd assume that each edge has 1 > n <= 10 of the CF version of this https://www.top-ix.org/wp-content/uploads/2016/10/Open-Conne... . Imagine CF had 100s to 1000s of these at every edge - they could/would then offer either DO sized droplets or AWS Fargate sized containers at every edge with CF load balancing, and we could be installing Pushpin on every edge. And it wouldn't sound odd. This seems like it's just a logistics problem - it's not inconceivable that 2020 / 2023 birthday week will announce this. (@CF you should totally call each droplet/instance a 'Flare')
In the meantime the Workers seems like a way to offer highly controlled computing on these edges - but other than the tighter control of the executing environment I see no difference from the scenario mentioned above. So if all the load balancing, connection handling and deployment pieces are already in place, I think we can and should try to use it for any possible use case that we would have used regular servers for.
Running Pushpin on a bunch of compute instances means being able to operate at maximum performance with minimal impact between tenants. Compared to FaaS, I believe the difference in resource usage should be so significant that any provider of a shared-Pushpin service would be able to win on price.
I'm also still not quite sure how a FaaS-based push system would actually work since there's the problem of getting data around among the workers. You don't want a million workers polling a DB. I suppose you could integrate a messaging/queuing system with your workers, and each worker keeps a long-lived connection with the queuing system. But if you do this, you'll have barely built a push system at all. Instead you'll be dependent upon a millions-connection-capable queuing system, and your workers will simply be doing data conversion between two connections. And of course the queuing system would live outside of the FaaS, provided by someone for a cost.
> There's no truth in the rumour that a KV store is a @KentonVarda store. Nor that it maps kentons to vardas.
If you’re truly replicating to every PoP that’s quite a fan-out and I can see why you’re limited to 1 write per second per key!
Can you create data spaces/keys for ones that are read-write per-user and others that are read-only for a given user?
Aside, it seems like this could be really interesting combined to make an entire API with static delivery from S3 or Azure Blobs, with a backend on a cloud hosted database. With a lot of flexibility in between.
When you say overhead limit, are you talking about latency? Our goal is to keep reads on the order of 5ms in the 90th percentile.
There's a (K,V) pair somewhere, but in order to get V, you need K, which you've lost.
You could also store carts by session id until they're logged in, and then store the carts by account id when they are.
But the person you responded to asked what happens after "I clear my local storage/cookies". So you don't have access to the session id. It was in a cookie that is now gone.
Our hope is that anyone could create such an API, not just Cloudflare. Just like we are building storage on top of workers, we hope to eliminate the distinction between what is possible for a Cloudflare employee and what is possible for any of our customers.
I think you might be overestimating that. Bundling the aforementioned https://github.com/faisalman/ua-parser-js wouldn't be significant - maybe hundreds of KB as a script (distinct from memory!) - at most.
No big dataset needed, just some regex and if/then statements. If you still want a library then you can try https://github.com/faisalman/ua-parser-js
Like, "show me all keys that match xyz∗ in this namespace"
I've considered similar for shard keys in terms of proximity related information.
$5/month for
- 1 GB of KV storage and up to 10 million KV reads
- 10 million requests
After that it's $0.50/month - per million requests
- per GB of storage
- per million KV reads
I think that's well within startup money. I mean, if a company has to give out credits perhaps it's just too expensive :-)