Spencer AlgerBlog

:branch: Every branch is a durable object

In our internal development platform we fetch diffs for in-progress changes from Github in order to show users as they work. Github's API is notoriously flaky, slow, and rate-limited, so we can't fetch this diff on every page load, we instead cache it in an object store and only refresh the cache when we identify that new commits have been pushed.

The system that we use to store these diffs is "session" based, which worked pretty well for a while, but we have started to expand and now want to show diffs for PRs that don't relate to sessions. I've tried to migrate our diff storage to our PR durable objects several times, but keep getting close and then getting caught up on the same problem: a PR is created at some point in the life cycle but not immediately.

You know what is created as soon as there are changes? A BRANCH! It took me embarrassingly long to realize that we could just create a new durable object to represent each branch, store the current state of the branch as soon as it exists, then broadcast changes to the branch out to interested consumers. Done after a couple prompts and so easy to reason about.