Why this blog is a single Rust binary

Axum, Askama and SQLx in one process, Git as the CMS, PostgreSQL as a rebuildable index. The reasoning behind onhlt's architecture.

1 min read

Building onhlt · part 1 of 2

Cet article existe en français

Most personal blogs are either a static site generator or a full CMS. onhlt is neither: it is one Rust binary that serves server-rendered pages, syncs Markdown from Git and keeps a snapshot of my GitHub activity. This post explains why.

What a blog actually needs#

A blog is a reading product. The first byte must contain the whole article, the page must work without JavaScript, and nothing slow should sit between a reader and the text.

That rules out a few things straight away:

  • Client-side rendering. A WASM or SPA bundle adds work before the first paragraph is readable.
  • Calling GitHub at request time. Rate limits and latency would leak into every page view.
  • A database as the source of truth. Text belongs in Git, where it is versioned, reviewable and diffable.

The shape of the system#

Reader to Caddy to the onhlt binary, which talks to PostgreSQL. GitHub sends webhooks and is polled in the background.
One process serves pages, syncs content and refreshes GitHub data.

The binary has three jobs, each a Tokio task:

  1. Serve HTTP with Axum. Pages are rendered by Askama templates that are compiled and type-checked with the rest of the code.
  2. Sync content. A signed GitHub webhook triggers a git fetch, the Markdown is parsed, and the whole index is replaced in a single PostgreSQL transaction.
  3. Refresh GitHub data every 30 minutes and store it, so pages only ever read a snapshot.

Why Axum, Askama and SQLx#

crates/onhlt-web/src/routes/article.rsrust
pub async fn article(
    State(app): State<AppState>,
    ctx: Ctx,
    Path(slug): Path<String>,
) -> Result<Html<String>, AppError> {
    let post = app.db.post(ctx.lang, &slug).await?.ok_or(AppError::NotFound)?;
    render(&ArticlePage::new(&ctx, post))
}
  • Axum sits on Tower, so tracing, timeouts and compression are ordinary middleware.
  • Askama catches a typo in a template at cargo check time, not in production.
  • SQLx keeps the SQL visible. Full-text search, jsonb and CTEs are first-class instead of fighting an ORM.

Written by

Software, backend and DevOps engineer. I write Rust, run Kubernetes and measure everything with OpenTelemetry.

↑↓ navigate ↵ open Esc close