MemDb
MemDb
HatTrick MemDb is an embedded database engine for .NET applications that need persistent, queryable storage without standing up a database server. The dataset lives in RAM; two compact log-structured files on disk make it durable across restarts. Ships as a single ~104 KB assembly targeting .NET 9 or later — no server, no schema, no external dependencies.
Why MemDb
- In-memory with file-backed persistence — reads from RAM; writes appended to disk on a configurable flush interval and on dispose.
- Native C# queries — filtering, sorting, aggregation, and query-scoped writes via a fluent query builder. No SQL.
- In-process thread safety — all operations within a process are safe without additional locking. Cross-process access is prevented by an OS-enforced lock file.
- Cached data integrity — records are deep-cloned at the cache boundary in both directions; callers cannot mutate stored data through reference aliasing.
- Record-level encryption (AES-256) — opt-in per record, transparent on read.
- Online snapshots — point-in-time backups without closing the database.
- Archive and restore — defrag-time archival enables restore to any historical timestamp.
- Simple by default, extensible when needed — minimal config to get started; custom serialization, cloning, and indexes when performance demands it.
When MemDb is a good fit
- Desktop, CLI, and embedded .NET applications that need durable structured storage
- Single-process services with datasets that fit comfortably in RAM
- Edge and IoT scenarios where shipping a database server is impractical
- Test fixtures and ephemeral caches (volatile mode requires no disk path)
- Read-heavy workloads where microsecond-scale lookup latency matters
When MemDb is not a good fit
- Datasets larger than available RAM
- Multi-process concurrent access to the same database files
- Distributed deployments or replication across nodes
- Workloads requiring SQL compatibility or external tooling
Where to find MemDb
| Resource | Location |
|---|---|
| GitHub | github.com/hattricklabs/mem-db |
| NuGet | HatTrick.MemDb |
Documentation
Install, configure, and write your first records.
Modes, persistence, flush, data integrity, and concurrency.
Insert, update, delete, find, exists, and count.
Fluent query builder with filtering, sorting, aggregates, and query-scoped writes.
Identity and applied indexes with all index operators.
Record-level AES-256-CBC encryption.
Cache purge, defragmentation, archiving, and point-in-time restore.
Online point-in-time backups without closing the database.
Custom serialization and custom cloning.
Diagnostic metrics from the database files.
Using interfaces and base classes as the record type.
Tuning recommendations for high-throughput workloads.
Write path, read path, file layout, and durability model.
Throughput, memory footprint, and on-disk format size.
Terminology used throughout MemDb.