What is a leaky abstraction?
A leaky abstraction promises to hide a detail but fails in some situations, so the user has to understand the hidden layer anyway. The simple view stops being enough.
Explain it simply
A railway app shows "Seat confirmed" and hides the network, the servers and the queue. That works until the app freezes at 10 AM when Tatkal opens. Now you must think about load and retries, the things the app was meant to hide. That is a leak.
Every abstraction leaks somewhere. The aim is to leak rarely and to document where.
Example
# A list "hides" storage, but cost leaks through.
items = list(range(100000))
def has(x):
return x in items # looks like one line, but scans up to 100000 items
lookup = set(items)
def has_fast(x):
return x in lookup # same syntax, very different costAn ORM is another classic case: user.orders looks like a field, but each access can fire a database query, so a loop over users can run hundreds of queries.
What to say in the interview
"A leaky abstraction hides a detail until some case, usually performance, failure or concurrency, forces you to know it. I use abstractions for convenience but still learn the layer beneath, and I document the limits of my own abstractions."
Common mistakes
- Thinking more abstraction is always better.