A database is a store for global variables
Sean Goedecke argues that database rows are effectively global variables, which clashes with the common advice to avoid globals. He tests five explanations for why databases get a pass and concludes that explicitness and disciplined usage, not anything inherent to databases, are what make them tolerable.
- Databases share the two core problems of global variables: any part of a program can read or write any record, and different parts become implicitly coupled through shared state.
- Many proposed reasons databases are better fail under scrutiny. ACID guarantees don't fix the core problem, and wrapping a global in a mutex doesn't make it acceptable.
- The two reasons he finds convincing are that database queries are explicit (they need a connection and a query call) and that teams use databases for a narrow set of purposes. Both are conventions, not inherent traits, so a codebase could apply them to globals too.
Sean Goedecke's core claim is that a database is just a store for global variables. Rows and records get called something else, but any part of a program can read or write them, which is exactly what the usual warnings against global variables object to. The two main problems with globals, in his view, are that they let code send data implicitly instead of through function signatures, and that they couple unrelated parts of a program so that one piece can break an assumption another depends on. Both apply to databases directly. He points out that bugs from code making wrong assumptions about a column's shape (string encoding, nullability) are routine in web systems, so the coupling is real in practice, not just in theory.
He then works through five possible reasons databases get a pass while global variables don't. He dismisses the idea that databases are simply better-designed in general, noting that a mutex wrapped around a global wouldn't make it acceptable under the same logic. He also rejects flexibility as the answer for typed languages, since a typed global still shouldn't be used. The ACID guarantees argument gets a skeptical hearing and little more. He finds two reasons more convincing: databases make access explicit, since queries need a connection object and a visible call, whereas a global variable is just ordinary-looking code, and teams tend to use databases only for a limited set of purposes like persistent structured data rather than loop counters or config file names. Both of these are conventions and design choices, not inherent properties, which he argues means a codebase with disciplined global-variable habits could match a database's safety.
His broader point is that two pieces of common engineering advice, avoid globals and put state in a database, are only partly consistent with each other. He treats most software design knowledge as loose heuristics and warns against engineers who invoke "best practice" without being able to give concrete reasons. The post is short, and it is more a provocation than a prescription. He explicitly says he doesn't recommend adding globals to your programs.