Skip navigation.

Database Abstraction Considered Harmful

Jeremy Zawodny is a MySQL database guru. I think that's great and respect his expertise, but sometimes your life experiences make you a bit too opinionated. I suffer from the same problem, so i hope that allows me to bring the same mirror to Jeremy. Recently he posted Database Abstraction Layers Must Die! In it, he argues that db abstraction just slows things down unnecessarily; and database portability is a myth anyway, because you have to optimize for each database.

Well this doesn't smell quite right. Jeremy works for a big corporation where things are standardized. It may make sense then to stick to the mysql_* calls from his perspective, but that's not for everyone. I'm sure many people, like me, work in companies that have to develop connectivity to multiple existing databases, or work in software houses where the client determines the database, so having a standard API for everyone to work with just makes things easier.

Secondly, Yahoo is a web-site where speed and scalability are always an issue. So getting as close to the metal may make sense there. But if you are developing for corporate websites with lower loads, the slight slowdown in performance is offset by the increase in flexibility that abstracting database calls give you (there is also useless abstraction, but that's another article).

And third, Jeremy's perspective is that of a database administrator, where you are concerned about tuning, indexing, etc. The developer, who is probably harassed for not finishing things sooner, just wants to download some data without any horse-shit, preferably in a simple standard way.

The irony is that in the end Jeremy advocates a standard database library for managing error-handling and other execution details. BUT IT'S OK BECAUSE IT DOESN'T HAVE THE WORD ABSTRACTION IN IT. Err, Jeremy, your fly is open.

PS: I know that Jeremy is just trying to say you should avoid "bloat". But the way he bristles at the word "abstraction" doesn't seem quite rational.

Update 1: Lambda the Ultimate debates this.

Update 2:Revjim disagrees (i like his zipper analogy). He could be right, I don't understand the difference between data access layer that (quoting Jeremy) abstracts persistent connections, replication awareness, load balancing, different error handling , and an abstraction layer that abstracts persistent connections, replication awareness, load balancing, different error handling. The truth is that most of the overhead of a well written database abstraction library is error-handling and similar data access issues, and not the difference between pg_fetch_array() and mysql_fetch_array().

Update 3 Having your cake and abstracting it. John talks about designing data access and abstraction layers.

Comment viewing options

Select your preferred way to display the comments and click 'Save settings' to activate your changes.

Can you?

yes good