What is K2?
Cloudflare added a new event streaming service called K2 to its Developer Platform. It is currently in public beta. K2 decouples producers from consumers by safely buffering the data flow between them.
In traditional RPC architectures, producers and consumers must align in both timing and scale. If a consumer falls behind or a downstream service goes down, events can be dropped. K2 solves this by placing a durable log in the middle.
How it works
K2 stores events as an ordered log. Consumers can read it in different ways: they can split reads across a consumer group or deliver all messages to all consumers. The service is fully serverless and supports long-term retention, so data is not lost even during long consumer downtime.
Why not Kafka?
Cloudflare first built K2 out of a need for a durable buffer at the edge, initially for Basin Pipelines. Pipelines runs on Cloudflare's edge infrastructure spanning more than 335 cities. In that environment, machines are small and short-lived, and networking is often over the public internet. That makes running traditional distributed systems software like Kafka difficult.
Instead, Cloudflare leaned on a state primitive it already had: R2 object storage. R2 combines high durability with strongly consistent APIs. Offloading replication and consensus to the storage layer makes the application layer far simpler, cheaper, and faster.
A log on top of object storage
R2, like other object stores, does not support appends; instead, complete files must be written. K2 first accumulates writes in memory on an edge service, then after a short wait writes all events as a single segment file. Ordering and strictly incrementing offsets are achieved using R2's atomic operations without a separate coordination service.