Preventing Race Conditions With Fencing Tokens in Rails

I recently ran across a concurrency problem that required the use of fencing tokens. The technique I ended up using for generating these tokens is a bit of an off-label use for ActiveRecord, so I thought it might be useful for anyone in a similar situation. Concurrent Workers Cause a Race Condition The issue I […]

Never Schedule Future Jobs

There are many situations in which you might be tempted to schedule a job in the future. Maybe you want to want to follow up with a user a few days after they purchased something to see how they’re liking it. Maybe you want to record some summary metrics a week after a new user […]

Recovering from “Fat Model, Skinny Controller”

Like many programmers, I’ve had a long, tortured journey through the world of software design as I did what worked in the moment and only later discovered the consequences of my decisions. I was especially “lucky” in this respect as my first professional software job was as the sole architect of what became two 20k+ […]

Refactoring the Rails Model

It feels like the Rails Model violates the Single Responsibility Principle right out of the box. Wouldn’t this be an easier way to write a non-trivial Rails application? # lib/ # models/ # item/ # creator.rb # query.rb # record.rb # validator.rb module Item class Creator < ActiveRecord::Creator def call! super ElasticSearch.item_created!(item) # … other […]