Hyperledger Fabric with CouchDB as the state database

A practical plan for running CouchDB as the Fabric peer state database: when it earns its extra process, how to configure and secure it, and how to keep channels consistent.

On this page

Hyperledger Fabric with CouchDB as the state database: when to use it and how it connects

If your permissioned network team needs rich queries or auditing over ledger state that LevelDB cannot serve, you need to decide whether to run CouchDB beside each peer. CouchDB runs as a separate database process alongside the peer, and it is the option for reporting and auditing needs that LevelDB does not meet. The peer's built-in CouchDB state database setting is the supported way to select it, so the decision is made in peer configuration rather than in application code.

The choice is made per peer, but it is not a free choice per peer. Each peer that joins a channel stores its state in either CouchDB or LevelDB, and the Fabric deployment guide advises against mixing the two on one channel, because CouchDB imposes restrictions on keys and values that LevelDB does not. Before you commit, confirm with your channel members which database each organization will run, and agree on that as part of the channel design rather than discovering a mismatch after chaincode is deployed. Ask your chaincode team which key and value shapes they depend on, since those are the first things CouchDB restricts.

Each CouchDB instance is operated as its own process with its own storage, memory, backup and upgrade cycle, so the extra cost is an operational one that recurs for every peer. Plan for that footprint before you approve the design, and confirm the CouchDB version your Fabric release supports in the Fabric CouchDB documentation. If the reporting need can be met by exporting data from a LevelDB peer to a separate analytics store, that may be the simpler path. Make the comparison explicit in your design record.

What a CouchDB-backed peer needs before you start

A CouchDB-backed peer is two processes that must be sized, secured and recovered together. The cards below cover the release line, the CouchDB version, the hosting layout, and the channel-wide decisions to settle before the first peer starts.

Pick the Fabric release line

Decide whether the network targets the v2.5 LTS line or the v3.x line before choosing CouchDB. The Fabric docs name v2.5 as the long-term support release for production users, and the 3.x and 2.5 lines both receive patch releases in parallel. Record the exact patch version you will deploy, because the CouchDB guidance you follow should match that release, not the latest docs page.

Fabric what's new

Confirm the CouchDB version

Do not assume a CouchDB version is supported. Check the current CouchDB section of the Fabric docs for the release you chose, then pin the same version in your image. Confirm that the version's defaults, including the default document size limit, match what your chaincode and tests expect. Treat this as a checklist item to verify in writing, not a setting you copy from an old tutorial.

Default document limit
8 MB
CouchDB state database docs

Decide which peers use CouchDB

Settle whether every peer joined to a channel will run CouchDB before the first peer is deployed. The deployment guide says a channel should not have peers using both CouchDB and LevelDB, because CouchDB restricts keys and values in ways LevelDB does not. Mixed state databases can pass tests on one peer and fail on another, so record this decision per channel in your network design notes.

Production deployment guide

Dedicate a host or container per peer

Run each CouchDB instance as its own process, in its own container or on its own host, rather than sharing one CouchDB across peers. Each peer's state database is tied to that peer's ledger, so a shared instance couples failure domains and upgrade windows. Plan CPU and memory for CouchDB separately from the peer, because the two processes compete for the same node if you co-locate them.

Provision persistent storage

Give each CouchDB instance a persistent volume sized for ledger state, indexes and compaction headroom. Ask your storage team to confirm snapshot and restore behavior for that volume class, and document how a lost volume is rebuilt from peers. Ephemeral container storage is not acceptable for a state database that a peer depends on after restart.

Map TLS and network paths

Plan the network path between each peer and its CouchDB instance, and decide whether that traffic stays on a private interface and whether it uses TLS. Restrict CouchDB's admin port to the peer and to your operators, and keep credentials out of images. Also confirm the CouchDB user and password approach: the Fabric docs say changing them after container creation requires the local.ini configuration approach, so decide that before first start.

How to configure CouchDB for a Fabric peer, step by step

This sequence takes a peer from a LevelDB default to a CouchDB state database with credentials set in configuration, optional size limits, reporting indexes, and checks that confirm the peer, the per-channel databases and query results all behave as expected.

  1. Provision CouchDB with dedicated storage

    The platform or database team runs CouchDB as a separate process beside the peer, with its own persistent volume so ledger state survives restarts and can be sized and backed up independently. Confirm the storage class, volume size and access path with your platform team before deployment, and keep the peer and CouchDB on the same network segment with no external exposure of the CouchDB port. Done when CouchDB starts, answers a basic HTTP request from the peer's network, and its data directory sits on the persistent volume.

  2. Set the CouchDB admin credentials in local.ini

    Set the CouchDB admin user and password in the CouchDB local.ini file rather than only through environment variables at container creation, because the Fabric docs state that changing the user and password after the container exists requires this configuration approach. Store the password in your secrets manager and inject the file at deploy time, not in source control. Done when CouchDB restarts with the new admin account and rejects requests that use the previous credentials.

  3. Point the peer state database settings at CouchDB

    In the peer configuration, set the state database to CouchDB and supply the CouchDB address and the admin credentials the peer should use, reading the password from a mounted secret rather than a plain value. Keep the same setting across every peer that joins a given channel, since mixing CouchDB and LevelDB peers on one channel is not supported. Done when the peer restarts with CouchDB selected and its logs show a successful connection to the CouchDB endpoint.

  4. Decide whether to raise max_document_size

    Review the largest value any chaincode will write to state. CouchDB 3.0.0 and later default max_document_size to 8 MB, and the Fabric docs say it can be raised to 4 GB, but a larger limit is only justified if real records need it. Keep the default when possible, and if you raise it, record the reason and the value in your configuration review. Done when the chosen limit is written to the CouchDB configuration and a test write above the old limit succeeds only in the environment where you expect it.

  5. Define indexes for reporting queries

    Work with the chaincode team to list the rich queries that reports and auditors need, then package CouchDB indexes with the chaincode so each query uses an index instead of a full scan. Keep the index set small, because every index adds write cost on the peer. Done when each planned query runs against a test ledger and the peer logs show the expected index in use, with no warnings about unindexed queries on the critical paths.

  6. Restart the peer and confirm per-channel databases

    Restart the peer and check that it creates one CouchDB database per channel and chaincode namespace it hosts, following the naming the peer uses. Confirm each channel's database appears in the CouchDB admin view and that block commits continue without errors on the peer. Done when every joined channel has its database and the peer reports the channel height matching the other members.

  7. Verify query results and record the baseline

    Run a set of test queries through the chaincode, including rich queries against the indexes, and compare the results with values written and read through LevelDB-independent checks, such as expected key counts and known records. Record the baseline response times and the CouchDB disk usage so later changes and backups have a reference. Done when the test queries return the expected records, the baseline is stored with the runbook, and a backup restore has been rehearsed against this configuration.

When CouchDB is worth the extra process over LevelDB

The Fabric CouchDB documentation says CouchDB can help meet auditing and reporting requirements that LevelDB does not support. This matters when a regulator, internal audit or a consortium member needs to query ledger state by attributes such as status, amount, date range or party, not only by a known key. LevelDB answers key lookups and key range scans well, but it gives you no document-level query layer for the state, so reporting often ends up as external exports that must be reconciled with the ledger.

  • Question to answer first: List the reports that auditors or members request today and mark which ones need filtering on value fields rather than on keys.
  • Export versus live query: Decide whether reports can run from a replicated copy built outside the peer, or must run against current state on the peer.
  • Read load: Reporting queries run against the peer's state database, so heavy analytical reads on a production peer need capacity planning.
  • Scope of data: Only the channels that need these queries should use CouchDB, since the database choice is made per channel.
  • Evidence: Auditors will ask how report results are produced, so document the query definitions and the data source for each one.

Confirm with your auditors and the consortium which reports must come from the ledger itself and which can come from an approved downstream system.

Why each channel must use one database type across its peers

The Fabric deployment guidance is direct: channels should not have peers that use both CouchDB and LevelDB. The reason is that CouchDB imposes restrictions on keys and values that LevelDB does not. Every peer on a channel maintains its own copy of the world state and runs the same chaincode against it, so the state database type is a property of the channel's operation, not an individual peer's preference. A mixed channel means the same transaction can be valid on one peer and fail on another because the state store rejected a write.

The practical consequence is that a key or value that works on a LevelDB peer may fail on a CouchDB peer. Chaincode that has run for months on LevelDB peers can surface these failures only after a peer with a different database joins, or when a new organization onboards its own peer with a default configuration. Before the network is designed, the team should record the database type for each channel in the network design, and confirm with the chaincode developers which key and value patterns the application already uses. Illustrative check: a chaincode that writes keys with a leading underscore or stores values that exceed CouchDB's default document size will behave differently on each database type, and the difference will not show up in a single-peer test.

Enforcement belongs in the onboarding process, not in a later audit. Each member organization should confirm the state database of any new peer before it joins a channel, and the channel's operating procedure should name who approves that check. Ask your Fabric operators to confirm the peer configuration for the database type against the channel design before admitting the peer, and to repeat that check whenever a peer is rebuilt or redeployed from a template.

Mapping ledger keys, values and queries to CouchDB behavior

This table maps each Fabric concept that touches the state database to how CouchDB behaves and the design check to make before go-live. Read it per chaincode: any row that fails your data model is a reason to rework keys, values or queries before peers use CouchDB. The main takeaway is that CouchDB adds value only when your queries and document shapes are designed for it from the start.

Fabric conceptCouchDB behaviorDesign check
Ledger keysKeys carry restrictions in CouchDB that LevelDB does not impose, so some key names valid on LevelDB can fail on CouchDBConfirm current key restrictions in the Fabric CouchDB docs and test every key pattern your chaincode writes against a CouchDB peer
JSON valuesValues are stored as JSON documents, so only structured data is queryable with rich queriesConfirm each state value is valid JSON and carries the fields your queries filter on
Document size limitDefault max_document_size is 8 MB as of CouchDB 3.0.0, raisable up to 4 GBMeasure the largest expected value and decide whether to keep the default, raise the limit, or split large data off-ledger
Index definitionsRich queries rely on indexes packaged with the chaincode, and unindexed selectors can scan the databaseDefine one index per reporting query pattern, package it with the chaincode, and test query performance on realistic data volumes
Chaincode query functionsRich query functions can return results that change as data is written, and are not repeatable in every read pathKeep rich queries out of transactions that must be deterministic, and document which functions are read-only reporting paths
One database type per channelPeers with CouchDB and LevelDB on the same channel create inconsistent key and value handlingSet the state database type for every peer on a channel and record it in your peer deployment standard

Securing CouchDB credentials, network access and data

A CouchDB state database gives every peer a second process that holds the ledger's current state, so its credentials, network reach and backups need the same care as the peer itself. The cards below cover the controls to set and the points to confirm before a production channel depends on this setup.

Keep credentials out of images

Set the CouchDB user and password in local.ini on the host or mounted volume rather than baking them into a container image. The Fabric docs say that changing the user and password after the CouchDB container is created requires this approach, so plan it before the first deployment. Check that no credential appears in image layers, build scripts or peer configuration committed to source control.

CouchDB state database docs

Confine CouchDB to its peer

Place each CouchDB instance on a private network segment that only its peer can reach, and do not publish its port to other organizations or to the wider network. Peers in other organizations never talk to your CouchDB directly, so any exposure is a risk you created. Test the rule from a host outside the peer's security group or subnet to confirm that the connection is refused.

Encrypt the peer-to-CouchDB connection

Enable TLS on the connection between the peer and CouchDB where your CouchDB version supports it, so state reads and writes are not sent in clear text on the segment. Confirm the TLS options for your exact CouchDB version and the Fabric peer settings in the Fabric and CouchDB docs before you rely on them. Record the certificate source and renewal owner alongside your other peer certificates.

Use least-privilege database users

Create a CouchDB user for the peer with only the permissions it needs on the channel databases, and keep administrator credentials separate for operators. Do not let the peer's account create or drop databases beyond what the peer requires, and do not share one administrator login across environments. Review user lists and rotate passwords on a schedule your security team sets, and confirm which admin and user roles your CouchDB version exposes.

Treat CouchDB backups as ledger data

Backups of CouchDB hold the same world state the peer serves, so store them with the same classification, encryption, access control and retention rules as the ledger and MSP backups. Restore tests should prove that a peer can rebuild its state from them and that restored data stays on its intended network. Ask your backup vendor or team how snapshots are encrypted and who can read them.

Confirm version-specific security settings

Security options for CouchDB, including TLS and authentication behavior, change between releases, so the settings you use must match the CouchDB version you run alongside your Fabric line. Check the Fabric CouchDB guidance and the CouchDB documentation for your version before go-live, and record the result in your change log. Repeat the check during every Fabric or CouchDB upgrade.

Sizing CouchDB storage and backing up state with the ledger

CouchDB state grows with the ledger and with every index you define, so sizing has to cover disk for data and indexes on each peer, not just the block store. Each peer that uses CouchDB holds its own copy of the world state for the channels it joins, which means disk, memory and CPU are multiplied by the number of peers, and index footprint grows with each reporting query you add. Before you commit to hardware, ask your Fabric partner or your own platform team to model state size per channel from current key counts and expected write volume, then add headroom for growth over your planned hardware refresh cycle. Confirm query memory and CPU needs by running your real reporting queries against a copy of production-like data, because rich queries and index builds are the workloads most likely to surprise you.

Backups have to capture the CouchDB state and the peer ledger as one consistent point in time. If you restore a peer's ledger from one moment and its CouchDB state from another, the peer must rebuild state from the block store on startup, which can take a long time on a large channel. Decide which of three approaches you will use: a stopped-peer file-level copy of both the ledger and the CouchDB data directories, a volume snapshot taken for both at the same moment, or a peer restored from a ledger snapshot and then allowed to catch up. Document the chosen method, the backup schedule, retention and where copies are stored, and treat the CouchDB admin credentials stored in local.ini as part of the backup scope without writing them into backup logs. Your team should confirm the exact procedure against the Fabric CouchDB documentation and the version of CouchDB you run.

The restore test is what proves the backup works, and it has to be run before go-live and repeated after material changes such as a CouchDB upgrade, a larger index set or a move to new storage. Restore a single peer into an isolated environment, start it, confirm it reaches the same block height as the source, run the reporting queries your business depends on and compare results with the original. Record how long the restore took, because that figure sets your realistic recovery expectation for the channel. Set a rule that a backup is not considered valid until a restore of it has succeeded, and assign an owner to repeat the test on a schedule agreed with your operations and compliance teams.

Common CouchDB failures on Fabric peers and how to fix them

This table pairs common CouchDB-backed peer failures with their likely causes and the general fix for each. Read it as a triage guide: match the symptom you see, check the cause, then follow the official docs for exact settings. The main takeaway is that most failures trace to connection settings, document size, missing indexes or mixed database types, and each one is easier to prevent in the build than to repair on a live channel.

SymptomLikely causeFix
Peer fails to start, logs show it cannot reach CouchDBCouchDB process not running, wrong host or port in the peer's core.yaml, or a network policy blocking the peer-to-CouchDB connectionConfirm CouchDB is up and reachable from the peer's network namespace or pod, then check the state database connection settings against the Fabric CouchDB docs
Peer cannot authenticate to CouchDB after a credential changeThe CouchDB user or password was changed after the container was created, so the peer still presents the old valuesUpdate the credentials in the CouchDB local.ini configuration as the Fabric docs describe, then align the peer's configured username and password and restart the peer
Transaction or chaincode write rejected for document sizeThe document value exceeds the CouchDB max_document_size limit, which defaults to 8 MB as of CouchDB 3.0.0Redesign the chaincode to store smaller values or split large records, or raise the limit only after confirming the change with your CouchDB version and sizing plan
Rich queries are slow, time out or return errorsNo index matches the query selector, so CouchDB scans every document in the databaseCreate indexes that match the selector fields and sort order, package them with the chaincode, and confirm query plans in a test channel before production use
Peers on one channel report different state database typesSome peers use CouchDB and others use LevelDB for the same channel, which the Fabric deployment guide advises againstChoose one state database type per channel, then rebuild affected peers so every peer on the channel uses the same type
State diverges or queries return stale results after a restoreA CouchDB backup was restored without the matching ledger block height, so the state database and ledger are out of stepRestore the ledger and state database together from the same point, verify block height and state on each peer, and follow the Fabric backup guidance before rejoining the channel
Queries behave differently after moving a channel to CouchDBKeys or values that LevelDB accepted are now restricted by CouchDB key and value rulesReview chaincode key naming and value formats against the CouchDB restrictions before migrating, and test the chaincode on a non-production channel first

What teams ask before running CouchDB with Fabric

Is CouchDB needed, or is LevelDB enough for our Fabric peers?

LevelDB is enough when your chaincode reads ledger state by key and you do not need rich queries over JSON values. CouchDB is worth the extra process when you need auditing or reporting queries that LevelDB cannot serve, because CouchDB runs as a separate database process alongside each peer and can answer those queries directly. Before choosing, list the reporting questions your members will ask, the queries your chaincode must run, and whether those queries can instead be served from an off-ledger reporting store. Adding CouchDB also adds a database to patch, back up and monitor on every peer that uses it, so the decision should follow from real query requirements rather than habit.

What drives the effort and cost of running CouchDB with Fabric?

The main drivers are the number of peers that run CouchDB, the number and shape of indexes you define, the query load your applications place on peers, the sizing of each CouchDB instance, and how much backup testing you commit to. Each peer carries its own CouchDB process, so cost grows with peer count and with the storage each state database needs. Indexes add build and maintenance work every time chaincode definitions change. When requesting a quote, ask the provider to itemize design work, build work on each peer, index design and review, load testing, backup and restore testing, and documentation for your operations team. Most of these costs are one-time, while patching, monitoring and backup verification recur.

How long does a CouchDB state database project take?

Duration depends on scope: how many channels and peers are involved, whether CouchDB is being added to a network already running LevelDB, how many reporting indexes you need, and how much load and restore testing is required. A single channel on a test network is a much smaller task than a multi-organization rollout with per-peer tuning and tested backups. We do not publish a fixed duration for this topic. Ask any provider, including DeployOpen, for a written schedule that ties each phase to a named deliverable and to a test network you can inspect, and confirm which phases depend on your change windows and approvals.

What must our team provide before the work starts?

You need people who understand Fabric channels, chaincode definitions and endpoint layout, and people who can operate CouchDB, including its users, databases, indexes and backups. You also need a test network that mirrors your production channel configuration, so index design and query tests can run safely. Decide in advance which channels will use CouchDB and which will stay on LevelDB, since the Fabric deployment guide says channels should not have peers using both database types. Finally, confirm who owns CouchDB credentials, where they are stored, and who approves changes to peer configuration. Missing any of these usually lengthens the work more than the technical build itself.

Can our own engineers run CouchDB with Fabric without an outside partner?

Yes, if they already run Fabric peers and have working knowledge of CouchDB administration, including authentication, database sizing, index management and backup restore. The gaps tend to be in index design for chaincode queries, document size limits, and rehearsed restores. A practical approach is to have your team build the design on a test network, then run a restore drill and a load test before touching production. If the team lacks one of these skills, a partner can cover that part under a fixed-scope agreement, and your team keeps the runbooks. Whatever the split, agree in writing who patches CouchDB and who responds when a peer's state database falls behind.

What are the main document size and key limits to plan for?

CouchDB imposes restrictions on keys and values that LevelDB does not, which is one reason the deployment guide asks you to keep one database type per channel. The CouchDB documentation states that, as of CouchDB 3.0.0, the default max_document_size is 8 MB and can be raised to 4 GB. Raising the limit is a configuration choice, not a free change: large documents slow replication, indexing and backups, so chaincode designs should keep values small and store large payloads elsewhere. Test your largest realistic value during the test phase and confirm the configured limit with your CouchDB version before go-live.

Where are CouchDB credentials stored, and how do we change them safely?

CouchDB user and password settings are usually supplied through configuration, and the Fabric docs state that changing the CouchDB user and password after the CouchDB container is created requires the local.ini configuration approach. Plan this at build time rather than after go-live, because credential changes touch every peer that uses CouchDB. Store the values in your secrets manager rather than in plain configuration files in source control, restrict file permissions on local.ini, and rotate credentials through a documented change window. Confirm with the Fabric and CouchDB documentation for your versions how peers reconnect after a change.

What happens if we need to switch between CouchDB and LevelDB later?

Switching database type is a planned change because the one-type-per-channel rule applies: you cannot leave a channel with peers on both types. In practice, the switch means choosing a channel, rebuilding each peer's state database from the ledger on the new type, and verifying that every peer on that channel reaches the same state before reopening traffic. Schedule the change with all member organizations, take a verified backup of the ledger and MSPs first, and rehearse the switch on a test network. Ask any provider to document the rollback path and the expected impact on peers during the rebuild.

How DeployOpen scopes and delivers a CouchDB state database for Fabric

DeployOpen plans, implements, hardens, documents and supports Hyperledger Fabric networks inside your own infrastructure, including the CouchDB state database on each peer. Work starts from a written scope that settles which channels use CouchDB, which queries need indexes, and how credentials, backups and sizing are handled before any peer is changed.

How we scope

  • Confirm which channels need CouchDB for auditing or reporting, and which can stay on LevelDB.
  • Map each peer and channel so no channel mixes CouchDB and LevelDB peers.
  • Record the reporting queries that need indexes and the document sizes the chaincode will store.

How we build

  • Configure CouchDB credentials through local.ini so user and password changes do not depend on container recreation.
  • Create and test indexes against representative data before they reach production peers.
  • Size CouchDB storage, memory and backup jobs against the ledger growth and query load you expect.

How we hand over

  • Deliver the written configuration, index definitions, credential handling steps and backup and restore runbook.
  • Walk your operators through checking peer health, CouchDB status and document size errors.
  • Document the chaincode key and value rules that apply because CouchDB is in use.

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer after handover.
  • Plan CouchDB version changes alongside Fabric upgrades so each channel stays on one database type.
  • Retest indexes and backups after chaincode or channel changes that affect stored data.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.