Exactly-Once Publishing on Cloudflare D1 Without Transactions
I run a small daily game, Costcodle, where everyone guesses the price of the same Costco item each day. Just after midnight UTC, a scheduled job publishes the answer page of every puzzle that has finished. It is a tiny job, and for a while it was the part of the system I trusted least.
The published answer page for Costcodle puzzle #1121: the product photo, the game price of $8.99 and the winning range of $8.55 to $9.43.
The reason was a migration. I was merging two Cloudflare Workers, one for the website and one for scheduled jobs, into a single Worker. Until the old one was deleted, both would fire the same cron string at the same moment, against the same database. I wanted three guarantees to survive that overlap:
- Every answer page is published exactly once, and the site's publication revision goes up exactly once per page.
- ...
Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE