New Blog!

Published: Jan 2, 2024

I've been wanting to revive my blog for a while now, I've had a desire to write some things about NeoVim in particular. Of course, I decided to write it myself instead of using something like Medium. For me, it's an opportunity to learn something new, in this case, several new things.

The stack I chose is:

  1. Go - The fact that I chose Go is a bit odd, especially since I thought I didn't like it (I tried it for a hackathon once and I didn't "get" it at the time). I figured I was probably wrong, several developers I know and respect were loving it. Also projects like Charm looked really ingriquing. It has a good track record for a backend. I'm happy to report that I was indeed wrong. Go is pretty cool!
  2. Templ - Another strange choice; it looks like JSX and that's another technology I shied away from, I just didn't like the way it looked. Again, willing to admit I'm wrong. Templ just looked neat and I thought it would probably work well with the third technology I chose (it does).
  3. HTMX - It's all the rage isn't it? This is the one I was most excited to try. For a primarily backend developer like me, it's a dream come true. Now I don't have to write my types in Go, use those types to serialize to JSON, fetch via JS, and deserialize into another type written there. I can use the same backend model and HTML can be the View.
  4. Tailwind - Anything to make CSS less annoying.

Like I said, I've wanted to bring back my blog for a while. I've considered a bunch of technologies like Svelte, Vue, NestJS, etc, but one idea that I wanted was to be able to write the articles in Markdown and have them convert automatically to HTML. This way I can store the articles directly in the git repository and edit them with the GitHub markdown editor. This also backs my articles up and keeps revisions of them automatically.

I considered having it read the articles from the filesystem at boot, and then populating a database (I still might do this eventually), but then I thought: what's so bad about just reading them into memory and serving them from there? I could still keep the comments in a database if I add that feature later. It's super fast (I'm getting ~40k req/s with 100 concurrent users using Cassowary). But, what if I have a lot of articles in there? The server has to load them up, convert all the markdown to HTML, and then just hold them in memory.

I did some experiments by creating a bunch of Lorem Ipsum markdown articles and seeing how Go (and my code) handled processing them.

I started with 10,000 6KB articles, and the app handled it just fine. I tried pushing it to 20,000 and then 30,000 articles.

At 30,000 articles (which would give me enough leeway to write 2 articles every single day for the next 80 years), the app took about 9 seconds to read every article from the filesystem, convert the markdown to html, and store them in memory. The process took about 890MB, which is a lot, to be sure, but I am ok with it because the memory will remain fairly constant, and lookups will be very fast (and, let's be honest, I'm not writing 30,000 articles, it took me over 5 years to write 90).


Filed Under: