Skip to content

Marten

Open source · Critter Stack

Marten

Document database and event store on PostgreSQL

PostgreSQL as a transactional document database and the most complete event store on .NET.

Marten turns PostgreSQL into a document database and event store with a .NET-native API. Store and query documents with LINQ, append events to streams, and build projections that keep read models current inline, asynchronously, or on demand. It has been in production since 2016 and underpins systems in finance, healthcare, logistics, and IoT.

Marten pairs naturally with Wolverine for command handling and messaging, and shares its programming model with Polecat on SQL Server and Fisher on SQLite, so code written against one store moves to another.

What Marten Gives You

Documents with LINQ

JSONB storage with a rich LINQ provider, computed and duplicated-field indexes, patching, and full-text, vector, and hybrid search.

Event sourcing

Streams with optimistic concurrency, snapshots, archiving, stream compaction, and strong-typed identifiers.

Projections

Single-stream, multi-stream, and flat-table projections, run inline with the write or by the async daemon with blue/green rebuilds.

Multi-tenancy

Conjoined tenancy in one database, database-per-tenant, or tenants added at runtime without a deployment.

Wolverine integration

The aggregate handler workflow, transactional outbox, and declarative persistence in command handlers and HTTP endpoints.

Schema management

Weasel generates and applies the schema, so a new database is one command away in development and CI.

Start Here

New to Marten? These 5 posts are the ones to read first, in order.

  1. 1Event Sourcing Quick Start with MartenLet's get up and running with event sourcing using Marten
  2. 2The Fastest Possible HTTP Queries with MartenHow to build the most efficient possible HTTP query endpoints in .NET by streaming JSON straight from PostgreSQL with Marten — using Marten.AspNetCore's WriteArray and compiled queries with zero C# allocation.
  3. 3Event Sourcing Without the Eventual Consistency Tax: Strong Consistency Options in Marten and PolecatMost event sourcing stacks make eventual consistency mandatory: events in one database, read models in another, and a subscription in between. Marten and Polecat keep events and read models in one database, which unlocks a dial no one else offers — projections snapshotted in the same transaction as the events, FetchLatest reads that are accurate even with async projections, wait-for-non-stale queries, and test automation that makes asynchronous projections actually testable.
  4. 4Every Lever Marten Gives You for Scaling a Big Event Sourcing SystemA tour of everything in Marten and Wolverine for scaling large event sourced systems: Quick Append, hot/cold event archiving, stream compacting, binary event serialization, read replicas, per-tenant partitioning, database per tenant and sharding, ancillary stores per module, projection lifecycles, strongly consistent async projections, partitioned projection data, and Wolverine-managed projection distribution.
  5. 5Rebuilding Projections Without DowntimeWolverine 6.51 adds a warm-up node role for blue/green deployments: spin up the new release's nodes with no messaging at all, let them rebuild the new versions of your Marten or Polecat projections off to the side, and only cut over once they've caught up. Here's how that fits together with Marten's versioned projections, Wolverine's capability-based agent assignment, and the new side-effect gate, and why a client with a very large system and a habit of revising projections needed all of it.

Latest on Marten

54 posts from the JasperFx blog cover Marten. Here are the most recent.

Managed Projection Distribution with the Critter StackManaged Projection Distribution with the Critter StackAsynchronous projections are stateful, so each one has to run on exactly one node, keep running when that node dies, and not pile up on one unlucky pod. Here is how Wolverine distributes Marten and Polecat projection work across a cluster, fairly by default and with database affinity for multi-tenanted systems, and what CritterWatch adds on top: visualization, operator controls, a lot more health monitoring, MCP tools, and LLM alert triage.Indexing JSON Documents in Marten and PolecatStoring documents as JSON doesn't mean giving up database indexes. A tour of the indexing options in Marten on PostgreSQL and Polecat on SQL Server: single property, multi-property, unique, partial, GIN and GiST indexes, how child collection queries use them, how both tools detect and migrate index changes, and how to read the SQL and the query plan to prove an index is being used.Tenants Taking TurnsA JasperFx client running thousands of tenants across hundreds of PostgreSQL databases was losing pods to out of memory kills during projection rebuilds. Here is how we worked through it together: partition the projection work by tenant, make the tenants take turns, and put a limit on the work in flight so one node can never load more than it can hold. Plus the other levers Marten gives you for very large systems, and how JasperFx works with clients on this kind of problem.Stoat: Memory for the Agents Working on Your CodeEvery AI agent session starts from zero. Stoat gives the agents working on your codebase a shared, event sourced memory: decisions, gotchas and conventions recorded by one session and recalled by the next, scoped to a repository, a plan or everything. Here's how it works, and the full-text and vector search in Fisher, Marten and Polecat underneath it.Clone n' Go with Stateful Resources and WeaselEvery Critter Stack tool that touches a database knows exactly what that database should look like, and can make it so. This is the basics of how that works: the AutoCreate modes, the Weasel migration engine underneath Marten, Polecat, Fisher and Wolverine, the stateful resource model that puts databases and message brokers behind one interface, and the four ways to get a schema into place from a laptop to a DBA-owned production database.Our Plan for the Critter Stack on .NET 11Our Plan for the Critter Stack on .NET 11JasperFx 3, Weasel 10, Marten 10, Polecat 6, Fisher 2, Wolverine 7 and CritterWatch 2 are all coming together on .NET 10 and .NET 11, and the headline is not the framework bump. It is the pile of opt-in defaults from the Wolverine 6.x and Marten 9.x lines that finally get to become the defaults, each with a single one-line opt-out. Here is what flips, why, what else is in the train, and how we are running the whole thing as one Stoat plan to dogfood Stoat before its 1.0.

Get help with Marten

JasperFx builds and maintains Marten. A support plan gives your team direct access to us; consulting and workshops get a project moving.

The Rest of the Stack