Never write a database, even if you want to, even if you think you should
twitter.com
twitter.com
So when talk "Never write a database" is coming? ;)
Charity Majors @mipsytipsy
That's it. That's the talk.
"Never write a database. Even if you want to, even if you think you should. Resist. Never write a database. Unless you have to write a database. But you don't."
I will present this talk at any conference of your choosing.
There is simply too much to master, it’s a very good skill to be able to say “this is fascinating but too far afield of what I need to do”.
Alternately, choosing when to say “after dipping my toe in the water this clicks for me, I’m going to take a risk and go further” is an even harder skill to master.
This is why many people have trouble finishing a PhD dissertation. Play is a necessary step, but play without focus is a ticket to mediocrity.
Databases in particular are something one will run across in nearly any task and 99:100 times one likely shouldn’t dwell too much on what is inside the magic box.
That said, it's a hard job to do right and there are now databases of every different size made by people who are just much better than me.
Sometimes, naivety is a good helper when it comes to learning - too much knowledge of the task ahead can be demotivating. No one was born a professional developer either, and only by encountering and considering problems as they occur can one truly understand why certain decisions were made in the past and stuck around. Also, many great projects started as hobby projects. And not all projects have to become fully functional, or correct, or ready for production.
The same is true of some other areas, like durable storage systems, filesystems, and compute isolation/virtualization systems. In all these cases going from zero to "undergrad quality demo" is doable in a couple days. Going from demo to running something in production is vastly harder and more expensive and requires a completely different mind set. Building the "undergrad quality demo" is a great exercise I'd recommend to anybody curious about these areas. The road to production, however, is a tougher one.
Source: I build and maintain databases for a living at AWS. One of my previous side projects (https://www.usenix.org/conference/nsdi20/presentation/brooke...) turned out to be bigger than expected and has a whole team dedicated to it. That one (Physalia) is even quite far from being a general database (for example it doesn't support SQL or cross-shard transactions).
The original statement does not include any caveat or constraint, and is an absolute statement that does not depend on specifics. The statement is not "Never write a custom database as a subproject of any other project". The original statement is "Never write a database." Like in any conceivable scenario, including a project whose main goal is to write a database.
I also feel that this sort of clickbait advice contrasts heavily with the history of SQLite.
Also, you're reacting to an incomplete quote. The tweet is:
> "Never write a database. Even if you want to, even if you think you should. Resist. Never write a database. Unless you have to write a database. But you don't."
There are precisely two cases where you "have to write a database":
1. when you want to learn how databases are architected, and educational material on the ground is wholly inadequate (which it is!); and
2. when you discover, under a production workload, that no existing DBMS sits in exactly the right part of DBMS configuration-space to meet your scaling needs — and nor can any existing DBMS even be modified to reach that point in DBMS configuration-space — and nor can you modify the design of your application to scale in a different way; such that the only possible way to address your scaling challenges is to write an entirely novel DBMS with an entirely novel architecture.
I can only think of two times #2 has happened in recent memory: Amazon with Dynamo (the core of S3 and DynamoDB); and Google with Dremel (the core of BigQuery.) Both projects have resulted in many research papers, and later copycat DBMSes (Dynamo → Cassandra, Riak, BigTable, etc; Dremel → Redshift, Snowflake, etc.) If you don't think your DB architecture is novel enough to result in that kind of response, then it's probably not something that requires "writing a database" — it's probably instead something you can do as a hack on top of some existing database. (Think: the way Citus/Timescale/Greenplum build on Postgres.)
The quote you quoted says you don't need to write a database, so if you want to agree, you also have to agree that Amazon and Google didn't need to write databases.
And learning would seem to be covered by the "want to" or "should"
However, every once in a while, even after everyone resists for months/years, it will turn out that the company really does need to write a database, and so — still mostly against their will — the individuals employed there will set out to write a database. (And once they've "written a database", and it turned out to actually be the best course of action for the company, then the advice no longer applies — because they're no longer considering "writing a database" at that point, but rather maintaining an existing database, that they happened to be the creators of.)
> And learning would seem to be covered by the "want to" or "should"
Instrumental vs. terminal goals. If I want to do X, then I need to do Y to achieve X. If I want to learn how databases work, then I need to write a database, because there's no other good way.
And you accuse me of pedantry? This then comes under need then?!?
>Amazon and Google aren't people
No, but the people within them make decisions, ie decisions to write a database. So the 'you' would be directed at the person in the organisation who decided to write the database.
...no? I was saying that my own response is pedantry, rather than being an argument that tries to address the spirit of your argument.
> This then comes under need then?!?
Yes. The definition of "need" is "something that some higher-level goal cannot be achieved without." Ultimately, at the terminal level, everything is a preference; you want to continue living, companies want to not go bankrupt, etc. Everything required to achieve those terminal preferences, are needs. You need to eat if you want to live. A company needs to make money if it wants to avoid bankruptcy. Etc.
> No, but the people within them make decisions, ie decisions to write a database. So the 'you' would be directed at the person in the organisation who decided to write the database.
In a bigcorp, ultimately, a manager or business analyst decided that someone else should write them a database. Nobody decided to, themselves, write a database.
I wrote a blog post about this: https://jacobgw.com/blog/observation/2023/07/08/shoot-yourse...
The First Rule of Program Optimization: Don't do it.
The Second Rule of Program Optimization (for experts only!): Don't do it yet.
It is because I know what a database actually does for me, and because I've had to write parts of that for myself, that I deeply understand why I don't want to write one. And why I want to push those problems to a database if I can.Of course you should ignore my advice if you're named Jeff Dean. Look through https://research.google/people/jeff/. Among his other projects, look at BigTable, LevelDB and Spanner. All are databases, implemented for good reasons.
You should write a database system if you want to, for learning, fun, to try out a lot of different approaches, and see how and why things are solved in other DBMS systems.
You can even try using it on small fun projects.
Dont ever think of putting into production on something important. It will come back and haunt you in the most undesirable ways.
Projects like pgrx (postgres extensions in rust) are starting to make it much more approachable to do so.
A little lower level: build on FoundationDB. (Projects like mvsqlite are super interesting here).
In both cases, we don't yet have fully managed providers. RDS seems to be flirting with opening up the extension ecosystem with trusted languages. I haven't seen any managed foundationdb offerings though.
I think what she means here is “nobody ELSE should write a database,” because they certainly found it necessary and beneficial to do so.
(In all seriousness, usually you shouldn’t write a database. But somebody has to, you know? There’s no need to gate-keep like that.)
If I ever would find myself walking into building-my-own-database-territory, I would probably first try to reach for FoundationDB and see if that could work.
I've just played around with it, but it seems like a great tool for building high performant and robust distributed databases on top of.
But: almost ever should you say never.
What better way to learn indexing tradeoffs than to write your own database?
What existed before Redis?
What existed before LevelDB?
What existed before Git?
Sure, write a database if you want. But be humble about the effort involved and reliability you’ll get.
It was as true then as it was today: very few people should write databases for production.
> I would consider SQLite, itself 20+ years old now, the intellectual heir of BDB.
Indeed. I've worked on projects that only use the btree part of SQLite. If all you need is a btree it's a good place to start.
My questions were rhetorical, BTW: emphasizing that progress happens when what exists now doesn't stop someone from making something different and maybe better.
We're probably not disagreeing. To summarize:
- practically, given real-world constraints and risk tolerances, yes, very few people should write databases for production. (Except villains. They should expend tremendous energy and effort writing bespoke artisanal databases, resulting in less time to be evil.)
- educationally, there is a lot to be gained by writing your own, even if only a small part [1], such as something around indexing, a write-ahead-log, a query planner, or even a query parser [2]
- if everyone thought e.g. 'writing a new database isn't worth it', collectively we'd be in a worse place
FWIW, I have a soft place in my heart for all the great projects that come out of Berkeley.
Note 1: Let me propose a game for a group of people. One person names some narrow aspect of a database, perhaps in the hopes that it is boring, trivial, or "solved". (Perhaps "autoincrementing indexes" for example.) Then the other people to talk about all the ways that the thing is actually quite hard, interesting, non-obvious, and maybe (?) even a good research area.
Note 2: It is nice that SQL is declarative. AND there is room for improvement, starting with composability. See https://news.ycombinator.com/item?id=24730713
They have a lot of really simple, good ideas that can make your life a lot easier. Attempting to work on data intensive applications without stealing ideas from databases can make your life much harder.
Having said that, I learned a lot from it. So I wouldn’t say don’t do it. You’ll probably learn from it. Just don’t expect to make the next MongoDB or MySQL :)
Are we not really integrators of prior art, for the most part?