Skip to content

Introduce Database Layer

  • Deciders: David Bauer, Julian Bäume
  • Date: 2025-03-11

Status

Accepted

Context

As we want to extend threads with meta information, we somehow need to store those. The most obvious way to do this is to introduce a database layer. There are multiple systems that could be used for this, that need to be evaluated.

NoSQL Databases

NoSQL databases are a good choice for storing unstructured data, which is basically what we have in our case. Options in this area are MongoDB, CouchDB or similar systems.

Relational Databases

Relational databases are a good choice for structured data. While our data is not really structured, we could still use a relational database. In this area we discussed MariaDB and PostgreSQL. We also thought about SQLite at least for running automated tests and development environments.

So if we decide to go with a relational database, it's quite clear that we would need some kind of abstraction layer (ORM) to make the interaction with the database easier. In JavaScript, there is Drizzle ORM which is a good choice for this. It has minimal overhead on top of SQL, which is good for performance but still abstracts away many of the complexities of SQL.

Decision

While a NoSQL database would have some advantages and would be a good fit for our use-case, we decided to go with a relational database. Our customers are used to deploy and operate such systems and going the NoSQL route would introduce a lot of complexity for them.

As PostgreSQL offers a lot of features that are very close to NoSQL databases, we decided to go with it as a good compromise between the two worlds. It's easy to run locally and there are a lot of options to operate it at scale in production environments (e.g. with CloudNativePG).

Consequences

We understand that this means we are introducing a new technology to the App Suite stack. It also means that operators have to maintain two different types of databases. We still think it's worth the effort, as PostgreSQL is a very powerful system and more suited to our needs than a MariaDB would be. Handling "unstructured" JSON data is simpler with JSONB columns that support efficient indexing (GIN indexes) for fast queries on nested data. The notify feature (LISTEN/NOTIFY) enables real-time updates from the database. Additionally, PostgreSQL's extension ecosystem provides capabilities like pgvector for AI/ML use cases (vector embeddings, semantic search) that we plan to leverage in the future.

As we settled for Drizzle ORM, we could as well provide an abstraction layer and also implement support for MariaDB if there's actually a demand for it. For now, we just assume that we will be the main consumers and operators of this, so PostgreSQL is a good fit. If we later want to hand this over to other operators, they hopefully will be equally happy in providing an instance of it than they are with MariaDB.