The Active Record pattern — where objects map one-to-one to database rows and are accessed by primary key — causes severe performance problems in real applications. Retrieving whole objects when only partial data is needed leads to N+1 query explosions, excessive serialization overhead, and algorithmic complexity that degrades as datasets grow. The pattern also encourages non-transactional writes, creating 'lost update' bugs. The recommended alternative is using first-class queries (querybuilders or SQL) and explicit transactions. The same structural flaw appears in RESTful APIs, where whole-resource access and HATEOAS-style link traversal cause latency and bandwidth problems — GraphQL and RPC-style APIs are presented as better alternatives.

11m read timeFrom calpaterson.com
Post cover image
Table of contents
The Active Record pattern, describedProblems ariseThe available mitigations don't work well in practiceThe viable alternative: first class queriesAlso necessary: first class transactionsThe analogous problem with RESTful APIsMy recommendationsContact/etcSee also

Sort: