Planning a Cloudflare D1 app around the 10 GB limit before a seasonal spike
Deco My Tree is a small seasonal site: you make a Christmas tree, share a link, and friends hang gifts with notes that open on December 25. Almost all of its traffic lands in December, and last season about 2 million peo
Deco My Tree is a small seasonal site: you make a Christmas tree, share a link, and friends hang gifts with notes that open on December 25. Almost all of its traffic lands in December, and last season about 2 million people visited. The backend is one Cloudflare Worker with D1, so before this season I had to answer one question: will the database fit?
The limit
A single D1 database tops out at 10 GB, and that limit can't be raised. So the plan starts with measuring what one note really costs.
Measure the real row size
The note text was the smallest part. Messages averaged about 100 characters, but once you add ids, hashes, three indexes, a log row and page slack, each note cost about 1 KB of database. The text was only around a tenth of that.
That changes the projection completely. At tens of millions of visitors and well over ten million notes, one database would pass 10 GB in the middle of December, exactly when you can't afford a migration.
Options I looked at
- One big database: simplest, but it fails at the worst possible moment.
- Durable Objects, one per tree: great isolation, but a risky rewrite mid-season and it kills the cross-tree counts I rely on for leaderboards.
- Several D1 databases: same pricing model (D1 bills rows read, rows written and storage), and the code change stays on the server.
What shipped
New accounts now get a home database, one of 32. Everything that belongs to that account's trees lives there, so the busiest queries (list my gifts, hang a gift) touch a single small database. Old accounts stay where they were, which kept the migration boring.
A few things that helped:
- Count-only tables kept by triggers, so leaderboards read one small row instead of grouping millions.
- A size check on a cron trigger that emails me as a database passes 3, 5, 7 and 9 GB.
- Keeping the change server-only, so the website and the Android app call the same API as before.
Takeaways
- Measure bytes per row with indexes included before you trust a capacity estimate.
- Split by owner when your hot queries are per owner.
- Do the boring version before the season, and the clever version after it.
If you want to see the result under load in December: https://decomytree.link
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.