Cloudflare K2: serverless event streams
Introducing Cloudflare K2: Serverless Event Streams
Published: October 1, 2026
Authors: Micah Wylde and Marc Selwan
Reading Time: minutes
In traditional Remote Procedure Call (RPC) setups, there is a fundamental friction: producers and consumers must be perfectly synchronized in both timing and capacity.
When producers overwhelm consumers, or when downstream services experience outages, the result is inevitable: data is preserved events are dropped. This fragility is magnified when multiple independent consumers need to process the same data stream—such as an e-commerce platform that must simultaneously feed transaction data into a fraud detection engine and an analytics dashboard.
To fix this, we must decouple the two sides by introducing a buffer that absorbs incoming writes and allows readers to consume data at their own speed.
Enter Cloudflare K2
We are excited to announce the public beta of Cloudflare K2, a durable event streaming primitive integrated into our Developer Platform.
K2 allows you to send events to a stream, which are then stored as an ordered log. Depending on your needs, consumers can read this data through various patterns, such as splitting the load across multiple consumers or broadcasting every message to every consumer.
Key Characteristics of K2:
- Fully Serverless: No infrastructure to manage.
- Massive Scalability: Designed for vast data volumes.
- Long-term Retention: Ensures data persists even during extended consumer downtime.
High-Level Architecture
K2 is built as a partitioned, durable log leveraging R2 object storage for its backend, enabling virtually unlimited storage capacity.
Engineering Streams at the Edge
K2 was born from an internal necessity: the need for a durable buffer to act as the ingestion layer for Basin Pipelines. Because Pipelines utilizes a pull-based stream processing engine, it requires a system to hold events before they are transformed and committed to R2.
Crucially, Pipelines guarantees that once an event is accepted, it will never be lost. This requires extreme durability over long durations.
The Edge Challenge
Operating across 335+ cities creates a unique environment. Traditional distributed systems (like Apache Kafka) aren't a natural fit because:
- Resource Constraints: We operate with relatively small machine slices.
- Ephemeral Nature: Nodes are frequently recycled.
- Network Volatility: Communication often occurs over the public internet.
However, we leveraged our "superpowers": global proximity to users and massive horizontal scalability.
The R2 Foundation
We decided to build K2 on top of R2. By utilizing object storage, we gain incredible durability—specifically (99.999999999%).
By offloading the complexities of consensus and replication to the storage layer, the K2 application layer becomes:
- Simpler to maintain.
- Cheaper to operate.
- Higher in performance.
Furthermore, separating compute from storage allows each to scale independently, keeping historical data costs low.
Solving the "Append" Problem
A technical hurdle is that R2 (and most object stores) does not support appends. To solve this, K2 uses a buffering strategy:
- Writes are accumulated in-memory on an edge service.
- After a brief window, these events are flushed as a segment file.
- Ordering and strictly increasing offsets are managed via
R2's atomic operations, removing the need for a separate coordinator.
The Trade-off: This architecture introduces higher produce latency. Because we must wait for batches to accumulate and write to object storage, the produce latency is approximately at the percentile.
K2 vs. Other Cloudflare Primitives
Cloudflare offers several ways to handle asynchronous data. Here is how to choose between them:
| Feature | Cloudflare Queues | Cloudflare K2 | Basin Pipelines |
|---|---|---|---|
| Primary Use Case | Individual, expensive tasks | High-scale data movement | Event transformation to storage |
| Consumption | Item-by-item | Batch-based | Pipeline-driven |
| Retention | Short-term (until processed) | Long-term | Varies |
| Key Strengths | Retries, Delays, DLQs | Fan-out, Ordered Logs | Iceberg/R2 integration |
| Latency | Low produce latency | Higher produce latency () | Stream-based |
When to use what?
- Use Queues if you are handling specific work items (e.g., an image processing request) that require granular logic like dead-letter queues or specific retry delays.
- Use K2 if you need to move massive amounts of data, maintain a long-term history, or allow multiple different services to read the same stream.
- Use Pipelines if your ultimate goal is to land JSON events into an Iceberg table or
R2object storage.
Getting Started
You can maintain multiple streams per account to categorize different event types.
Deployment Options
You can provision your streams using any of the following:
cfCLIWrangler- The Cloudflare Dashboard
- The REST API
Quick Start Checklist
- Create a Cloudflare account.
- Navigate to the Developer Platform.
- Initialize your first stream via
Wrangler. - Configure your producers to send events.
- Attach your consumers to the ordered log.
// Example: Conceptual K2 Stream Interaction
async function produceEvent(event) {
await K2.stream("transaction-log").write({
data: event,
timestamp: Date.now(),
});
}
Stay tuned for an upcoming technical deep dive where we will explore the inner workings of K2 in greater detail!