Exactly-Once Publishing on Cloudflare D1 Without Transactions

https://hackernoon.imgix.net/images/79HRs4xnb5UK7XbfTI5Pz7TyOhu2-aig3b44.png

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:

  1. Every answer page is published exactly once, and the site's publication revision goes up exactly once per page.
  2. ...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more