liveBook · Manning

Leaky abstraction

As explained in Grokking Software Architecture

A leaky abstraction is an abstraction whose underlying implementation details or limitations remain observable to its users.

An abstraction can hide complexity, but it cannot erase the system underneath. An ORM may let you write queries without SQL; database limits and query costs still show through. section 8.3.2

Watch for leaks when ORM behavior meets database constraints:

  • A broad lookup can fetch every column. If each user row includes a 5MB profile image, fetching 100 users can use 500MB. Project only the fields you need. section 8.3.2
  • A custom C# function may not translate to SQL. Older ORMs could fetch the whole table and filter in memory; EF Core 3+ throws an exception instead. Rewrite the query in translatable logic, or fetch only necessary data before calculating in memory. section 8.3.2
Figure 8.7 The N+1 Problem: Fetching data in a loop is like making a separate trip to the kitchen for every single french fry. Always fetch in batches!

The N+1 analogy makes the cost of fetching data in a loop tangible: batch requests instead of making a separate trip for each item. section 8.3.2

How Grokking Software Architecture covers it

How deep it goes
Works through projection and client-side evaluation failures, but does not detail ORM internals.
Examples
Uses a 5MB profile image, a custom age-calculation query, and fetching data in a loop.
What you can do after
Diagnose ORM query failures and reduce unnecessary data fetching with projections, translatable logic, or explicit in-memory calculation.
How it connects
Connects leaky abstractions to ORMs, SQL, client-side evaluation, and the N+1 problem.

Also explained in

Compare how 4 books explain leaky abstraction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.