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

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

Critter Stack AI Skills 1.18: Caught Up With CritterWatch 1.2Critter Stack AI Skills 1.18: Caught Up With CritterWatch 1.2AI Skills 1.18 brings every CritterWatch skill up to the 1.2 MCP tools, checked tool by tool against the source: a new sagas skill, the get_command_outcome tool, dead letters ranged by failure time, event queries over bodies and metadata, and six corrections to advice that had gone wrong, including the Prometheus series names every Grafana example used.CritterWatch 1.2: See Inside Your Event Store, Documents, Sagas and SchedulesCritterWatch 1.2: See Inside Your Event Store, Documents, Sagas and SchedulesCritterWatch 1.2 turns the console into a real explorer for what your Critter Stack services hold: an overview of every event store, a Step Through tab for projections, a Document Store Explorer that checks your documents still deserialize, saga instances with their state and pending timeouts, a Schedule Explorer that tells you what a schedule is actually doing, and an Event Model you can drill into.Critter Stack in Review: October 12th to 30thCritter Stack in Review: October 12th to 30thThree weeks, 72 tagged releases, and 57 pull requests from 18 people outside JasperFx. The big themes were not losing messages, with a durable inbox and outbox hardening pass that closed a dozen community-reported ways a message could go missing; performance, from SQL Server index seeks to a thread pool thread the run command was quietly eating; shutting down cleanly; an async daemon that heals itself; and multi-tenancy at a scale we'd never tested before. Plus Marten's hard stream delete, Aspire parity in Wolverine, NServiceBus XML interop, and the upgrade notes you should read first.Failure Groups: Handle a Dead Letter Incident as One ThingFailure Groups: Handle a Dead Letter Incident as One ThingCritterWatch 1.1 groups dead letters by the failure that caused them, across every service and database, and lets you replay, archive, restore or discard the whole group as one tracked operation with a reason attached. Your AI agent gets the same loop over MCP, and still has to show you the preview before it deletes anything.CritterWatch 1.1, Bobcat 1.0, AI Skills 1.17, and a First Look at StoatCritterWatch 1.1, Bobcat 1.0, AI Skills 1.17, and a First Look at StoatOne release wave, four products: CritterWatch 1.1 with 83 MCP tools, cron schedules, a Document Explorer and a long list of scalability fixes earned on real systems; Bobcat 1.0, the successor to Storyteller and our answer for spec-driven development; AI Skills 1.17; and the first public preview of Stoat.Critter Stack AI Skills 1.17: One Month of Releases, Checked Against the SourceCritter Stack AI Skills 1.17: One Month of Releases, Checked Against the SourceAI Skills 1.17 is the result of a review of everything Wolverine, Marten, CritterWatch, Bobcat and Stoat shipped in the last month, checked against the product source rather than the changelogs. Thirty-six skill changes, seven of them correcting advice that had quietly gone wrong, and the CritterWatch 1.1 paired updates that were waiting in 1.16.

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