Mere Code

Diverse Topics of General Interest to the Practicing Programmer

What's wrong with ORMs

I was recently reading about F1, Google’s fault-tolerant distributed RDBMS and came across this neat little summary of what’s wrong with ORMs.

  1. Obscured database operations
  2. Serial reads
  3. Implicit traversal
Obscured database operations essentially means that when scanning code, you cannot easily tell which code is going to kick off a network round-trip to the database. If you care about writing code that performs well, it’s pretty important to know.

Serial reads are what many in my circles know as ”potato programming”. When you have a loop, and something inside that loop is doing a query, that’s potato programming. Again, disastrous for performance.

Implicit traversal is doing unwanted joins and loading unnecessary data. ORMs tend to load up an object with all of its instance variables, which often means traversing the graph of references.

Anyway, this is a much handier answer to have than ‘google for ”Vietnam of Computer Science”’, which is fascinating but rather lengthy. (See also Jeff Atwood’s summary).

For bonus points, these three things are also what’s wrong with Launchpad’s API.


Jonathan Lange on 2012-11-21 10:10
For 1 for Launchpad's API, change "database" to "remote". It's really easy to accidentally do something with a launchpadlib object that makes it hit the network, giving your lucky, lucky users another roundtrip to wait on.
Aaron Bentley on 2012-11-21 04:46
I agree about 2 and 3 affecting Launchpad's API. For 1, don't all Launchpad API operations hit database? And so how is that obscure? Unless you mean Launchpadlib there.