archive / 2023

Boring technology is a feature

A client wanted an internal dashboard 'done properly': React, an API, a build pipeline. I built it with server-side templates and htmx. A case for boring.

This spring a client asked me to build an internal dashboard. Twelve users, all planners in a warehouse. A few tables, some filters, a button to mark a shipment as “done” and a form to add comments. The kind of application that got built in an afternoon in PHP in 2010 and then lasted ten years.

Internal IT already had a proposal ready: a React frontend, a separate REST API in Go, an OpenAPI spec, a state management library, a two-stage build pipeline and a separate container for the frontend. Two repos. For twelve people.

I carefully asked whether I could try something different.

What I built#

One Go service. html/template for the pages. PostgreSQL. And htmx for the bit of interactivity that was needed. No frontend build step, no node_modules, no JSON API that only exists to be consumed by a single client.

Marking a shipment as done looks like this:

<script src="https://unpkg.com/[email protected]"></script>

<tr id="shipment-4711">
  <td>4711</td>
  <td>Ghent → Lyon</td>
  <td>
    <button hx-post="/shipments/4711/done"
            hx-target="#shipment-4711"
            hx-swap="outerHTML">
      Done
    </button>
  </td>
</tr>

And the server just sends back the new row, as HTML:

func (s *Server) markDone(w http.ResponseWriter, r *http.Request) {
	id, err := strconv.Atoi(chi.URLParam(r, "id"))
	if err != nil {
		http.Error(w, "invalid id", http.StatusBadRequest)
		return
	}
	sh, err := s.store.MarkDone(r.Context(), id)
	if err != nil {
		http.Error(w, "could not update shipment", http.StatusInternalServerError)
		return
	}
	s.render(w, "shipment_row.html", sh)
}

That’s it. The template for that row is also used to render the full table, so there’s exactly one place where the HTML of a shipment is defined. Filters are a form with hx-get and hx-trigger="change". The comment form is a regular form with hx-post. With JavaScript turned off, most of it still works, because underneath it’s just links and forms.

Three weeks later it was in production. The entire frontend “stack” is one script tag.

What I’m not claiming#

I’m not claiming React is bad. I worked with it for years, and for an application with lots of client-side state, offline behaviour or complex interactions (an editor, a planning tool with drag-and-drop across fifty columns) I’d pick it again without hesitation.

I’m also not claiming htmx is the future. Maybe it’s forgotten in five years. Honestly, I don’t care much, because the core of what I built is server-rendered HTML, and that will still be around in five years.

What I am claiming: the default choice should be the boring one, and you should be able to explain why you’re deviating from it. Not the other way around.

Why boring wins#

There’s an old, well-known essay by Dan McKinley, “Choose Boring Technology”, that I reread every couple of years. The idea is simple: every company only has a limited number of “innovation tokens” to spend. Every new, unfamiliar technology costs one. Spend them on the things that make your product unique, not on your dashboard for twelve planners.

My own version, after thirteen years in this job:

  • Boring means the failure modes are known. If PostgreSQL does something weird, someone already asked about it on Stack Overflow in 2014.
  • Boring means someone else can take it over. I’m a freelancer. I’ll be gone within a year. The team that has to maintain this knows Go and SQL. They shouldn’t need to learn a frontend framework to add a column.
  • Boring means fewer moving parts. Every layer you add is a layer that can break, that needs updates, and that can get a security advisory on a Friday afternoon.
  • Boring isn’t the same as old. htmx is fairly new. But the idea behind it (the server sends HTML, the browser shows it) is as old as the web itself.

How the client reacted#

Internal IT was sceptical at first. “Does that scale?” For twelve users, yes. For twelve thousand too, probably, because it’s just a Go server sending back HTML.

The planners themselves didn’t notice a thing. They think it’s fast. One of them asked if it was “a new technology”. I said it was actually a very old technology. He looked at me like I was making a joke.

That reaction is the best summary I can give: if nobody notices which technology you used, you probably picked the right one.

    Tip: / opens search, ↑↓ to select, ↵ to open.