Skip to content
sirixdbPublic

About

SirixDB is an an embeddable, bitemporal, append-only database system and event store, storing immutable lightweight snapshots. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1.2k stars

Watchers

28 watching

Forks

Latest commit

 

History

5,388 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

SirixDB

SirixDB - The Bitemporal Database System

Query current and historical revisions directly

CI Build Status Maven Central PRs Welcome All Contributors

🟢 Live Demo · Why SirixDB · Docs · Website · Discord · Forum

Status: 1.0.0-beta — usable today and actively developed. The on-disk format and public APIs are stabilizing toward a 1.0 release; feedback from real use is exactly what we're looking for.


The Problem

You update a row in your database. The old value is gone.

To get history, you bolt on audit tables, change-data-capture, or event sourcing. Now you have two systems: one for current state, one for history. Querying the past means replaying events or scanning logs. Your "simple" audit requirement just became an infrastructure project.

Git solves this for files—but you can't query a Git repository. Event sourcing preserves history—but reconstructing past state means replaying from the beginning.

The Solution

SirixDB is a database where every revision is a first-class citizen. Not an afterthought. Not a log you replay.

// Open the first committed revision
session.beginNodeReadOnlyTrx(1)

// Query by timestamp - which revision was current at 3am last Tuesday?
session.beginNodeReadOnlyTrx(Instant.parse("2024-01-15T03:00:00Z"))

// Both open readable snapshots of committed revisions

This works because SirixDB uses structural sharing with sub-page versioning. Unchanged pages are shared between revisions via copy-on-write — and versioning continues below the page: under the default sliding-snapshot strategy, a commit writes page fragments containing the changed records and the few that must be carried forward to keep reads bounded, and any page is reconstructible from at most N fragments. Above the fragments, a commit rewrites the copy-on-write path up to the new revision root. Block-level COW (ZFS-style) copies a whole page when one byte in it changes; delta-based systems make reads replay ever-growing diff chains. SirixDB pays neither cost. Revision 1000 doesn't store 1000 copies—it stores the current state plus pointers to shared history.

The result:

  • Storage under the default sliding-snapshot strategy grows with changed and carried-forward records and the height of the rewritten path, never with the size of the data
  • Read any page from any revision: O(N) page fragment reads, where N is the configurable snapshot window (default 3)
  • No event replay, no log scanning—direct page access

Bitemporal: Two Kinds of Time

Most databases (if they version at all) track one timeline: when data was written. SirixDB tracks two:

  • Transaction time: When was this committed? (system-managed)
  • Valid time: When was this true in the real world? (user-managed)

Why does this matter?

January 15: You record "Price = $100, valid from January 1"
January 20: You discover the price was actually $95 on January 1

After correction, you can ask:
  "What did we THINK the price was on Jan 16?"  →  $100 (transaction time)
  "What WAS the price on Jan 1?"                →  $95  (valid time)

Both questions have correct, different answers. Without bitemporal support, the correction destroys the audit trail.

Core Properties

  • Append-only storage: Data is never overwritten. New revisions write to new locations.
  • Structural sharing: Unchanged pages and nodes are referenced between revisions via copy-on-write.
  • Snapshot isolation: Readers see a consistent view; one writer per resource.
  • Embeddable: a Java library with dependencies managed by Maven or Gradle; the REST server is also available as a fat JAR and Docker image.

Performance

Historical reads follow persisted page references rather than replaying an event log. Actual latency depends on the query, cache state, storage and versioning strategy.

See BENCHMARKS.md for workload-specific measurements and methodology. The PostgreSQL comparison is explicitly withdrawn as unsound; its throughput, storage and diff ratios are not performance claims. The DuckDB comparison describes its analytical workloads and limitations. Measure your own workload before choosing a deployment configuration.

How Versioning Works

Logical page structure of a resource with 3 revisions
Logical page structure of a resource with 3 revisions — read-only transactions (RTX) can open any revision, while a single write transaction (WTX) appends to the latest.

SirixDB stores data in a persistent tree structure where revisions share unchanged pages and nodes. Traditional databases overwrite data in place and use write-ahead logs for recovery. SirixDB takes a different approach:

Physical Storage: Append-Only Log

All data is written sequentially to an append-only log. Nothing is ever overwritten.

Physical Log (append-only, sequential writes)
┌────────────────────────────────────────────────────────────────────────┐
│ [R1:Root] [R1:P1] [R1:P2] [R2:Root] [R2:P1'] [R3:Root] [R3:P2'] ...    │
└────────────────────────────────────────────────────────────────────────┘
     t=0      t=1     t=2      t=3      t=4       t=5       t=6    → time

Logical Structure: Persistent Trie

Each revision has a root node in a trie. Unchanged pages are shared via references.

  [Rev 1]           [Rev 2]         [Rev 3]
     │                 │               │
     ▼                 ▼               ▼
  [Root₁]           [Root₂]         [Root₃]
   │   │             │   │           │   │
   │   └──────────┐  │   └────────┐  │   └─────────┐
   ▼              ▼  ▼            ▼  ▼             ▼
┌──────┐        ┌──────┐        ┌──────┐        ┌──────┐
│  P1  │        │  P2  │        │ P1'  │        │ P2'  │
└──────┘        └──────┘        └──────┘        └──────┘
 Rev 1          Rev 1+2         Rev 2+3          Rev 3
                (shared)        (shared)

Rev 2 modified only P1 (writing P1') and still shares P2 with Rev 1; Rev 3 modified only P2 (writing P2') and still shares P1' with Rev 2 — matching the physical log above.

Page Versioning Strategies

How page versions are stored is configurable per resource:

Strategy Page fragments per read Write cost Notes
FULL 1 full page per change fastest reads, largest storage
INCREMENTAL up to N−1 diffs small diffs + periodic full snapshot write spikes at snapshot points
DIFFERENTIAL 2 diffs grow between snapshots bounded reads, uneven writes
SLIDING_SNAPSHOT (default) ≤ N (default 3) small diffs, out-of-window records rescued into the newest fragment no full-snapshot spikes, best balance

With the default sliding-snapshot strategy, writes use the page fragments and copy-on-write paths described above; unchanged pages are referenced from the new revision, and the old revision remains intact and queryable. Read cost: opening a revision is O(1) by number, O(log R) by timestamp; each page read combines at most N fragments. The full strategy walkthrough is in docs/ARCHITECTURE.md.

Quick Start

Platform support: Linux (x86-64 and arm64), macOS, and Windows are CI-tested on every pull request. Linux x86-64 additionally gets native binaries and the Docker images; known limitations are listed in docs/KNOWN_LIMITATIONS.md.

Using Docker and the REST API

Requires Docker and curl, on Linux x86-64. Start a local development server in one command:

docker run --rm --name sirix-first-run -p 127.0.0.1:9443:9443 -e SIRIX_AUTH_MODE=none sirixdb/sirix@sha256:76cb3ec3f8c1efa2d62b526962ff5fed1f7b3f7436bb34db4685abc7320ad33a

Leave that terminal open. This pins the image rather than relying on a changing latest tag. Authentication is disabled and every request has administrator access; the port is bound to loopback for local development. The data lives inside this disposable container and is removed when it exits. For persistent storage and OAuth2, see docs/operations.md and docker-compose.yml.

In a second terminal, wait for readiness, write a JSON document, and read revision 1:

# Retry for up to two minutes; stop here if readiness fails.
curl --fail --silent --show-error --retry 60 --retry-connrefused --retry-delay 2 --retry-max-time 120 http://localhost:9443/health
# Expected: {"status":"UP"}

curl --fail-with-body -X PUT http://localhost:9443/first-run/message \
  -H 'Content-Type: application/json' -d '{"message":"hello"}'

curl --fail-with-body 'http://localhost:9443/first-run/message?revision=1'
# The returned document contains "message":"hello".

Stop it with docker stop sirix-first-run in the second terminal. For queries, updates, time-travel reads and diffs, continue with docs/QUICKSTART.md. The OpenAPI specification defines the endpoint contract. The agent quickstart also covers reversible JVM, REST and JSONiq edits.

Using the CLI (Native Binaries)

SirixDB provides two CLI tools, both available as instant-startup native binaries:

Binary Module Description
sirix-cli sirix-kotlin-cli Full-featured CLI for database operations
sirix-shell sirix-query Interactive JSONiq/XQuery shell

Build native binaries with the GraalVM toolchain documented here:

# Build both CLIs as native binaries
./gradlew :sirix-kotlin-cli:nativeCompile  # produces: sirix-cli
./gradlew :sirix-query:nativeCompile -Pnative.mainClass=io.sirix.query.Main -Pnative.imageName=sirix-shell

# Or run via JAR
./gradlew :sirix-kotlin-cli:run --args="-l /tmp/mydb create"

The whole create/update/time-travel loop from the shell (-l names the database path):

sirix-cli -l /tmp/mydb create json -r myresource -d '{"name": "Alice", "role": "admin"}'
sirix-cli -l /tmp/mydb update -r myresource '{"team": "engineering"}' -im as-first-child
sirix-cli -l /tmp/mydb query  -r myresource '$$.name'   # $$ is the document root
sirix-cli -l /tmp/mydb query  -r myresource -rev 1      # query a previous revision
sirix-cli -l /tmp/mydb resource-history myresource

sirix-shell is a JSONiq/XQuery REPL over the same data (jn:store(...), jn:doc(...) — multi-line queries, an empty line executes accumulated input, Control-D or Control-C exits). An empty submission keeps the session open. A runtime query failure reports an error, discards that query's pending updates and returns to the prompt. Its terminal presentation adds syntax highlighting, formatted results and a revision indicator. See the shell presentation reference for colour controls, error reporting, plain-output compatibility and the supported revision/diff inference forms.

Run a query script with sirix-shell -iqf queries.xq, or pipe it into sirix-shell -iqf -. Empty lines and lines containing only spaces or tabs separate queries; repeated separators are skipped, and the final query needs no trailing separator. LF and CRLF line endings are accepted and joined with LF within each query, preserving indentation; other characters remain query content. Queries run in order in one session without prompts. A failed query uses the same failure boundary as the REPL, and later queries still run. The shell returns status 0 if all queries succeed and -1 if any fails. An unreadable script reports I/O Error and returns -1.

JSONiq array access uses zero-based positions. Negative positions count from the end of each containing array: jn:doc('mydb','myresource').numbers[-1].v reads the last element's v field. A position below minus the array length raises FORG0006, including negative access on an empty array; a nonnegative position at or beyond the length returns an empty sequence. Indexed queries follow the same rules, including consecutive accesses such as .root.numbers[-2][-1].

XML imports from constructed nodes preserve element and attribute namespace URIs and local namespace declarations:

xn:store('names', (), <root>
  <item xmlns='urn:a'>a</item>
  <item xmlns='urn:b'>b</item>
  <p:item xmlns:p='urn:a'>alias</p:item>
  <item>plain</item>
</root>)

xn:store($coll, $res, $nodes) and the sibling jn:store, jn:load and xn:load functions add a resource: they create a database only when it is missing, never drop an existing one, and never replace a resource in place. A single input uses $res, including singleton sorted or lazy sequences. A free resource name is added beside existing resources. A name that is already taken raises SIRIXDBF0006 and writes nothing. Every other resource keeps its content, revisions and indexes.

To put unrelated content under a name that is taken, use jn:replace-resource($coll, $res, $fragment) / xn:replace-resource(...), or jn:replace-resource-from / xn:replace-resource-from for a file or URI source. A replacement starts a fresh history: the old revisions are discarded and the new content becomes revision 1. It needs the CREATE, MODIFY and DELETE roles and is refused while another session holds the resource. Atomic publication and crash recovery follow TXN-405. Use jn:import/xn:import below instead to update a resource while preserving its history, and jn:drop-resource/xn:drop-resource to remove one. The full contract is in the store, load, replace and drop specification.

The $create-new flag these functions used to take as a fourth argument is gone in 1.0: a call that still passes it fails with a message naming the replace and drop functions. The fourth argument is now the options object for JSON, or the commit message for XML (with the commit timestamp fifth). See the migration table.

Several inputs use new automatic resourceN names regardless of $res. Automatic naming skips names already in use, including names claimed by concurrent callers. With $res = (), xn:store uses resource1 for a single node in a new database and resource in an existing database, so storing a second unnamed single node into the same database is refused until that resource is dropped; xn:load uses automatic names in either case.

For embedded Java/CLI queries, xn:load reads XML documents from URI strings, including a sequence of URIs. For example, xn:load('names', (), ('file:///tmp/first.xml', 'file:///tmp/second.xml')) adds documents to an existing collection, or creates it if absent. Loads acquire every source before preparing targets or writing, so an unavailable source leaves existing content and revisions unchanged. A later parsing or write failure can leave earlier imports committed; a load is not a transaction across resources.

jn:import($database, $resource, $new-version) is the JSON counterpart of xn:import: it compares a full new document against the latest stored revision with FMSE, applies the tree edit, and commits exactly one new revision. Unchanged nodes retain their node keys, and earlier revisions remain available. The database and resource must already exist. JSON accepts serialized content or a JSON item; a stored JSON string item retains its string value rather than being parsed as serialized content. XML accepts serialized XML content. Both return the imported document.

jn:import('versions', 'orders', '{"orders":[{"id":1,"status":"shipped"}]}')
jn:import('versions', 'orders', {"orders":[{"id":1,"status":"delivered"}]})