Header logo.
small hallucinations
home • years • tags • about • rss

A Few Updates on Morceau

I've been working on a reading app I'm calling Morceau for now. The name is a metaphor for reading a long piece of text in little bites, like nibbling on breadcrumbs.

For the longest time, I insisted on building the backend in Elixir because I liked its elegant syntax and how easy GenServers made it to send messages between processes. I seriously considered using Cloudflare Workers from day one, but decided against it partly because I wanted to avoid vendor lock-in. (Looking back, that was probably overthinking.)

I deployed my last product, a word game named Lexocube, on Railway. These days it barely has any daily active users, and Railway still charges me about $5 a month. Elixir apps are good at handling lots of concurrent requests (an overkill), and I assume Railway keeps the server running so it’s ready for them. (I didn’t check.) With so few players, CPU, storage, and bandwidth barely showed up on the bill. The surprise was how much I was paying for memory.

This time around, when I deployed the Morceau backend to staging, I chose Hetzner. I figured I could run the app alongside a Postgres instance for a flat fee. I didn't want to SSH into the server and type commands to configure it. That felt cumbersome. So I installed Coolify.

Coolify is a great piece of software. It lets you run projects and attach resources to them. (The GUI is a bit too complicated.) For my project, I linked a GitHub repository and attached a Postgres database. What's useful is that Coolify notifies you about the most recent dependency updates. That saved me a lot of headaches during the recent flurry of CVEs. I can imagine how painful it would be to hunt down every update and apply it by hand.

For the first week, both Coolify and my backend ran perfectly. Then one day, I noticed that four recent deployments of the backend service I managed in Coolify had failed. I could've paid more attention to error messages, but this is the staging environment for a product that's still early in development.

With Codex's help, I waded through the logs and was surprised to find that the server had run out of memory while building the Elixir binary. Following a misleading suggestion from Codex, I tried different versions of Elixir, Erlang, and one Elixir dependency. It turned out that Coolify was using 1.2 GB of the VPS's 2 GB of RAM. (The VPS is a good deal. It costs less than what I pay Railway for memory.) I tried increasing the size of the swap file, but that didn't work either. (The last time I resized a swap file, I was probably in high school.)

Then I asked myself why don't I just hosted everything on Cloudflare? It would've been much easier to deploy and configure. Since Morceau is still early in development and has only test users, I probably won't need to pay Cloudflare a dime for a long time.

The rewrite was simple enough. The TypeScript code Codex generated was easy enough to read. (I still prefer reading Elixir code.) Codex missed one small thing though. It didn't find the R2 bucket I was already using, so it created a new one without asking me. I fixed that manually.

I created a migration file that reflected the latest state of the schema of the Postgres database. I then exported the Postgres database from the VPS, converted the data to SQLite, and loaded it into the D1 database on Cloudflare. Everything is working fine now.

Ah, well, I really should start talking to potential users.

In the meantime, I shipped a few features for Morceau. Now, When Morceau ingests a webpage, it tries to extract the article's hero image. With this new feature, I crop a distinctive part of the image to use as the article's “icon” and use the image to generate three pairs of background and text colors that readers can choose from. Pretty cute, isn't it?

While looking for a way to parse webpages, I found out that the now-defunct Omnivore used a library called Readability.js. I thought the algorithm was quite clever. It uses a few heuristics to guess which elements belong to the main article. I adapted the algorithm and added domain-specific preprocessors to improve ingestion.

◆