Skip to main content

Database Internals

Stalwart uses a modular storage architecture based on subspaces. Subspaces are logical partitions of the database, each responsible for storing a specific category of data. This approach allows the system to efficiently organize, access, and maintain information across a wide variety of backend databases.

Each subspace in Stalwart is represented by a single ASCII alphabetic character. These subspaces are integral to the internal design of the system and define how different types of information are separated within the underlying database.

Backend Mapping

The way subspaces are represented and stored depends on the type of data store backend used:

  • When Stalwart is configured to use an SQL database such as PostgreSQL, MySQL, or SQLite, each subspace is mapped to a separate SQL table. This ensures that different categories of data are logically and physically isolated, improving performance and maintainability.
  • For setups using FoundationDB, subspaces are represented by the first byte of the key. This allows for efficient key-space partitioning and lookup operations.
  • In RocksDB, subspaces are implemented as distinct column families, allowing different data types to be stored with optimized compaction and caching strategies.

Subspace Structure

The following table provides a detailed description of each subspace used in Stalwart. Each entry includes the subspace letter and the type of data it is intended to store:

SubspaceDescription
aAccess Control Lists (ACL): Stores permissions and access rules governing resource access.
bDocument Ids: Holds a list of assigned document ids for each collection.
cTags: Contains tags such message flags.
vText index: Maps tokens to document ids.
dDirectory: Stores the internal directory using for authentication.
fTask Queue: Keeps a list of scheduled or pending tasks awaiting background processing.
iIndexes: Contains general-purpose indexes used throughout various modules in the system.
jBlob Reserve: Reserved blobs that haven't been committed yet
kBlob Links: Links blob ids to document ids.
tBlobs: Used to store binary large objects, such as attachments and file content.
lLogs: Contains the system't changelog used for incremental caching and the IMAP CONDSTORE extension.
nCounters: Persistent numerical counters used to track metrics or system state.
mIn-Memory Values: Temporarily stores volatile key-value pairs kept in memory.
yIn-Memory Counters: In-memory numeric counters with ephemeral lifespan.
pProperties: Used to store properties or metadata for different entities.
sSettings: Stores system configuration and operational settings.
eQueue Messages: Holds individual messages that are part of mail or event queues.
qQueue Events: Captures events and changes occurring within queues.
uQuota: Tracks usage limits and enforces resource quotas.
hOutgoing Reports: Stores generated reports such as pending outgoing DMARC or TLS reports
rIncoming Reports: Contains data received from external reports or analytics.
gFull-Text Search Index (FTS): Maintains indexes used for efficient text-based search capabilities.
oTelemetry Span: Records spans used for distributed tracing and observability.
wTelemetry Index: Stores indexed entries for quick access to telemetry data.
xTelemetry Metrics: Captures raw metric data collected for system performance monitoring.