Skip to main content

Architecture · How it works

One database per organization: keeping each space's data apart

· 3 min read

Several organizations can use the same Chudora tools. Their data must never mix: one organization must never have access to the contents of another organization's space. Here is how I organized that separation, and the safeguards that protect it.

Two ways to separate data#

A tool used by several organizations can store their data in one of two ways.

A single database for everyone. Each row carries the identifier of its organization, and every query has to filter on that identifier. This is the most common method. Its weakness: a single filter forgotten in one query, and one organization's data shows up in another's.

One database per organization. Each organization has its own database and its own file folder. A query can only read the database that was opened for it. This is the method I chose.

It has a cost: structure updates have to be applied to every database, and the right database has to be opened for every request. With SQLite, a database is a simple file, which keeps that cost low.

How it is organized#

Each tool has:

  • a shared database, which only holds what is needed to run the tool: open sessions, rate limits;
  • one database per organization, in a folder named after it, with its files alongside.

On startup, the tool opens each database and applies any missing structure updates. A new organization gets a fresh database that is already up to date.

The rule that prevents mistakes#

The main rule fits in one sentence: without an open space, no query goes through.

When a person signs in, the session records the space they opened, that is, the organization they are working in. Every function that reads from or writes to a database goes through that space. If some code tries a query without an open space, it fails with an error, instead of falling back to a default database.

This choice changes the nature of the possible mistakes. An oversight no longer leaks data: it causes an error, visible right away, during development or testing.

Files follow the same rule. They are always saved and read through a single function, which stores each file in the folder of the open space.

Who can open which space#

The portal decides which spaces each person can open, tool by tool. It writes them into the token it hands the tool at sign-in. The tool does not have to guess: it only opens a space if that space is listed in the token.

The Chudora team has one more constraint. To enter an organization's space, two conditions must be met:

  • the organization has given its support consent, which it can withdraw at any time;
  • the team member is assigned to that organization.

Each visit is recorded in the organization's log, which it can view.

The tests that check it#

This rule is checked by tests. A suite of automated tests creates two organizations, fills them with data in four tools (Agartha, Ithaque, Danimage and the portal), then tries to access one organization's data from the other. Every attempt must be refused.

The same suite checks that the team's support visits are recorded in the log, and that the backup produces a separate archive for each organization. It runs before every release.

What else this makes possible#

Separate databases also have practical advantages:

  • backups are done organization by organization, and a restore only affects one organization;
  • exporting an organization's data is simple: everything is in its folder.

How those backups are encrypted is the subject of a separate article.

Request access to the tools

Access is free, by invitation. Write through the contact form and say which tools you are interested in.