Articles by Jonathan Miles

Articles by Jonathan Miles

Jonathan began his career as a C/C++ developer but has since transitioned to web development with Ruby on Rails. 3D printing is his main hobby but lately all his spare time is taken up with being a first-time dad to a rambunctious toddler.

Using ActiveRecord's #update_counters to Prevent Race Conditions

Race conditions are arguably the most insidious kind of bug; they're intermittent, subtle, and most likely to occur in production. ActiveRecord's update_counter provides us with a convenient way to avoid race conditions when incrementing or decrementing values in the database. In this article, Jonathan Miles shows us how to use it, how it's implemented, and other approaches to avoiding race conditions.

Everything You Ever Wanted To Know About View Caching In Rails

If you've ever built a UI in Rails, you've probably noticed that views tend to get slower over time. That's because adding features to a UI often means adding DB queries to the view. They add up. Fortunately, Rails provides us with an easy-to-apply band-aid in the form of view caching. In this article, Jonathan Miles introduces us to view caching, discusses when it's appropriate to use, and covers common pitfalls to watch out for.

Mastering Low Level Caching in Rails

Sometimes when your app is slow, it's not your fault. Your code might be optimized to the teeth, but it won't matter if it has to perform intrinsically slow tasks, like fetching data from an external API. In these situations, Rails' low-level caching can be a life-saver. But caching is infamously tricky. It's dangerous to go alone. In this article, Jonathan Miles guides us through the landscape of low-level caching. He covers the basics, but more importantly, digs into essential details of cache invalidation and points out common pitfalls.

Speeding up Rails with Memoization

Whoever first said that "the fastest code is no code" must have really liked memoization. After all, memoization speeds up your application by running less code. In this article, Jonathan Miles introduces us to memoization. We'll learn when to use it, how to implement it in Ruby, and how to avoid common pitfalls. Buckle up!

Rails Performance: When is Caching the Right Choice?

We've all been there. You're clicking around your Rails application, and it just isn't as snappy as it used to be. You start searching for a quick-fix and find a lot of talk about caching. Take your existing app, add some caching, and voila, a performance boost with minimal code changes. However, it's not this simple. Like most quick fixes, caching can have long-term costs. In this article, Jonathan Miles discusses what caching is and what can go wrong, as well as explains non-caching strategies you can use to speed up your Rails app.

Decoupling Ruby: Delegation vs Dependency Injection

We've all worked with tightly-coupled code. If a butterfly flaps its wings in China, the unit tests break. Maintaining a system like this is...unpleasant. In this article, Jonathan Miles dives into the origins of tight-coupling. He demonstrates how you can use dependency injection (DI) to decouple code. Then he introduces a novel decoupling technique based on delegation that can be useful when DI is not an option.