# A database is a store for global variables

DevFeed: [A database is a store for global variables](<https://devfeed.tech/articles/a-database-is-a-store-for-global-variables-121312.md>)

Original publisher: [Read original article](<https://seangoedecke.com/a-database-is-a-store-for-global-variables/>)

Published: 2026-11-06T00:00:00Z

Content type: opinion

Language: en

Sources: [Sean Goedecke](<https://devfeed.tech/sources/seangoedecke-com-rss-feed.md>)

Topics: [Database](<https://devfeed.tech/topics/database.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>)

Tags: [advice](<https://devfeed.tech/tags/advice.md>), [apps](<https://devfeed.tech/tags/apps.md>), [bugs](<https://devfeed.tech/tags/bugs.md>), [code](<https://devfeed.tech/tags/code.md>), [column](<https://devfeed.tech/tags/column.md>), [data](<https://devfeed.tech/tags/data.md>), [database](<https://devfeed.tech/tags/database.md>), [databases](<https://devfeed.tech/tags/databases.md>), [function](<https://devfeed.tech/tags/function.md>), [global](<https://devfeed.tech/tags/global.md>), [program](<https://devfeed.tech/tags/program.md>), [programming](<https://devfeed.tech/tags/programming.md>), [query](<https://devfeed.tech/tags/query.md>), [records](<https://devfeed.tech/tags/records.md>), [software](<https://devfeed.tech/tags/software.md>), [state](<https://devfeed.tech/tags/state.md>), [store](<https://devfeed.tech/tags/store.md>), [systems](<https://devfeed.tech/tags/systems.md>), [value](<https://devfeed.tech/tags/value.md>), [variables](<https://devfeed.tech/tags/variables.md>)

## AI overview

The excerpt argues that databases behave like global variables: any program component can query or change shared state, creating implicit data flow and coupling. It considers five explanations for why database-backed programs can still be better structured: they may simply be messier; ACID guarantees may reduce harm; database access is more explicit; databases store less flexible values; and established conventions limit their use. The author is unconvinced by ACID guarantees and flexibility as the main explanations, and favors explicit query points and norms such as checking column types and reserving databases for suitable uses. These advantages are contingent on how a codebase uses its tools, so the author treats both "avoid globals" and "use a database for state" as heuristics that need concrete reasons.

## Source excerpt

Databases are for storing global variables. We usually call them "rows" or "records" instead, but they're definitionally global variables: any part of your program can read or write them. Isn't this kind of weird? It's common programming advice that global variables are bad, and yet many elegant programs rely on databases. Either the common advice is wrong, or there's something special about databases that makes them the exception to the rule. What's so bad about global variables? Here's the two main1 reasons, in my view: They allow any part of your program to implicitly send data to any other part instead of passing it around via function signatures They couple different parts of your program: if one part depends on a variable having some value, any other part can break it Both of these apply to databases. Any part of your program that makes a query can send and receive data from any other part of your program. In practice this happens all the time: one function will save some data on a record, and another one will check for it. And if you haven't seen bugs where some piece of code makes some incorrect expectation about the shape2 of a database column, you haven't been working on web systems for long enough. So why aren't database-backed apps in terrible architectural shape? In the rest of this post I'll consider some options. First, we could bite the bullet: maybe all database-backed apps really are a mess. This is surprisingly plausible. When I think about the systems I've worked on that haven't involved a database, they're usually much cleaner and more elegant. If managing state is the hardest thing about designing software -- and I think it is -- then systems that manage less state are going to be better-designed. However, this doesn't explain everything. Database-backed apps aren't that bad, and even in database-backed apps, we try to avoid introducing regular global variables3, so in practice we treat global variables as worse. Second, we could say that databas