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

ResourceLocation
GitHubgithub.com/hattricklabs/mem-db
NuGetHatTrick.MemDb

Documentation