I wanted one copy of my Kafka data, in object storage, that I could query two ways: live SQL from an app, and Iceberg from a laptop with DuckDB.
KafScale 2.2.0 is a Kafka-compatible broker that writes every record to object storage. I pointed a cluster at Cloudflare R2, produced 3000 orders, and force-deleted one broker while the producer was still running. The producer finished at 3000 acked. A consume came back with 3000 distinct keys. A Cloudflare Worker, sitting in front of the SQL processor running as a Container, also counted 3000. DuckDB, reading Iceberg tables in R2's catalog, counted 3000 as well. Nothing was lost or duplicated. kcat and a Java consumer agreed on the same path.
That is the idea. The records live in R2. The Worker is SQL for apps. Iceberg is for analytics. Nobody copies the data into a second store.
I work on KafScale, so this is a walkthrough from the person who ships it, not a review. The long form of the cluster and Iceberg setup is How to run KafScale on Cloudflare R2. This post is the path I ran: cluster, Worker, Iceberg, the broker kill, and the two queries.
The same build, narrated:
What you will build
- A KafScale 2.2.0 cluster that keeps every record in an R2 bucket.
- The SQL processor, pushed as a container image and run as a Cloudflare Container, with a Worker in front of it that answers a few fixed HTTP routes.
- The Iceberg processor, writing the same topics into R2 Data Catalog (now called Basin Catalog), which you query with DuckDB and a catalog token only.
A Worker cannot speak the Kafka protocol, so it cannot consume from the KafScale proxy. It reads the segments in R2, the same way the Iceberg processor does.
Before you start
- A Cloudflare account with R2 turned on. R2 asks for a payment method even for the free tier.
- The Workers Paid plan, which Cloudflare Containers need. That plan is $5 a month.
- A Kubernetes cluster with Helm 3, and
kubectlaccess. I ran this on a local cluster. - Docker, to build the SQL processor image.
- Node.js, so you can run
npx wrangler. - kcat or the Kafka CLI, and DuckDB if you want to run the queries yourself.
- KafScale 2.2.0. Clone the tag when you install:
git clone --branch v2.2.0 --depth 1 https://github.com/KafScale/platform.git kafscale Secrets come only from files only you can read, never from the command line, never from helm --set, and never from this post. Use a mode-600 R2 env file for the access key, secret key, endpoint and bucket, and a mode-600 file for the Cloudflare API token. Load them with:
set -a; . ./r2.env; set +a Do the same when you need the token file. Replace <ACCOUNT_ID>, the bucket name and the keys with your own.
1. Create an R2 bucket and an API token
In the Cloudflare dashboard, open R2 Object Storage and create a bucket, for example kafscale-data. Leave the storage class on Standard: the free tier does not apply to Infrequent Access.
Create an R2 API token with Object Read & Write, scoped to that bucket. Note the Access Key ID, the Secret Access Key, and the S3 endpoint https://<ACCOUNT_ID>.r2.cloudflarestorage.com. Cloudflare shows the secret only once.
KafScale only needs object access to this bucket. Brokers check that the bucket exists at startup and never need to create it.
2. Store the R2 keys in a Kubernetes Secret
kubectl create namespace kafscale umask 077 cat > r2.env <<'ENV' AWS_ACCESS_KEY_ID=<access key id> AWS_SECRET_ACCESS_KEY=<secret access key> ENV kubectl -n kafscale create secret generic kafscale-s3 --from-env-file=r2.env Keep that file mode 600, and also store R2_ENDPOINT and R2_BUCKET in it or in a sibling file, so you can load them later. The Kubernetes Secret only needs the two AWS_* keys. Don't commit the file, and don't put the values on a command line.
3. Install KafScale and point the cluster at R2
Save this as values-r2.yaml. An empty etcdEndpoints lets the operator run etcd for you:
operator: etcdEndpoints: [""] etcdReplicas: 3 proxy: enabled: true replicaCount: 2 etcdEndpoints: - http://kafscale-etcd-client.kafscale.svc.cluster.local:2379 advertisedHost: kafka.example.com advertisedPort: 9092 helm upgrade --install kafscale kafscale/deploy/helm/kafscale \ -n kafscale -f values-r2.yaml The chart's appVersion is v2.2.0, so the operator, brokers, proxies and the Iceberg processor in step 7 run the ghcr.io/kafscale/kafscale-*:v2.2.0 images.
Then create the cluster. Save this as cluster-r2.yaml:
apiVersion: kafscale.io/v1 kind: KafscaleCluster metadata: name: kafscale namespace: kafscale spec: brokers: replicas: 2 s3: bucket: kafscale-data region: auto endpoint: https://<ACCOUNT_ID>.r2.cloudflarestorage.com credentialsSecretRef: kafscale-s3 etcd: endpoints: [] Leave spec.s3.kmsKeyArn unset. R2 encrypts objects at rest itself, and AWS KMS is not a thing here. Path-style addressing is turned on for you whenever endpoint is set.
kubectl apply -f cluster-r2.yaml kubectl -n kafscale get kafscalecluster kafscale \ -o jsonpath='{range .status.conditions[*]}{.type}={.status} {.reason}{"\n"}{end}' When the brokers are up you should see S3Credentials=True and Ready=True. A broker only starts listening after its conditional write check against R2 succeeds (If-None-Match: *; the second write must get 412).
By default, etcd snapshots also go to this bucket, under _kafscale/etcd-snapshots/. R2 does not implement bucket versioning or a public access block, so protectBucket has no effect. The howto has the snapshot check if you want to run one.
4. Produce a few records and look at the bucket
This is a small paste you can run yourself. The 3000-record run is in the next step, and in the video.
export BOOTSTRAP=kafka.example.com:9092 kafka-topics.sh --bootstrap-server $BOOTSTRAP --create --topic orders --partitions 4 --replication-factor 1 cat > orders.jsonl <<'EOF' 1:{"order_id":1,"status":"paid","amount":19.99,"region":"eu"} 2:{"order_id":2,"status":"paid","amount":5.50,"region":"us"} 3:{"order_id":3,"status":"shipped","amount":42.00,"region":"eu"} 4:{"order_id":4,"status":"paid","amount":12.25,"region":"apac"} 5:{"order_id":5,"status":"cancelled","amount":7.00,"region":"us"} 6:{"order_id":6,"status":"shipped","amount":30.10,"region":"eu"} EOF kcat -b $BOOTSTRAP -P -t orders -K: -X acks=all < orders.jsonl kcat -b $BOOTSTRAP -C -t orders -o beginning -e -q -f '%k:%s\n' The consumer reads partition by partition, so the order will differ from the file. You should get all six JSON objects back.
The segments show up in R2 under <namespace>/<topic>/<partition>/:
aws s3 ls s3://kafscale-data/kafscale/orders/ --recursive \ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com Each flush writes one .kfs segment and its .index. That is the copy everything else will read.
If you use the Kafka console producer against a new topic on R2, its default request.timeout.ms of 1500 can log REQUEST_TIMED_OUT on the first produce. It retries and stores the records exactly once. kcat is the simpler path here.
5. Kill a broker mid-run
This is the run in the video. I produced 3000 JSON orders, idempotent, acks=all, and force-deleted one of the two brokers while the producer was still going. The producer finished at 3000 acked. A consume came back with 3000 records and 3000 distinct keys. Lost: 0. Duplicated: 0.
kcat producing and a Java consumer (kafka-clients 3.9.1) reading through the proxy also saw 3000, 0 lost, 0 duplicated.
The two query paths below were aimed at that topic, named liveorders, with the same JSON shape as the six records above: order_id, status, amount, region.
6. Run the SQL processor as a Cloudflare Container
From the v2.2.0 checkout, build the SQL processor image in addons/processors/sql-processor and tag it kafscale-demo-sql:v2.2.0.
Start a Worker project from the Cloudflare containers template. Remove container_src/ and the template Dockerfile, so you push the KAFSQL image instead of building a different one.
npx wrangler containers push kafscale-demo-sql:v2.2.0 Pin the digest it prints in wrangler.jsonc as registry.cloudflare.com/<ACCOUNT_ID>/kafscale-demo-sql@sha256:<DIGEST>. Bind a Durable Object named KafsqlContainer. The container is started as instance standard-1 (1/2 vCPU, 4 GiB memory, 8 GB disk), with KAFSQL_METADATA_DISCOVERY=s3 and password auth on.
Write a secrets file from the env files, not from the shell history, with R2_ENDPOINT, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and KAFSQL_PASSWORD. Deploy with:
npx wrangler deploy --secrets-file <secrets-file> The first request after a deploy starts the container and can take a few seconds.
curl -s "$WORKER_URL/" curl -s "$WORKER_URL/counts" curl -s "$WORKER_URL/count/liveorders" curl -s "$WORKER_URL/partitions/liveorders" GET / lists those routes. The Worker runs fixed queries only. It does not run SQL from the URL.
On the 3000-record liveorders topic, a count through the Worker took about 5.6 s and returned 3000. Repeats on small topics took 0.5 to 1.2 s.
7. Write the same topics to Iceberg in the R2 catalog
Turn on the catalog for the bucket and note the warehouse and catalog URI it prints:
npx wrangler basin catalog enable kafscale-data The warehouse is <ACCOUNT_ID>_kafscale-data and the URI is https://catalog.cloudflarestorage.com/<ACCOUNT_ID>/kafscale-data.
Create a separate R2 API token with Admin Read & Write for the processor only, and put its token value in its own Secret. Anyone holding that token can create tables and commit, so brokers and readers never get it.
umask 077 read -rs -p "Catalog token: " TOKEN; echo printf '%s' "$TOKEN" > r2-catalog-token unset TOKEN kubectl -n kafscale create secret generic r2-catalog --from-file=token=r2-catalog-token rm r2-catalog-token Save this as iceberg-r2.yaml. manages_locations: true is required on R2. The processor then creates tables without a location, and R2 places the files under __r2_data_catalog/. Do not put a lifecycle or lock rule on that prefix.
replicaCount: 2 s3: credentialsSecretRef: kafscale-s3 catalogToken: secretName: r2-catalog secretKey: token config: s3: bucket: kafscale-data namespace: kafscale endpoint: https://<ACCOUNT_ID>.r2.cloudflarestorage.com region: auto iceberg: catalog: type: rest uri: https://catalog.cloudflarestorage.com/<ACCOUNT_ID>/kafscale-data manages_locations: true warehouse: <ACCOUNT_ID>_kafscale-data etcd: endpoints: - http://kafscale-etcd-client.kafscale.svc.cluster.local:2379 mappings: - topic: orders table: kafscale.orders mode: append create_table_if_missing: true schema: columns: - {name: order_id, type: long, required: true} - {name: status, type: string} - {name: amount, type: double} - {name: region, type: string} If you are following the 3000-record topic, use the same mapping with topic: liveorders and table: kafscale.liveorders.
One warning if you show a required column like order_id: if a record is not JSON, or is missing that field, the Iceberg processor currently writes 0 into the column instead of rejecting the row (issue #492). The demo records all had order_id set, and DuckDB showed 3000 distinct ids from 1 to 3000. Keep values that are not JSON, or that miss a required column, out of a mapped topic.
helm upgrade --install iceberg-processor \ kafscale/addons/processors/iceberg-processor/deploy/helm/iceberg-processor \ -n kafscale -f iceberg-r2.yaml The s3.credentialsSecretRef is the bucket key from step 2, used to read segments. For the table files, the catalog hands out its own credentials, so the processor needs no other keys. Leave iceberg.catalog.token empty so the token stays out of the ConfigMap.
When two replicas commit to the same table at once, R2 answers with HTTP 409. The processor reloads the table and retries. Every row carries a record_id of <topic>:<partition>:<offset>.
On the 3000-record run, Iceberg reached 3000 rows and 3000 distinct order ids 1 minute 43 seconds after the last ack.
8. Query the table with DuckDB
Use a read-only catalog token (Admin Read only) in R2_CATALOG_TOKEN. DuckDB needs no S3 keys.
INSTALL iceberg; LOAD iceberg; CREATE SECRET r2 (TYPE iceberg, TOKEN getenv('R2_CATALOG_TOKEN')); ATTACH '<ACCOUNT_ID>_kafscale-data' AS lake (TYPE iceberg, URI 'https://catalog.cloudflarestorage.com/<ACCOUNT_ID>/kafscale-data', SECRET r2); SELECT status, count(*) AS orders, round(sum(amount), 2) AS total FROM lake.kafscale.orders GROUP BY ALL; If you produced the six orders records in step 4, you should see:
┌───────────┬────────┬────────┐ │ status │ orders │ total │ │ varchar │ int64 │ double │ ├───────────┼────────┼────────┤ │ paid │ 3 │ 37.74 │ │ cancelled │ 1 │ 7.0 │ │ shipped │ 2 │ 72.1 │ └───────────┴────────┴────────┘ On the 3000-record liveorders run, the same kind of query saw 3000 rows and 3000 distinct order ids. That is the same 3000 the Worker counted, from the same objects in the bucket.
Cost
The only cost worth quoting is the Workers Paid plan, $5 a month. R2 stayed inside the free tier, and there was no usage bill on top of that.
From Cloudflare's R2 pricing: 10 GB-month of storage, 1 million Class A operations and 10 million Class B operations free each month, and no egress fees for any storage class. Above that, Standard storage is $0.015 per GB-month, Class A is $4.50 per million and Class B is $0.36 per million. DeleteObject is free. A short 3000-record run is a tiny amount of storage.
One thing to watch if you leave a producer running: every flush writes a segment and an index, so 2 Class A operations per partition per flush. With sync flush, a producer that sends one request per second to one partition makes about 5.2 million writes a month, which is over the free 1 million. Batch on the producer, or use fewer, busier partitions.
Clean up
Tear down only the demo Worker kafscale-demo-sql, its container application, and its registry image. Do not delete other Workers on the account. On this account, wrangler delete and wrangler containers delete did not tear down cleanly, so those three resources were removed through the Cloudflare API, and only names that start with kafscale-demo-sql.
Deleting a KafScale topic does not delete its data in R2. That is documented, not a bug. If you want the objects gone, remove the topic prefixes yourself, or use kafscale-cli prune as described in the howto. If you added Iceberg, drop the tables you created in the catalog rather than pointing a lifecycle rule at __r2_data_catalog/.
Where to go next
- The full cluster, snapshot, token and Iceberg notes: How to run KafScale on Cloudflare R2
- The code: github.com/KafScale/platform
- The 2.2.0 release: v2.2.0

