Barrel Docs

Embeddable document database with MVCC, declarative queries, real-time subscriptions, and peer-to-peer replication. Built in Erlang.

Core Capabilities

Everything you need for document storage, querying, and distributed sync.

CORE

MVCC

Multi-Version Concurrency Control with revision trees.

  • + Conflict-free writes
  • + Revision history
  • + CRDT-style merge
QUERY

Declarative Queries

Path-based queries with automatic indexing.

  • + Auto path indexing
  • + No manual indexes
  • + Federation support
SYNC

P2P Replication

Peer-to-peer sync with replication policies.

  • + Chain, Group, Fanout
  • + Filtered replication
  • + Sync writes
REALTIME

Subscriptions

Real-time notifications via MQTT-style patterns.

  • + Path patterns
  • + Query subscriptions
  • + SSE streaming

Federated Queries

Query across multiple databases and merge results

Tiered Storage

Hot/warm/cold tiers with automatic TTL migration

Attachments

Store binary data alongside documents

HLC Ordering

Hybrid Logical Clocks for distributed coordination

Prometheus Metrics

Built-in metrics for monitoring and alerting

Embeddable

Use as a library in Erlang/Elixir apps

Replication Policies

Chain

A → B → C

Sequential replication with sync writes

Group

A ↔ B ↔ C

Multi-master with conflict resolution

Fanout

A → B, C, D

Event distribution to multiple targets

Performance

<1ms

Read latency (p99)

50K/sec

Write throughput

100K QPS

Read throughput

Benchmarked on single node, 1KB documents

Use Cases

Edge Computing

Deploy nodes that sync to cloud when connected

Multi-Region

Replicate data across regions with conflict resolution

Tiered Caching

Hot/warm/cold data tiers with automatic migration

Event Distribution

Fan-out patterns for event streaming architectures

Quick Start

cURL
# Run with Docker
docker run -p 8080:8080 barrel-platform/barrel-docdb

# Create a database
curl -X POST http://localhost:8080/db/mydb

# Put a document
curl -X PUT http://localhost:8080/db/mydb/doc1 \
  -H "Content-Type: application/json" \
  -d '{"type": "user", "name": "Alice"}'

# Get a document
curl http://localhost:8080/db/mydb/doc1

# Query documents (automatic path indexing)
curl -X POST http://localhost:8080/db/mydb/_find \
  -H "Content-Type: application/json" \
  -d '{"where": [{"path": ["type"], "value": "user"}]}'

# Subscribe to changes (SSE stream)
curl http://localhost:8080/db/mydb/_changes/stream

When to Use

Use Barrel Docs when:

  • + Need document versioning
  • + Offline-first/sync required
  • + Multi-device sync needed
  • + Embedded in Erlang/Elixir app

Consider alternatives when:

  • + Simple key-value is enough
  • + Need SQL/relational queries
  • + Graph traversal required
  • + No versioning needed

Integration with Barrel Vector

Barrel Docs pairs naturally with Barrel Vector for storing document content alongside embeddings.

Python
# Store document in docdb
doc = docdb.put("documents", {
    "_id": "doc1",
    "title": "Machine Learning Basics",
    "content": "...",
    "source": "ml-book.pdf"
})

# Store embedding in vectordb
embedding = get_embedding(doc["content"])
vectordb.insert("documents", [{
    "id": "doc1",
    "values": embedding,
    "metadata": {"docdb_id": "doc1"}
}])

# Search vectors, retrieve full documents
results = vectordb.search("documents", query_embedding, top_k=5)
for r in results:
    full_doc = docdb.get("documents", r["metadata"]["docdb_id"])