Amazon DocumentDB

Amazon DocumentDB - Architecture and Production Practice

Amazon DocumentDB – Architecture and Production Practice

A deep, practical walkthrough of how Amazon DocumentDB actually works under the hood — its storage engine, replication, failover, security model, and the patterns experienced teams use to run it well in production.

Imagine a library where every book is automatically copied into six vaults spread across three different buildings the moment it’s written, and a librarian can hand you a fresh copy from any nearby vault in under a second — even if one entire building loses power. That is roughly what happens every time an application writes a document into Amazon DocumentDB. Most engineers use DocumentDB as “a managed MongoDB-compatible database” and stop there. But underneath that simple description sits a genuinely distinct storage architecture, one that separates compute from storage in a way that changes how you should think about scaling, failover, backups, and cost. This tutorial goes past the surface-level pitch and walks through how DocumentDB is actually built, how data moves through it, and how to run it the way mature engineering teams do.

1What DocumentDB Really Is

Not a fork of MongoDB, and not a generic NoSQL box — a purpose-built, distributed storage system with a MongoDB-compatible front door.

Amazon DocumentDB is a fully managed document database built by AWS that speaks the MongoDB wire protocol. Applications connect to it using MongoDB drivers, and it accepts many of the same commands developers already know — find, insert, aggregate, and so on. But DocumentDB does not run MongoDB’s actual server code underneath. AWS built its own database engine from the ground up, and made that engine understand MongoDB’s language. This distinction matters constantly in production: DocumentDB supports a defined subset of MongoDB API compatibility (currently aligned with versions such as 4.0, 5.0, and later releases), and some MongoDB features simply don’t exist in DocumentDB because the underlying engine was never built to need them.

Simple Analogy

Think of MongoDB compatibility the way you’d think of a universal remote control. The remote (your MongoDB driver and queries) can operate many different televisions (database engines) because it speaks a common signal language. But the television itself — the actual electronics doing the work — can be built completely differently on the inside while still responding correctly to the same buttons.

Why AWS built it this way

Running MongoDB reliably at scale traditionally means managing replica sets yourself, tuning storage, handling failover scripts, and babysitting backups. AWS’s bet with DocumentDB was that most teams don’t actually want to operate a database engine — they want the query language and document model, with someone else responsible for durability, patching, and scaling the storage layer. That single design goal explains almost every architectural choice covered in this tutorial.

i
Worth Remembering

“MongoDB-compatible” is a compatibility layer, not an emulation of MongoDB’s internals. Query behavior, index behavior, and operational behavior can all differ from self-managed MongoDB in ways that matter for design decisions.

Where it fits among AWS’s database options

AWS offers several purpose-built databases, and DocumentDB occupies a specific niche: flexible, semi-structured JSON-like documents, accessed through a familiar query API, with the operational model of a managed relational-style service. It sits next to services like Amazon RDS and Amazon Aurora conceptually — in fact, as you’ll see in the next chapter, it borrows Aurora’s most important architectural idea directly.

2Architecture and Core Components

DocumentDB’s defining architectural decision is splitting compute away from storage — and everything else follows from that split.

A DocumentDB deployment is called a cluster. A cluster is made of two separate layers that scale independently: a fleet of compute instances that run queries, and a distributed, log-structured storage volume that actually holds the data. This is the same foundational idea Amazon Aurora pioneered for relational databases, adapted here for a document workload.

Compute Layer

Instances

Each instance is a virtual database endpoint that executes queries and returns results. One instance is always the primary (handles writes); the rest are replicas (read-only).

Storage Layer

Cluster Volume

A single logical, distributed volume shared by every instance in the cluster. It automatically grows in increments as data grows, up to very large sizes, with no manual resizing.

Networking

Endpoints

A cluster endpoint always points at the current primary; a reader endpoint load-balances across all healthy replicas automatically.

Isolation

VPC Placement

Every DocumentDB cluster lives inside a VPC subnet group and is never reachable from the public internet by default.

Why a shared storage volume changes everything

In a traditional replicated database, each replica keeps its own full copy of the data and replays a stream of changes to stay in sync — which means writes have to travel across the network to every node before they’re durable. DocumentDB replicas don’t do this. They all read from the same underlying storage volume. A replica catches up simply by fetching pages it doesn’t yet have cached, not by re-executing every write operation. That’s why adding a read replica in DocumentDB is fast and doesn’t add extra write overhead to the primary.

graph TD
  A[Application / MongoDB Driver] --> B[Cluster Endpoint]
  A --> C[Reader Endpoint]
  B --> D[Primary Instance]
  C --> E[Replica Instance 1]
  C --> F[Replica Instance 2]
  D --> G[(Distributed Cluster Storage Volume)]
  E --> G
  F --> G
  G --> H[(6 copies across 3 Availability Zones)]
        
FIG 1 — Compute instances share one distributed storage volume instead of holding private copies of the data.

Instance classes and clusters versus elastic clusters

A standard DocumentDB cluster scales reads by adding instances (up to 15 replicas) and scales vertically by resizing instance types. For workloads that outgrow a single write node’s capacity, AWS also offers DocumentDB Elastic Clusters, which automatically shard data across many instances behind the scenes, distributing both reads and writes horizontally. Elastic clusters trade some operational simplicity for the ability to scale write throughput well beyond what one primary instance can handle.

3Internal Working: The Storage Engine

The single most important internal concept in DocumentDB is that the log is the database — not a side record of it.

In most databases, changes are first written to an in-memory data structure and to a write-ahead log, and later “flushed” into the actual data files in a separate step. DocumentDB’s storage engine skips that second step almost entirely. Only the log records themselves are shipped to storage; the storage layer is responsible for turning that log into readable data pages in the background. This is why AWS describes the design as “log is database.”

Simple Analogy

Picture a construction crew that, instead of hauling finished wall panels to a building site, ships only the blueprints and lets a local crew at the site assemble the walls. Shipping blueprints is far lighter than shipping finished panels — and that’s exactly why DocumentDB sends compact log records across the network instead of full data pages.

The quorum write model

Every write is replicated six ways, spread across three Availability Zones — two copies per zone. A write is considered durable once four of those six copies acknowledge it. This “4-of-6” quorum is deliberately chosen: it can tolerate losing an entire Availability Zone (two copies) and still confirm writes, and it can tolerate an additional single copy failure without impacting availability. Reads only need one healthy copy of the requested data among the segments queried, but a special read quorum of three copies is used specifically when repairing a stale or lost segment.

6
Copies of data written
3
Availability Zones spanned
4/6
Quorum needed to confirm a write

Storage nodes and self-healing segments

The cluster volume is broken into fixed-size segments (10 GB each), and each segment is independently replicated six times. If a storage node fails or a disk becomes corrupted, only the affected segments need repair — the system re-replicates just those 10 GB pieces from healthy copies elsewhere, rather than restoring an entire volume. This segment-level self-healing is what allows the storage layer to recover from hardware failures continuously, without any visible downtime and without a human being paged for routine disk issues.

!
Common Misconception

People sometimes assume DocumentDB replicates like typical MongoDB replica sets, where secondaries apply an operations log (oplog) one write at a time. DocumentDB replicas don’t replay operations at all — they read finished pages from shared storage. This is why replica lag in DocumentDB is usually measured in milliseconds, not seconds.

4Data Flow and Lifecycle

Following a single write from driver call to durable, queryable data reveals why DocumentDB behaves the way it does under load.

1

Driver sends the write

The application’s MongoDB driver sends an insert or update to the cluster endpoint, which always routes to the current primary instance.

2

Primary generates a log record

The primary instance translates the operation into a compact redo log record — not a full data page — and ships that record to the storage layer.

3

Storage nodes acknowledge in parallel

The log record is sent to all six storage copies simultaneously. The write is durable the instant four of the six acknowledge receipt.

4

Storage applies the log in the background

Independently and asynchronously, storage nodes turn accumulated log records into updated data pages, so future reads don’t need to replay history.

5

Replicas become visible

Read replicas fetch the newly available pages (or invalidate stale cache entries) from the shared volume, typically within tens of milliseconds.

Reads follow a different, shorter path

A read issued against the reader endpoint is routed to one of the healthy replica instances, which serves the request from its own buffer cache or by fetching the needed page directly from storage. Because there’s no requirement to “catch up” on a replayed log, replicas can serve consistent, recent data with very little lag relative to the primary — an important property for read-scaling analytics-style workloads without stale results.

“In DocumentDB, durability is a storage-layer guarantee, not a compute-layer one — the primary instance can be replaced without ever touching the data it was responsible for.”

Backups are a continuous byproduct, not a scheduled event

Because the log stream is already being shipped to storage continuously, DocumentDB captures continuous, incremental backups to Amazon S3 automatically, with no measurable performance impact on the primary instance. This lets you restore a cluster to any point in time within your retention window (up to 35 days), rather than only to the moment of a nightly snapshot.

5Advantages, Disadvantages and Trade-offs

Every architectural choice that gives DocumentDB its strengths also draws a boundary around what it will never be good at.

Advantages

  • Storage scales automatically without manual provisioning or resizing.
  • Replica lag is typically single-digit milliseconds, enabling near-real-time read scaling.
  • Storage-level self-healing removes an entire category of operational toil.
  • Continuous backup to S3 with point-in-time restore, at no extra performance cost.
  • Fast, predictable failover to a replica, often under 30 seconds.
  • Fully managed patching, monitoring hooks, and encryption integration with AWS services.

Disadvantages / Trade-offs

  • Not a drop-in replacement for MongoDB — some aggregation operators, transaction guarantees, and index types differ or are unsupported.
  • Only one instance accepts writes at a time in standard clusters (elastic clusters address this differently).
  • No public internet access by default — always requires VPC networking, which adds setup complexity for some teams.
  • Version compatibility lags behind the newest MongoDB releases.
  • Storage-separated architecture makes some workloads (very write-heavy, large single documents) behave differently than expected from MongoDB experience.

The trade-off in one sentence

DocumentDB optimizes hard for durability, read scalability, and operational simplicity, and it accepts a narrower single-writer model and partial API compatibility as the price for that. Teams that need exact MongoDB parity, multi-region multi-writer behavior, or the very latest MongoDB features should evaluate that gap carefully before committing.

6Performance and Scalability

Scaling in DocumentDB is really two independent scaling problems: scaling reads, and scaling writes — and they are solved in completely different ways.

Scaling reads: nearly free, nearly instant

Because replicas share the storage volume, adding a fifteenth read replica doesn’t require copying terabytes of data first, and it doesn’t add write amplification to the primary. This makes DocumentDB extremely good at absorbing read-heavy spikes — reporting jobs, dashboards, or seasonal traffic — by adding replicas that become useful within minutes.

Scaling writes: vertical, until you shard

Standard clusters can only scale write throughput by choosing a larger primary instance class — more vCPUs and memory to process incoming operations faster. There’s a ceiling to this. Once a workload’s write volume exceeds what the largest instance class can process, the only paths forward are re-architecting the data model, splitting the workload across multiple clusters, or moving to an elastic cluster, which shards data across nodes to scale writes horizontally.

Buffer Cache and Working Set Size

Query latency depends heavily on whether the “working set” — the data actively being read — fits in an instance’s memory buffer cache. When it does, DocumentDB serves reads almost entirely from RAM. When the working set exceeds available memory, latency rises because pages must be fetched from the storage layer over the network, which is why right-sizing instance memory is one of the highest-leverage performance levers available.

Indexing strategy still governs everything

No amount of instance scaling compensates for a query pattern that forces a full collection scan. As in any document database, compound indexes that match your actual filter and sort patterns, and avoiding unbounded array growth inside documents, remain the primary performance controls an application team has, independent of the underlying storage architecture.

i
Practical Tip

DocumentDB provides a Performance Insights-style profiler and slow-query logging. Reviewing slow queries regularly catches missing indexes long before instance resizing becomes the “fix” a team reaches for by default.

7High Availability and Reliability

Because storage and compute fail independently, DocumentDB treats an instance failure and a storage failure as two entirely different problems with two different recovery paths.

sequenceDiagram
  participant App as Application
  participant DNS as Cluster Endpoint (DNS)
  participant P as Primary Instance
  participant R as Replica Instance
  participant S as Storage Volume
  App->>DNS: Connect
  DNS->>P: Route to primary
  Note over P: Primary fails
  DNS-->>R: Endpoint re-points automatically
  R->>S: Promote to primary using shared volume
  App->>DNS: Reconnect
  DNS->>R: Route to new primary
        
FIG 2 — Failover promotes an existing replica rather than rebuilding a database from backup, because the data was already shared.

Instance failover

If the primary instance becomes unhealthy, DocumentDB promotes an existing read replica to become the new primary and repoints the cluster endpoint’s DNS to it. Because the new primary already has access to the same shared storage volume, there’s no need to copy data during promotion — this is why failover typically completes in well under a minute, and often in under 30 seconds. If a cluster has no replicas, DocumentDB still creates a new instance automatically, which takes longer since there’s no already-running standby to promote.

Storage failure and Multi-AZ durability

Because every piece of data already exists as six copies across three Availability Zones, losing an entire Availability Zone’s storage does not threaten durability — the surviving four copies in the other two zones still satisfy the write quorum. This is a fundamentally different reliability guarantee than “we take frequent backups”; the data was never dependent on a single zone to begin with.

Global Clusters for cross-region resilience

For disaster recovery across entire AWS regions, DocumentDB Global Clusters replicate data from a primary region to up to five secondary regions with typical replication lag under one second, using dedicated infrastructure rather than application-level replication. In a regional outage, a secondary region can be promoted to take write traffic, trading a short RTO for the cost of maintaining warm standby infrastructure elsewhere.

8Security

DocumentDB’s default security posture is deliberately closed — nearly every protection has to be turned off on purpose to create a gap.

Network

VPC-Only Access

Clusters have no public endpoint by default. Access is controlled through VPC security groups, subnet placement, and optionally VPC peering or PrivateLink.

Encryption at Rest

AWS KMS

Storage volumes, automated backups, snapshots, and replicas are encrypted using AWS Key Management Service keys, chosen at cluster creation.

Encryption in Transit

TLS by Default

Connections use TLS out of the box; disabling it is an explicit, discouraged configuration change rather than an opt-in step.

Identity

Authentication

Supports username/password authentication (SCRAM) and, more recently, IAM database authentication for centralizing identity through AWS IAM policies.

Auditing and least privilege

DocumentDB supports audit logging that records connection attempts, authentication events, and data-definition operations, which can be streamed to CloudWatch Logs for retention and alerting. Combined with role-based access control inside the database itself, teams can enforce least-privilege access both at the network layer (who can even reach the cluster) and at the data layer (what an authenticated user is allowed to touch).

ANTI-PATTERN-01 Avoid
Problem

Placing a DocumentDB cluster in a public subnet and opening its security group broadly “temporarily” to unblock a developer, then forgetting to close it.

Why It’s Harmful

Even though DocumentDB has no public endpoint by default, misconfigured security groups combined with bastion hosts or peered networks can still expose the cluster far more broadly than intended, and this kind of drift is easy to miss in a security review.

Correct Approach

Keep clusters in private subnets, scope security group rules to specific application security groups rather than IP ranges, and use infrastructure-as-code so network access is reviewable and reversible.

9Monitoring, Logging and Metrics

Because the storage layer is invisible to you as a user, monitoring in DocumentDB is mostly about watching the compute layer and the signals storage exposes through it.

The metrics that matter most

MetricWhat it tells you
CPUUtilizationWhether the instance class is undersized for current query load.
DatabaseConnectionsWhether the application is opening more connections than the instance can efficiently handle.
BufferCacheHitRatioWhether the working set fits comfortably in memory, or reads are falling back to storage.
VolumeBytesUsedHow large the shared storage volume has grown, relevant for cost tracking.
ReplicaLagHow far behind a replica instance is from the primary’s latest visible state.

Logs and profiling

DocumentDB integrates with Amazon CloudWatch Logs for audit logs and profiler logs. The profiler captures slow-running operations above a configurable threshold, which is typically the fastest way to find a missing index or an inefficient aggregation stage without guessing. CloudWatch Alarms can be layered on top of any exposed metric to page a team before a slow degradation becomes an outage.

!
Common Mistake

Teams often monitor CPU and connections but skip enabling the profiler because it’s not on by default. This means the single most useful diagnostic tool for query performance sits unused until after a production incident forces it on.

10Deployment and Cloud Configuration

Deploying DocumentDB well is largely about getting a handful of cluster-level decisions right before the first write ever lands.

Networking

Subnet Group

A DB subnet group spanning at least three Availability Zones ensures the cluster’s storage and replicas can actually spread across zones as designed.

Configuration

Parameter Groups

Cluster and instance parameter groups control engine-level settings such as TLS enforcement and TTL monitor behavior, applied consistently across instances.

Maintenance

Maintenance Windows

Patching and minor version upgrades apply during a configurable weekly window, minimizing surprise restarts during business-critical hours.

Scaling Model

Elastic Clusters

An alternative deployment mode that shards data automatically across many nodes, aimed at workloads that outgrow single-writer throughput limits.

Choosing between a standard cluster and an elastic cluster

A standard cluster is the right default for the large majority of workloads: simpler mental model, one writer, many readers. An elastic cluster becomes worth its added complexity once a workload’s write throughput or total data size genuinely exceeds what a single, well-sized primary instance and one storage volume can serve — commonly seen in very high-ingest event or telemetry pipelines rather than typical application databases.

11Design Patterns and Anti-patterns

Document databases reward a different modeling instinct than relational databases — DocumentDB is no exception, and the same traps that hurt MongoDB deployments show up here too.

Pattern: Embed What You Read Together

Grouping data that is almost always read as a unit — an order and its line items, a user profile and its preferences — into a single document avoids the cross-document joins document databases are not optimized for.

Pattern: Reference for Large or Independently-Growing Data

Data that grows without bound (a running activity log, an ever-expanding comment thread) is better modeled as a separate collection referencing a parent ID, rather than as an array field that keeps growing inside one document.

Pattern: Read-Replica Offloading

Routing reporting queries, admin dashboards, and analytics jobs to the reader endpoint keeps that traffic from competing with transactional traffic on the primary instance.

ANTI-PATTERN-02 Avoid
Problem

Storing an unbounded array inside a single document — for example, appending every event a user ever triggers into one “events” array on their profile document.

Why It’s Harmful

Documents that keep growing become progressively more expensive to read and rewrite, and eventually risk hitting document size limits, degrading performance long before that limit is reached.

Correct Approach

Move unbounded, append-heavy data into its own collection with a reference back to the parent document, and paginate or aggregate rather than loading the full history at once.

12Best Practices and Common Mistakes

Most production issues with DocumentDB trace back to a small, repeatable set of oversights rather than exotic edge cases.

Advantages

  • Use the reader endpoint, not individual instance endpoints, so failover and scaling stay transparent to the application.
  • Enable the profiler early, before an incident forces you to.
  • Right-size instance memory to fit your actual working set, not just peak CPU needs.
  • Test failover deliberately in a non-production cluster so the application’s reconnect logic is proven, not assumed.

Disadvantages / Trade-offs

  • Assuming full MongoDB feature parity without checking the compatibility notes for the specific engine version in use.
  • Leaving connection pools unbounded, exhausting the primary’s connection limit under load.
  • Ignoring replica lag entirely because it’s “usually small,” then being surprised during an unusual load spike.
  • Sizing instances for average load instead of the peak load that actually causes incidents.
i
Practical Tip

Because failover repoints DNS rather than rebuilding data, application-side connection retry logic with short backoff is usually all that’s needed to ride out a failover gracefully — no manual intervention required if the driver reconnects correctly.

13Real-world and Industry Examples

The kinds of workloads that gravitate toward DocumentDB share a common shape: flexible schemas, read-heavy access patterns, and a need for managed durability without operating a fleet of replica sets.

Content and Catalog Platforms

Media and e-commerce platforms often store product catalogs or content metadata as documents, where different products or articles naturally have different attributes — a shape that fits documents far better than a rigid relational schema.

User Profile and Preference Stores

Applications with large numbers of users store profile, settings, and personalization data as documents, benefiting from DocumentDB’s fast read-replica scaling as user bases grow.

Gaming Backends

Player state, inventories, and match history are naturally document-shaped and read-heavy, making DocumentDB’s low-lag replicas useful for real-time leaderboards and player dashboards.

Migration Target for Self-Managed MongoDB

Organizations already using MongoDB frequently adopt DocumentDB specifically to shed the operational burden of managing replica sets, patching, and backups themselves, using AWS Database Migration Service to move data over with minimal application changes.

“The workloads that succeed on DocumentDB are the ones that were already thinking in documents — it rewards teams for embracing the model rather than forcing relational habits onto it.”

14Frequently Asked Questions

Q1Can DocumentDB accept writes on more than one instance at the same time?

In a standard cluster, no — only the primary instance accepts writes, and all other instances are read-only replicas. Elastic clusters distribute writes across shards instead, which is a different deployment mode entirely.

Q2Does DocumentDB support every MongoDB feature?

No. DocumentDB implements a defined, version-specific subset of the MongoDB API. Certain aggregation operators, some transaction semantics, and specific index types may behave differently or be unavailable, so it’s worth checking compatibility documentation for the target engine version before migrating.

Q3How quickly does a replica pick up a write made on the primary?

Typically within tens of milliseconds, because replicas fetch already-materialized pages from the shared storage volume instead of replaying a stream of operations one at a time.

Q4What happens to my data if an entire Availability Zone goes down?

Nothing is lost. Data is stored as six copies spread across three Availability Zones, and losing one zone still leaves enough copies to satisfy the write and read quorums the storage layer requires.

Q5Can a DocumentDB cluster be reached directly from the public internet?

Not by default. Clusters live inside a VPC and require explicit networking configuration such as VPC peering, a bastion host, or PrivateLink to be reached from outside that private network.

Q6Is DocumentDB a good fit for cross-region disaster recovery?

Yes, through Global Clusters, which replicate data to up to five secondary AWS regions with sub-second typical lag, allowing a secondary region to take over write traffic during a regional outage.

15Summary and Key Takeaways

Amazon DocumentDB earns its reliability and read-scaling characteristics from one core decision: separating compute from a distributed, self-healing, six-way-replicated storage volume, and treating the write-ahead log itself as the actual database. That single choice explains its fast failover, near-instant replica scaling, continuous backups, and its very real limits — a single-writer model in standard clusters and partial rather than complete MongoDB compatibility. Teams that model their data in document-native ways, monitor the right signals, and respect the single-writer boundary tend to get the most out of the platform with the least operational effort.

Key Takeaways

  • Compute and storage are separate layers — replicas share one distributed volume instead of holding private copies, making replica addition fast and replica lag tiny.
  • The log is the database — only compact log records travel across the network; storage nodes turn them into pages in the background.
  • Durability comes from a 4-of-6 write quorum across three Availability Zones, tolerating a full zone failure without losing data.
  • Failover promotes an existing replica using shared storage, typically completing in under a minute without any data movement.
  • Standard clusters have exactly one writer — elastic clusters exist specifically to scale write throughput horizontally when that becomes a ceiling.
  • Security defaults to closed — no public endpoint, encryption in transit and at rest available from day one, plus audit logging for accountability.
  • MongoDB compatibility is real but partial — always verify feature and version compatibility before assuming exact parity with self-managed MongoDB.