# Exactly-Once Publishing on Cloudflare D1 Without Transactions

DevFeed: [Exactly-Once Publishing on Cloudflare D1 Without Transactions](<https://devfeed.tech/articles/exactly-once-publishing-on-cloudflare-d1-without-transactions-119321.md>)

Original publisher: [Read original article](<https://hackernoon.com/exactly-once-publishing-on-cloudflare-d1-without-transactions?source=rss>)

Author: horushe

Published: 2026-11-05T15:44:50Z

Content type: article

Language: en

Sources: [HackerNoon](<https://devfeed.tech/sources/hackernoon.md>)

Topics: [database-consistency](<https://devfeed.tech/topics/database-consistency.md>), [Transactions](<https://devfeed.tech/topics/transactions.md>), [race-condition](<https://devfeed.tech/topics/race-condition.md>), [cache-invalidation](<https://devfeed.tech/topics/cache-invalidation.md>), [Cloudflare](<https://devfeed.tech/topics/cloudflare.md>), [Cloudflare Workers](<https://devfeed.tech/topics/cloudflare-workers.md>), [Cache](<https://devfeed.tech/topics/cache.md>), [cache-control](<https://devfeed.tech/topics/cache-control.md>)

Tags: [atomic](<https://devfeed.tech/tags/atomic.md>), [batches](<https://devfeed.tech/tags/batches.md>), [cache](<https://devfeed.tech/tags/cache.md>), [cache-invalidation](<https://devfeed.tech/tags/cache-invalidation.md>), [cloudflare](<https://devfeed.tech/tags/cloudflare.md>), [cloudflare-d1](<https://devfeed.tech/tags/cloudflare-d1.md>), [cloudflare-workers](<https://devfeed.tech/tags/cloudflare-workers.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [concurrent](<https://devfeed.tech/tags/concurrent.md>), [condition](<https://devfeed.tech/tags/condition.md>), [content](<https://devfeed.tech/tags/content.md>), [d1](<https://devfeed.tech/tags/d1.md>), [distributed-locks](<https://devfeed.tech/tags/distributed-locks.md>), [distributed-systems](<https://devfeed.tech/tags/distributed-systems.md>), [exactly-once](<https://devfeed.tech/tags/exactly-once.md>), [exactly-once-processing](<https://devfeed.tech/tags/exactly-once-processing.md>), [fencing](<https://devfeed.tech/tags/fencing.md>), [fencing-tokens](<https://devfeed.tech/tags/fencing-tokens.md>), [learn-how-to](<https://devfeed.tech/tags/learn-how-to.md>), [publishing](<https://devfeed.tech/tags/publishing.md>), [race-conditions](<https://devfeed.tech/tags/race-conditions.md>), [revision](<https://devfeed.tech/tags/revision.md>), [software-architecture](<https://devfeed.tech/tags/software-architecture.md>), [sql](<https://devfeed.tech/tags/sql.md>), [transactions](<https://devfeed.tech/tags/transactions.md>)

## AI overview

The article's D1 publishing design combines expiring leases with fencing tokens and SQL guards inside every write. The final batch inserts the page only if lease and content checks still hold, then uses a random commit token to conditionally update the publication ledger and revision; a stale writer therefore makes no partial changes. Cache invalidation uses a global publication revision in cache keys instead of purges, with short lifetimes capped at scheduled visibility changes such as a post-midnight grace window. The tradeoff is one primary database read per cacheable request. A separate single-statement SQLite insert enforces unique sessions, dense slots and a 50,000-row puzzle limit. The article reports concurrent integration runs on Worker, D1 and R2 that published six pages once each and stored seven images once each.

## Source excerpt

Learn how to prevent duplicate writes in Cloudflare D1 using fencing tokens, guarded SQL batches, and revision-based cache invalidation.