
Categories
Engineering
Earlier this month I merged a pull request with 12 lines added and 1,318,664 removed.
Most of those lines were generated migration snapshots, the copies of the database schema that get written out every time it changes. So no, I didn’t delete a million lines of logic. What it did mean is that the Creators app no longer owns its own database, which was the last piece of moving a whole platform, originally built by an agency, into Framer’s shared backend. It’s something I’ve been working on since around when I joined in February.
Where it started
The Creators app is the Next.js app behind the Framer Marketplace and community. It was first built by an agency as its own standalone platform, so it grew up separately from the rest of Framer, with its own Postgres database that it read and wrote to directly.
Once the work came in-house, more of Framer needed that same data, so Framer’s shared backend started reading and writing it too. Two codebases, one database, and either of them able to change it.
Simple, at least on the surface…
In practice, every schema change had to land in both repos in the right order, validation lived in two places and slowly drifted apart, and it wasn’t always clear which side was the source of truth.
One piece at a time
I didn’t want a big-bang rewrite. The Marketplace is in use all day, every day, and the team still had features to ship. So instead I moved one area at a time, and every move followed the same steps (if you read my background job post, this will sound familiar):
the backend gets an endpoint for that area and publishes its types as a small package, so the app and backend can’t quietly disagree
the app switches its reads over to the backend, while writes still go to the database
once the reads have been healthy for a while, the writes move over too
the old queries and duplicated checks get deleted
Each step is its own small pull request. If one goes wrong, you only have to revert that one small change.
I started with the smaller areas, like settings and the current creator’s session, then moved on to accounts, the admin tools for plugins and templates, categories, image metadata, affiliates and links. Share links, which used to go through a third-party link shortener, are now created by the backend itself.
A handful of these landed over the summer, then it really picked up in the autumn, with around twenty in October alone.
The in-between
The period in the middle was the trickiest, when some areas read from the backend and others still went straight to the database, and the app had to behave the same either way.
Errors were a good example of this. A failed database query and a backend that briefly can’t be reached look very different, so the app had to learn to tell a backend outage apart from a genuine auth failure, pass the backend’s error messages through properly, and stop reporting expected rate limits as errors.
The schema went last
Until the very end, both repos could still run schema migrations, so I stuck to a few simple rules: one schema change per branch, always start on the app side, and make sure both repos agree on the latest state of the database before anything ships.
Once nothing in the app talked to the database directly anymore, it no longer needed its own migrations. I handed ownership over to the backend and deleted the app’s copy, snapshots and all. Hence the diff.
What changed
If you use the Marketplace, you won’t have noticed any of this, and that is intentional.
Now there is one place that owns the data and its rules, and it’s the same backend the rest of Framer runs on. A schema change is now one pull request in one repo, and the app is a lot simpler to work on.
Huge thanks to everyone who worked on this with me!
