10 ms·
Introducing Workers KV
- ryanworl 8y agoAre you planning on releasing any of the architectural details behind this service? 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!
- jgrahamc 8y agoYes, we will. This is something we built internally and we'll talk about architecture at some point.
- Serow225 8y agoThank you! Lots of super cool stuff coming out of CF these days, the pace is hard to keep up! Not that it's a bad thing necessarily :)
- kentonv 8y agoOne interesting implementation detail is that this product is itself implemented as a worker. We're finding that the Workers platform is the easiest way to build first-party Cloudflare features.
- zhobbs 8y agoI was wondering if it is lazily replicated to PoPs via KV gets. Would be interested in clarification on that though.
- kentonv 8y agoAt present, yes, lazy propagation. But we're also exploring ways to do proactive propagation where desirable.
- flaviocopes 8y agoPretty awesome to see Charles Babbage credited in the introduction.
- sylvinus 8y agoIf you're interested in his work, you might want to check out another project of JGC: http://plan28.org/ http://plan28.org/
- _pmf_ 8y agoTuplespaces?
- chrisweekly 8y agoThis is really cool. Webapps are basically programs that are executed across the network; having fine-grained control over what happens at each layer (client, client service worker, edge nodes, proxy server, origin server) means more choices and complexity, but also so much more power.
- zackbloom 8y agoThe question I would ask is: once you have the ability to run code and store data on the network itself (which Cloudflare effectively is), why do you need an origin at all?
- scoggs 8y agoI could be understanding the crux of your question wrong but I believe the point the article and technology makes over and over is that it offloads nearly all of the stress and communication off of the backend and instead replaces it with a Worker KV which converts into becoming one static call and then everything is handled within the Worker. The applications seemed vast and only limited by creativity, as well.
- tyingq 8y agoOne write per second, per key plus eventually consistent does limit the functionality a bit. You're right for some use cases though.
- hamandcheese 8y agoWhere are you getting 1 write per second from?
- jweather 8y ago1 write per second per key. It's from the Limits and Pricing section of the technical post: https://blog.cloudflare.com/building-with-workers-kv/ https://blog.cloudflare.com/building-with-workers-kv/
- webjames 8y agoWith the shopping cart example, I'm not sure I understand how session identity can be preserved if I clear my local storage/cookies?
- ericcholis 8y agoYou'd still need some identifier, ie: a cookie, to link the KV store and your session.
- zackbloom 8y agoIt's moving that shopping cart data from being stored at a single origin, to being stored in the network all around the world. The advantage of that in that use-case is you can render your site just as quickly as if it was a static website, but it can contain the customer's personal shopping cart data.
- adrianmonk 8y agoThe shopping cart is still stored somewhere, but when the user has cleared their cookies, etc., what information do you have that will let you it's their shopping cart so you can find it again? There's a (K,V) pair somewhere, but in order to get V, you need K, which you've lost.
- zackbloom 8y agoIt would work just as most shopping carts do I imagine. You could store a session id in a cookie, and then use the data in KV to map that session id to a user account (if they're logged in) and their cart. So you would have a namespace full of sessions, and a namespace full of carts. You could also store carts by session id until they're logged in, and then store the carts by account id when they are.
- adrianmonk 8y ago> You could store a session id in a cookie 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.
- OJFord 8y agoThe feature aside, this is a really great blog post: learning a bit about the history of the feature, even if only tangentially related (Babbage and the Analytical Engine) in the intro is great.
- jgrahamc 8y agoThank you; that's kind.
- deleted 8y ago[deleted]
- gaius 8y agoDupe https://news.ycombinator.com/item?id=18092660 https://news.ycombinator.com/item?id=18092660
- chatmasta 8y agoThose are different blog posts. Also, the OP of both is CTO of Cloudflare.
- mkj 8y agoGood work Kenton Varda getting his initials into the product name!
- kentonv 8y agohttps://twitter.com/jgrahamc/status/1041998948733472768 https://twitter.com/jgrahamc/status/1041998948733472768 > There's no truth in the rumour that a KV store is a @KentonVarda store. Nor that it maps kentons to vardas.
- noelwelsh 8y agoHoly return of tuple spaces! Are there any features for controlling consistency, or is it just YOLO last write wins?
- kloepper 8y agoLast write wins. There are several features for controlling consistency that we have been prototyping. Based on how storage is used we will enable those as the product matures.
- zzzcpan 8y agoSo why not strong eventual consistency and CRDTs? As they fit perfectly for such functions running on edge nodes and no silly limitations of 1 write per second necessary.
- kentonv 8y agoIndeed. This is just stage 1 of our storage plans. We have some really cool stuff in the works but we wanted to get basic KV functionality out there for people to start using ASAP.
- _pmf_ 8y agoOT: we need to read more about your website-in-kv-thingy setup.
- kentonv 8y agoIt was pretty trivial. I just stored each page into a value and served them out of there, with some stupid code to infer content-type from file extension. I meant it as a dumb demo because I wasn't feeling creative. I didn't know John would mention it in his blog. :) 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. :)
- mbell 8y agoAre there any plans to provide browser detection in the worker API? I imagine it's possible to implement as a user now, but may be clunky to provide a dataset to work from. This seems like a killer feature to have on edge workers to allow serving optimized builds for based on browser feature support without paying the overhead of client side detection.
- zackbloom 8y agoIf you can find a good Javascript library for doing it you can build it into your Worker with Webpack.
- mbell 8y agoIt's not finding a parser that I find problematic, it's the dataset needed. My understanding is that the workers are limited to 128MB of ram and that they may be 'restarted' at any time. Datasets for accurate browser detection would be really tight in fitting into that amount of RAM when combined with whatever else you may be doing and you have to deal with load / parse time whenever a worker is restarted. This seems like a common enough need that cloudflare could provide it as an API and their implementation wouldn't have such issues.
- kloepper 8y agoUsing storage along with worker code to perform the function should make this possible. 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.
- elithrar 8y ago> ... understanding is that the workers are limited to 128MB of ram and that they may be 'restarted' at any time. Datasets for accurate browser detection would be really tight in fitting into that amount of RA I think you might be overestimating that. Bundling the aforementioned https://github.com/faisalman/ua-parser-js https://github.com/faisalman/ua-parser-js wouldn't be significant - maybe hundreds of KB as a script (distinct from memory!) - at most.
- sahin-boydas 8y ago@jgrahamc what a great service. It might be great to have cloudflare credits like aws/google/azure credits for CL Workers for startups.
- jgrahamc 8y agoTake a look at the pricing. $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 :-)
- Operyl 8y agoHeck, I think that's well within hobbyist budgets. Thanks for pricing it out nicely :).
- deleted 8y ago[deleted]
- Serow225 8y ago@jgrahamc could you link to the technical post near the top, and maybe copy in that table 'Limits and Pricing' on this post? Because it would be really helpful to have that info in the general post, otherwise it's not clear what the details are (like write rate). Great posts BTW!
- tyingq 8y agoIs there an API method that can list existing/matching keys in a namespace with a glob or prefix or similar? Like, "show me all keys that match xyz∗ in this namespace"
- zackbloom 8y agoWe're planning on adding support for range requests (which becomes equivalent to prefixes a la CouchDB). Is there a reason you need glob specifically?
- tyingq 8y agoWhat you're describing would work...
- tracker1 8y agowell, for one example off the top of my head would be using geohashes for proximity in records... if you could glob every geohash with the same first 6-8 characters, you could do range queries pretty quickly. I've considered similar for shard keys in terms of proximity related information.
- sctb 8y agoShit, the Cap'n Proto website is like 10ms faster than the HN frontpage now.
- sudhirj 8y agoGreat job - was trying to something similar by setting up three etcd raft nodes on each continent, but this is like 150+ nodes. Mind sharing of you’re using good clocks, paxos or raft to coordinate? 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.
- zackbloom 8y agoCan you talk more about your specific use case?
- sudhirj 8y agoThe simplest example is liveblogging - someone is sitting at the next iPhone launch, and sending out photos and commentary that's being updated as they send on a large number of readers' screens worldwide. The Verge has a good system that they do with polling S3 for new data, but there's really much more effective ways to do it. 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.
- 8y ago
- tracker1 8y agoThis is very cool, but how do you limit an end user to only being able to read a given set of values. It seems to me that this scheme puts all credentials for access in the browser, and they'll be able to just run roughshod all over your data without constraints in place. Can you create data spaces/keys for ones that are read-write per-user and others that are read-only for a given user?
- zackbloom 8y agoYou write the Worker code which runs on our infrastructure, not in a browser. You have complete control over who can access which piece of data, as it's your code doing the accessing.
- tracker1 8y agoThanks, I misunderstood that part... very cool indeed. What are the overhead limits for workers? 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.
- zackbloom 8y agoThe ultimate goal is to let you do all of that within our network! 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.
- tracker1 8y agoI mean compute/memory for the workers... just a rough comparison of what that might look like. Will probably sign up for the early access and play around with it soon.
- zackbloom 8y agoWe limit you to 50ms of CPU and 128 MB of memory now, but we're working on ways of raising those limits.
- skunkworker 8y agoWith this and the changes to their worker caching API it's now completely possible to write a custom pull origin CDN service that you have complete control over.
- manigandham 8y agoI wonder how the Fastly crew feels about all this. Great team over there, and they were originally the super configurable CDN, but it seems that is now completely beaten by Workers.
- skunkworker 8y agoI'm curious but I haven't seen anything about cache expiration on keys. Eg Expire all keys 'key-1' after 30 minutes or expire at a globally recognized time frame. Does anyone know if this is possible?
- zackbloom 8y agoWe haven't exposed it yet, but it's implemented internally. Follow our blog and we'll update you when it's released.
- skunkworker 8y agoAwesome, I'll be sure to keep up on that.
- zzzcpan 8y agoA bit offtopic: could you guys move the "please enable javascript"/captcha page to a separate, but cloudflare owned domain, so at least people who don't want to enable javascript for random websites behind cloudflare could enable it for your domain and pass all your browser checks?