Honest answers about ALOS DB, its current state, sync modes, concurrency, crash protection, and how it compares to other databases.
ALOS DB is a document-oriented database written in Go. It runs as a standalone TCP server with mandatory AEGIS-128L authenticated encryption on every connection. It stores data as MessagePack-encoded documents in append-only shard files, using memory-mapped I/O for reads and a single-writer-per-shard pattern for writes. Credentials (username and password) are required, and the server will refuse to start without them.
Key design goals:
ALOS DB is not a SQL database. It does not support joins, foreign keys, or complex aggregations. If you need relational features, use PostgreSQL or SQLite.
No. ALOS DB is currently in testing and pre-release. It has not been deployed to production environments handling millions of users. The codebase is actively evolving, APIs may change, and while we perform regular testing, you should not rely on it for critical data without thorough validation in your own environment.
What has been tested:
What has not been tested at scale:
Run your own benchmarks on your hardware before making any deployment decisions. No database is magic; only your measurements matter.
Go is the only officially supported language right now. The server is a single Go binary, and the official client library is also written in Go. The wire protocol uses length-prefixed MessagePack frames over TCP, so in theory any language with TCP and MessagePack support could write a client, but none exist yet.
Planned support:
If you want to write a client in another language (Rust, C#, JavaScript, etc.), the protocol is documented in the Go source. However, there are no stability guarantees for the wire protocol yet, as it may change between pre-release versions.
ALOS DB is proprietary software. It is not open source. You may use it according to the terms provided by the author. For commercial licensing questions, contact the developer directly.
Join the community on Discord: https://alos.gg/discord
alosdbclient.SetClientLogging(true) to diagnose connection issues.ALOS DB can run in two modes, set at startup via the --sync-mode flag. This is the single most important configuration decision:
In async mode, when the client sends a regular write, the server appends it to an in-memory buffer and immediately returns success. The buffer is flushed to disk every 10 milliseconds by the group commit manager. Regular writes do not use the WAL. If the machine loses power before the next flush, at most ~10ms of buffered writes are lost. However, transaction commits are always crash-safe. They are routed through the WAL via WriteSyncBatch regardless of async/sync setting. This is significantly safer than MongoDB's default w: 1, j: false or Redis with appendfsync everysec (which can lose up to 1 second).
In sync mode, every write goes through a Write-Ahead Log (WAL) opened with FILE_FLAG_WRITE_THROUGH on Windows (or O_SYNC on Unix). Each write is durable the instant the server acknowledges it, with no separate fsync call needed. The WAL uses a Leader+Cond pattern (inspired by PostgreSQL): writers attempt to become the flusher via TryLock; non-leaders Cond.Wait until the flush completes; a fallback flusher fires every 5ms to prevent stalls. Periodic WAL truncation occurs every 50K records. Transaction commits use a coalesced transaction writer that batches multiple concurrent commits (200+ records per flush) before hitting the WAL. This achieves ~100K InsertOne docs/sec while guaranteeing zero data loss.
You cannot mix sync and async mode in the same server instance. If you need both behaviors, run two ALOS DB instances on different ports: one with --sync-mode async and one with --sync-mode sync.
No. The sync mode is set at server startup via --sync-mode and cannot be changed without restarting the server. Switching at runtime would be unsafe: inflight async writes might not be on disk yet, and suddenly demanding fsync for every operation would cause a massive latency spike.
No. "Async" means the server does not wait for fsync, but the operating system still holds the data in its page cache. On a clean shutdown (SIGTERM), the OS flushes everything. Data loss only happens on:
The group commit manager flushes every 10ms, so the actual window for data loss is ~10 milliseconds, not seconds. If your server is on a UPS with battery-backed RAID cache or enterprise NVMe (which have capacitors to flush in-flight writes), even that 10ms window is effectively zero. For financial transactions where even 10ms of potential loss is unacceptable, use sync mode.
ALOS DB uses a multi-stage write pipeline:
sync_file_range to hint the kernel to flush dirty pages, without blocking the write path.The write path is designed to be CPU-efficient: documents are serialized to MessagePack once, then written directly to the file with minimal copying.
Here are actual benchmark numbers over localhost TCP with mandatory AEGIS-128L encryption (AMD Ryzen 7 5700X, NVMe SSD, 128 workers, 16 connections):
These numbers will vary dramatically based on:
In sync mode, all writes go through the WAL with write-through I/O for crash safety. InsertOne drops from ~150K to ~100K docs/sec. Read operations are largely unaffected: FindOne is ~165K async vs ~160K sync. Transactions are crash-safe in both modes. Every committed transaction goes through the WAL via WriteDocumentsRawDurable / WriteSyncBatch regardless of async/sync setting. The coalesced transaction writer batches 200+ concurrent commits together before hitting the WAL, achieving ~140K docs/sec async and ~106K docs/sec sync.
These are single-machine, single-client numbers from testing. They are not production benchmarks. Always run your own benchmarks with your document sizes and query patterns.
ALOS DB splits data across multiple independent shards (64 or 256 per collection, configurable). Each shard owns:
.db data file.sidx, .sbloom, .svidx) with in-memory overlaysBecause each shard is isolated, there is no global lock on the database. A write to shard 42 never blocks a read from shard 7. Within a single shard:
mmap). A reader sees the data file as it existed at the moment the read began. Even if the writer appends new data, existing mmap'd pages remain valid for the reader.The only synchronization is the shard worker channel, which is a buffered Go channel. Writers send; the worker receives. No mutex, no futex, no kernel syscalls for locking.
Most databases use a reader-writer lock (like sync.RWMutex) to protect the B-tree or LSM-tree in memory. When a writer holds the lock, all readers block. Under heavy write load, readers can starve.
ALOS DB avoids this by giving each shard exactly one writer goroutine. All writes for that shard go through that goroutine's channel. Because there is only one writer, there is no need for a lock around the data structure. The writer simply appends to the log and updates the index.
Readers access the mmap'd file directly without any locks. They use the index to find offsets, then read the data. The index is an immutable sorted slice that the worker replaces atomically after a batch. Readers hold a pointer to the old index until they finish; Go's garbage collector cleans it up later.
The result: readers never block writers, and writers never block readers. Only write-write conflicts on the same document require coordination, which is handled by MVCC.
Yes. Reads are fully concurrent and lock-free. You can have hundreds of goroutines reading the same document simultaneously, and they will all see a consistent snapshot without blocking each other or the writer.
Each read gets a reference to the current index snapshot (a pointer to an immutable sorted slice). The document data is read directly from the mmap'd file. Because the file is append-only, old data is never overwritten in place. A reader holding a pointer to offset 1,204,832 will always find valid data there, even if the writer has appended megabytes of new documents after it.
ALOS DB uses Multi-Version Concurrency Control (MVCC). When a transaction begins, it captures the current database timestamp. All reads inside the transaction use that timestamp to look up the index snapshot that existed at that moment.
While the transaction is running:
If two transactions try to write the same document, the second one to commit detects the conflict (the document's version timestamp changed since the transaction began) and rolls back automatically. This is called optimistic concurrency control.
ALOS DB has backpressure mechanisms to prevent unbounded memory growth:
Under sustained load beyond hardware capacity, latency increases gracefully rather than crashing. The server logs warnings when queues exceed 80% capacity.
Sync mode provides the strongest durability guarantee. All writes go through a Write-Ahead Log (WAL) using a Leader+Cond pattern inspired by PostgreSQL:
FILE_FLAG_WRITE_THROUGH on Windows or O_SYNC on Linux, bypassing the OS page cache entirely.TryLock. If it wins, it flushes; otherwise it calls Cond.Wait until the current leader finishes. A fallback flusher fires every 5ms to prevent stalls..db file and the in-memory index is updated.The WAL is periodically truncated every 50K records. If the server crashes, unacknowledged writes were never confirmed to the client (safe to retry). Acknowledged writes are in the WAL and replayed on startup. On restart, ALOS DB replays the WAL and reconstructs the indexes from the append-only log. Any partial write at the end of the file is detected via length validation and discarded.
Additionally, sync mode computes a CRC32C checksum for every document. If a document's checksum fails on read, it is treated as corrupted and skipped during index rebuild.
Async mode recovery follows the same replay logic, but with a smaller safety window:
.db file from the beginning.The key difference from sync mode is how much data might be at the trailing edge. In async mode, the group commit manager flushes every 10ms, so the kernel might have up to ~10 milliseconds of unflushed regular writes. If power is lost, those pages evaporate. Transaction commits are unaffected because they always go through the WAL and are crash-safe regardless of mode. ALOS DB will recover to the last point the kernel actually wrote to disk, which could be at most ~10ms behind the last acknowledged regular write.
This is significantly safer than MongoDB (without journal) or Redis (with AOF but appendfsync everysec, which can lose up to 1 second). It is a deliberate performance trade-off.
Modern storage devices guarantee atomic sector writes (typically 4KB or 512 bytes). ALOS DB structures every document so that its header (length + CRC) fits within a single sector. This means:
For documents larger than the sector size, the data is written as multiple sectors, but the header is always the last sector written. This ensures that if a large document is torn, the header will either be present (document is valid) or absent (document is ignored). You cannot have a valid header with invalid data.
Yes, with --disable-crc. This removes the CRC computation and validation from the hot path. On small documents, this can improve write throughput by a small percentage.
However, you lose protection against:
Only disable CRC if you have error-correcting RAM (ECC) and you have benchmarked that CRC is actually your bottleneck. For most users, CRC overhead is negligible compared to network and disk I/O.
Yes, because ALOS DB files are append-only and never modified in place. You can safely:
cp or rsync while the server is running.tar on a live database.The copied files will be a consistent snapshot of the database at the moment the copy started. Any writes that happen during the copy will not appear in the backup. This is the same principle as PostgreSQL's pg_basebackup.
For portable backups, use the built-in Export and Import APIs, which produce a msgpack stream.
Use MongoDB if you need a mature ecosystem, full aggregation pipelines, GUI tools, or multi-document ACID across sharded clusters.
Use ALOS DB if you want a lightweight, single-binary document store with minimal memory usage and simple deployment. Be aware it is pre-release software.
PostgreSQL is a general-purpose relational database. ALOS DB is a specialized document store. They solve different problems:
Many architectures use both: PostgreSQL for relational data and ALOS DB for high-velocity event streams.
Redis and ALOS DB both prioritize speed, but for different use cases:
If your dataset fits in RAM and you can tolerate losing a few seconds of data on crash, Redis is the better cache. If your dataset is larger than RAM or you need durable document storage, ALOS DB is more appropriate.
A common pattern is Redis as the hot cache in front of ALOS DB, with ALOS DB as the durable source of truth.
SQLite is the gold standard for embedded relational databases. ALOS DB differs in several ways:
Use SQLite for mobile apps, local tools, and small embedded systems. Use ALOS DB when you need a network-accessible database with high concurrency.
ScyllaDB and Cassandra are distributed wide-column stores for multi-datacenter replication. ALOS DB is a single-node document store.
ALOS DB runs well on modest hardware, but for high throughput:
The bottleneck is usually disk I/O in sync mode, or network latency in remote deployments. CPU is rarely the bottleneck unless you are doing complex aggregations.
Several design decisions reduce overhead:
However, these optimizations are specific to ALOS DB's design. A general-purpose database like PostgreSQL or MongoDB does more work per query (query planning, secondary index maintenance, replication logs) because they support more features. Speed is a trade-off against flexibility.
The hot cache is an LRU cache of recently accessed documents, stored in deserialized form. When a read request arrives:
The cache is per-shard. Writes invalidate affected cache entries. The default size is small; tune it with --cache-mb if you have RAM to spare.
For read-heavy workloads where the same documents are accessed repeatedly, the hot cache can significantly improve read latency by avoiding disk access entirely.
Because ALOS DB is append-only, updates and deletes leave stale data behind. Over time, data files grow larger than the live data. Compaction rewrites each shard's data file, keeping only live documents.
Compaction triggers when:
--compact-stale-ratio)--compact-min-size)--compaction is enabledDuring compaction, the shard briefly locks to swap the old file for the new one. Reads continue via the old mmap'd file until the swap. Writes are buffered and applied after compaction.
Compaction runs in the background at low priority. On fast NVMe, a 1GB shard compacts in a few seconds.
Documents are sharded by hashing their _id field. The hash modulo --shards determines which shard owns the document.
You set the shard count at database creation time via --shards. Once data exists, changing the shard count requires a full rebuild (export and re-import) because every document would hash to a different shard.
Guidelines:
Each database is a directory containing subdirectories per shard:
data/
mydb/
shard_000.db # Append-only document log
shard_000.sidx # Primary index (id -> offset)
shard_000.sbloom # Bloom filter for fast membership checks
shard_000.svidx.0 # Value index segment (field:value -> offsets)
shard_000.svidx.1 # Value index segment
shard_001.db
...
.db: The append-only document store. Each document is prefixed by a 4-byte length and a 4-byte CRC32C..sidx: The sorted primary index (ID to byte offset). Rebuilt on startup from the .db file. Has in-memory overlays updated at write time; dirty shards flushed every 60 seconds..sbloom: Bloom filter for fast document membership checks. Has in-memory overlays; dirty shards flushed every 60 seconds..svidx.N: Inverted value indexes mapping hash(field:value) to byte offsets. Binary-searchable. Integrated into FilteredScan for direct offset lookup before falling back to shard scan. Has in-memory overlays; dirty shards flushed every 60 seconds.ALOS DB indexes are fully automatic and zero-config:
_id to disk offset. Built automatically from the .db file on startup.CreateIndex(field, unique). Build B-tree indexes on the fields you query. Managed with DropIndex, ListIndexes, and RebuildIndex..svidx files provide field:value lookups without manual configuration.B-tree indexes are maintained automatically on all writes after creation. Queries on indexed fields are O(log n).
In practice, ALOS DB has been tested on a simulated dataset of 16 million Discord message logs with indexes created on the queried fields. Queries across the entire dataset, including range lookups by timestamp, regex searches within message content, and filtered aggregations, consistently complete in under 15 ms.
Cluster mode enables multi-node replication. When enabled:
--cluster-port.Important limitations:
For most users, a single ALOS DB node with good backups is recommended. Use cluster mode only for experimentation or warm standbys.
TCP connections can drop for many reasons: idle timeouts, NAT evictions, server restarts, or network hiccups. The Go client has automatic reconnection:
To debug disconnections, enable client logging:
import "github.com/guno1928/alosdbclient"
func init() {
alosdbclient.SetClientLogging(true)
}
Common log patterns:
READ_LEN_FAILED err=EOF: Server closed the connection (idle timeout or restart).READ_LEN_FAILED err=i/o timeout: Network latency spike or server overload.CONNECT_FAILED: Server is down or unreachable.By default, the client creates a single TCP connection. For higher throughput, increase the pool size:
db, err := alosdbclient.Connect("localhost:6900",
alosdbclient.WithPoolSize(8),
)
The pool uses round-robin: each request cycles through available connections. This prevents head-of-line blocking where one slow request stalls others.
Each connection maintains its own TCP socket and encryption state. If one drops, only requests routed to it are affected. Dropped connections are re-established automatically on next use.
For most workloads, 4-8 connections is optimal. More than 16 rarely helps and can exhaust server file descriptors.
ALOS DB uses a PSK (Pre-Shared Key) handshake on every connection. Encryption is mandatory and cannot be disabled. Credentials (username and password) are required; the server refuses to start without them.
Every packet is encrypted with AEGIS-128L (an AEAD cipher running at 19 GB/s on AES-NI hardware) using a monotonically increasing 16-byte counter as the nonce. Replay attacks are impossible because the counter must always increase. The handshake takes ~1ms on modern CPUs. AEGIS-128L provides stronger forgery resistance than AES-GCM and is nonce-misuse resistant.