Designing a publishing workflow with D1 and R2
A failed upload should never leave readers looking at half a release. Give each revision an immutable body and make publication a single database decision.
Model the release
Consider a publisher with a homepage and ten Markdown stories. An editor corrects one story while another editor previews a redesign. If both operations overwrite a file called latest.md, the preview can change beneath the reviewer. Give every saved body an immutable object key in R2. In D1, keep a revision record that identifies its project, parent revision and object key. D1 supplies the relational catalogue. R2 holds the article bodies and artwork.
Switch the pointer
Write the objects first and verify they can be read. Then change the published revision using a conditional update that matches both project ID and the previously published revision. Check the affected row count. A zero means another editor has published in the meantime. Present that conflict for review. A failed object upload leaves the previous release visible. A failed database update may leave an unused object, which a later cleanup can reclaim once references have been checked.
Prove that rollback works
Build the homepage and article links from the same revision manifest. Include its identifier in cache keys for immutable content and give the public entry point an explicit freshness policy. In staging, interrupt a release just after its final upload. Open a story from the public homepage, then from the draft preview. Each should resolve within its own revision. Finally, restore the previous published pointer and measure how long readers take to see it. That measurement tells you what rollback actually means to your users.