Cloudflare K2 is a serverless event streaming service built directly on top of R2 object storage for high-scale data movement and long-term retention. By decoupling producers and consumers at the edge, K2 enables…

297 points•elffjs•2 months ago•112 comments•

112 comments

psanford2 months ago
Object store is quickly becoming the new core data substrate. Lets build kafka, but on s3. Lets build github, but on s3. It feels like we going to see more and more "object-store first" systems in the next few years.

I am excited about this future. Give me stateless servers and a storage bucket over having to manage systems with disks any day.

I do wonder if we will see an expansion of the s3 api to support more of these use cases. S3 added a janky file append operation to their new express-one-zone bucket type, and limited to 10k total file append operations. I wonder what else we will get in the next few years.

necubi2 months ago
Definitely agree that every data system that doesn't need <100ms latency is moving to object storage.

> I do wonder if we will see an expansion of the s3 api to support more of these use cases

This is actually an area where I think we have a big leg up on folks building on top of S3. My team (which built K2) sits next to the R2 team, and we have the opportunity to co-evolve the products in mutually beneficial ways.

sensodine2 months ago
> every data system that doesn't need <100ms latency is moving to object storage

I think the opportunity extends below 100ms too, particularly given the existence of faster object storage tiers like S3 express or more recently GCS rapid bucket (both only offering single-zone durability, so still need to do quorum writes to get region-level durability as with standard tiers).

One of the tensions of course is how long to linger before flushing to object storage - you have to trade off directly between latency and cost of your API ops for PUTs.

When building the serverless offering of s2.dev (which is in a similar space, full disclosure!), we designed around stateful backend processes capable of constantly flushing multi-tenant objects (i.e., containing records from many streams), allowing streams to offer low ack latencies (~50ms p99 from same region) without blowing up the unit economics.

Congrats on the launch btw!

khazit2 months ago
I still think S3 is underutilized.

The range of things you can do with blob storage and a (very simple) auth model are surprisingly broad.

We recently replaced our Docker container registry with S3 using a tiny tool [1] we built in-house. I think that even with current capabilities, we can still model a lot services as a very thin layer over object storage.

[1]: https://github.com/Simple-Observability/grue

monster_truck2 months ago
From the opposite side of things, I feel the same about OPFS. Finally having something that performant that multiple workers can operate against in a browser is such a massive boon. You could plug something like that in to it locally with markedly less bullshit than you would have had to do previously with the other APIs.
tomjen32 months ago
That sounds really cool — I tend to agree with you that S3 and similar are underutilized, but I remember that essentially all of the providers charge for bandwidth measured in gigabytes and I'm like no. My consumer line is measured in megabits per second and if I have to pay for my data usage the way it's paid for in data centers it would be far more expensive. Somehow consumer ISPs, who have to pay for the lines, are cheaper than than the cloud providers.
ForHackernewsabout 2 months ago
Have you seen Zot? It's a more full-featured extension of this same idea, and also supports S3 as a storage backend: https://zotregistry.dev/v2.1.21/articles/storage/#configurin...
deanputney2 months ago
I'm a little surprised the Docker CLI doesn't support this directly, since gcr.io works this way. Maybe there's a thin layer between the bucket and the CLI? Neat that you worked it out for the generic case.
shye2 months ago
It makes perfect sense: it's a extremely reliable, infinitely-scalable, strongly consistent (in some implementation), cheap, and extremely simple to use key-value store. As such, it transparently solves a lot of the problems distributed systems have to be engineered around.

As long as you can run on a CSP, and can engineer around the high-ish latency (most business cases can), it's extremely expensive to try engineer around it.

Onavo2 months ago
People like S3 because they have hard engineering guarantees around bit rot and work well as a high level abstraction of a network filesystem with all of the low level failure recovery built-in. You don't have to worry about doing your own RAID configs. The bigger question is whether non-AWS services can offer the same level of guarantees. I have heard horror stories for example when it comes to downtime on Hetzner's S3 object store.

I am currently using Cloudflare R2 right now and if you see their forums, there's always the occasional post about objects going missing.

sgt2 months ago
Meanwhile, just using disks and regular servers is still reliable and more so than ever, especially with some redundancy.

Consider your cloud costs.

someonebaggy2 months ago
I find that Ceph is pretty annoying to operate but if you do, it works fine. Keeps redundant copies of data on multiple disks, across multiple racks if your diversity is that wide. Supports erasure coding for effective redundancy less than 2x.

Don't go for the "object gateway" compatibility layer - just use raw Ceph if you're writing your own app.

UltraSaneabout 2 months ago
On one hand the durability and scalability of object storage is amazing. But on the other hand it seems perverse to build so many systems around the very high latency of object storage when we have NVMe SSDs that have higher bandwidth than RAM did not long ago and microsecond latency.
necubi2 months ago
I'm the author of the post and tech lead for K2. Happy to answer any questions!
e1g2 months ago
I'm doing some testing, and while my writes are <1s, I'm seeing E2E delivery latency of p95=2.5s / p99=7.5s. Is this roughly expected?
turbofish20about 2 months ago
The tail latency is higher than we would expect, but tbh our Consume API have work to do in terms of perf optimization. If it's not much to ask, can you share what's the max_records and the size of the stream that it was tested on? We are working on improving the read latency and you should be able to observe them in a week or so :)
samtp2 months ago
After reading the post, still don't fully understand when you would use CF Queues vs K2. Can you help to elaborate a bit more?
necubi2 months ago
Sure! There are definitely some overlapping use cases, and we've seen folks using/abusing queues for use cases that are more appropriate to something like k2.

Queues are great when you have a unit of work that needs to be completed, retried, and tracked individually. For example, a shop might need to call a payment processor API that can fail or timeout, and retry it until it succeeds, while polling on the frontend for the state of that particular message. With a queue, you can insert a message tracking that payment, and have a queue processor that keeps getting sent it until it succeeds or has failed too many times.

In a queue each item is its own thing that's important to someone, and queues give you APIs to interact with that particular item.

K2 is for moving large volumes of data around. Pricing is per GB, not per message. Records are produced and consumed in bulk, and what matters is that all records are processed, but no one is querying the state of a particular record. K2 also supports multiple consumers for the same record, and long term retention. For example, all of your applications may emit events when things happen, and those events need to be read by an alerting system, a system that durably stores them, and a system that uses them to build ML features.

pcthrowawayabout 2 months ago
My understanding: Distributed queues are generally good for when you have multiple workers processing chunks of work. Each queue item usually needs to be processed to completion exactly one time, so the queue provides the mechanism for the workers to coordinate state of each item at the item level (which allows for time-outs and re-tries if, say, a worker dies during processing, like if you were using spot instances for your worker pool)

Event streams are for multiple consumers, and can offer different guarantees. As far as I can tell, K2 is designed to ensure all consumers receive all events at least once (it's unclear to me whether this means they're continuously storing all events from the stream origin, or if older events age out at some point, or are dropped when they've been consumed by all known consumers).

Other types of guarantees with streams might be "at-least-once", "at-most-once", and "exactly-once" delivery, for different needs. Redis streams used to be at-least-once but it looks like they support all 3 use cases now. Some relational DBMSes also have the option to replicate by streaming their transaction logs to all servers in the cluster so each node maintains its own understanding of the database state (though stale reads can also occur in some/all? DBMSes that replicate this way, when a server is queried before receiving an update)

hasyimibhar2 months ago
Queues are for actions (do this), K2/event streams are for events (this happened).
aniketsauravv2 months ago
Great product, congratulation on launch. Are you using this internally in any way?
necubi2 months ago
Yes! We originally built K2 to serve as the ingestion layer for Basin Pipelines [0], our stream processing product. We have a number of other teams building new products on top of it at the moment which I can't talk about yet :)

[0] https://developers.cloudflare.com/basin-pipelines/

prasoontrivedi2 months ago
Have I understood the pricing correctly? There's charges for data published and consumed per GB?
httgpabout 2 months ago
Congratulations on the launch! Was this built on top of Arroyo?
nnxabout 2 months ago
The pricing is surprising, Data Produced at $0.04/GB seems reasonable (when compared to other clouds event streams) but Data Consumed being at the same $0.04/GB is rather steep...

This means actual usage is $0.08/GB in the simplest case (one consumer) but fan-out consumer strategies get very expensive very fast.

loufe2 months ago
If I was a serious Cloudflare customer I would be seriously concerned about the security of my infrastructure with them. Yes LLMs can code fast but this is an almost frenetic pace of releasing new products, all with fewer staff.
owenthejumper2 months ago
They've always been this fast. The trick is that they release beta products a lot. Kind of classic "lean" (does anyone remember that?)

My bigger concern would be their increasing grip on a lot of the market, and eventually becoming a monopoly (or part of the big tech "duopoly")

sssilver2 months ago
> eventually becoming a monopoly (or part of the big tech "duopoly")

At this point this has already effectively happened. The average person doesn't realize the extent of it, because the products Cloudflare builds are inherently transparent to the average consumer.

NicoJuicy2 months ago
That's just perception. At the same time they were hiring 1 k. People and hired 2 k. People the year before ( interns).

There was just more news about it than with other companies ( I think they let go about 2 k. People a year ago).

( Not saying it's good, just a little perception balance)

hack13122 months ago
It hasn’t even been 6 months since they fired 20%
vmg122 months ago
They are working on a set of primitives that make building this kind of software easier. With AI, runtimes matter more than ever and languages matter less.
threatofrain2 months ago
I find this release relieving because it fills a hole that was really needed. Another hole would be a proper database and improvements to D1.
wqtz2 months ago
I trust that this is not the case. Check out both the authors. Micah's company was acquired by Cloudflare, and both of these guys actually bring good expertise around this area.

The question is less about "vibe coding" the product, and more about how their acquired teams function. For most products they have released so far, they are backed by a company they acqui-hired. They will usually rebrand the product and absorb the team.

You would not be surprised if this release was from a product for a startup company rather than a large enterprise company.

Cloudflare hired a bunch of folks for sure, but they also fired a lot of folks. What they are doing these days is building products by buying out entire companies, giving them nearly independent authority to build a product like they would build a company.

addisonj2 months ago
Congrats on the launch! Stream/event-based system are really powerful, but they are also just pretty complex, in no small part because the modeling of streams for most people today is really modeling Kafka topic/partitions which has a whole bunch of foot-guns and complexity. Making the individual stream really cheap and easy is a big simplification, especially if flexibly consuming a stream for both ordered and unordered use-cases is made simple. This looks to work for unordered, be curious to see how the managed dividing the work for the mentioned key-based ordering.
mrkeen2 months ago
To support the ordered use-case, put events on the same topic-partition. To support the unordered use-case, don't.
someonebaggy2 months ago
Kafka works the way it does for a reason. I don't see how Cloudflare can avoid the same fundamental limits that Kafka faces.
Kinranyabout 2 months ago
Discovering the limits is not trivial though, and they also change as hardware changes?

Read the full thread on Hacker News →

Related stories