logo
Kurashizu Blogwhere ideas flow
  • Home
  • News
  • Blog
  • About
  • Home
  • News
  • Blog
  • About

© 2026 Kurashizu. All rights reserved.

Admin·New Post·Service Status
Powered by Cloudflare·30.10.26
← Back to news

Cloudflare K2: serverless event streams

Original article
blog.cloudflare.com|86 points|26 comments|by elffjs|Oct 1, 2026

Introducing Cloudflare K2: Serverless Event Streams

Published: October 1, 2026
Authors: Micah Wylde and Marc Selwan
Reading Time: ≈7\approx 7≈7 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:

  1. Resource Constraints: We operate with relatively small machine slices.
  2. Ephemeral Nature: Nodes are frequently recycled.
  3. 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 11×9s11 \times 9\text{s}11×9s (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:

  1. Writes are accumulated in-memory on an edge service.
  2. After a brief window, these events are flushed as a segment file.
  3. 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 1s1\text{s}1s at the p99p99p99 percentile.

Cloudflare Infrastructure Concept


K2 vs. Other Cloudflare Primitives

Cloudflare offers several ways to handle asynchronous data. Here is how to choose between them:

FeatureCloudflare QueuesCloudflare K2Basin Pipelines
Primary Use CaseIndividual, expensive tasksHigh-scale data movementEvent transformation to storage
ConsumptionItem-by-itemBatch-basedPipeline-driven
RetentionShort-term (until processed)Long-termVaries
Key StrengthsRetries, Delays, DLQsFan-out, Ordered LogsIceberg/R2 integration
LatencyLow produce latencyHigher produce latency (≈1s\approx 1\text{s}≈1s)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 R2 object 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:

  • cf CLI
  • Wrangler
  • 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!