Running MongoDB Workloads as a Managed Service with Amazon DocumentDB - Document Model and Query Design
DocumentDB manages document data with a MongoDB-compatible API and achieves read scaling and DR with up to 15 read replicas and global clusters. This article explains how to use sharding with Elastic Clusters.
Overview of DocumentDB
Amazon DocumentDB is a fully managed, MongoDB-compatible document database service. It is compatible with the MongoDB 3.6, 4.0, and 5.0 APIs, so you can use existing MongoDB drivers and tools as is. Storage automatically scales up to 128 TiB, and the service has a high-availability design that keeps six copies of data across three AZs. Unlike RDS relational databases, it can flexibly store schemaless JSON documents, and you can store and query complex data structures that include nested objects and arrays as they are. Whereas DynamoDB is optimized for key-value access, DocumentDB is suited to workloads that require rich queries (aggregation pipelines, text search, geospatial queries).
Cluster Configuration and Scaling
A DocumentDB cluster consists of one primary instance and up to 15 read replicas. Read replicas distribute read workloads, and when the primary fails, the cluster automatically fails over. You can set the failover priority for each instance, which makes it possible to promote a specific instance preferentially. Elastic Clusters is DocumentDB's sharding feature and supports millions of writes per second and PB-scale storage. Simply by specifying a shard key, it automatically distributes data, and you can also add / remove shards online. Global clusters place read replicas in up to five Regions and achieve global read scaling and DR with replication lag of less than 1 second.
Queries and Operations
DocumentDB supports MongoDB aggregation pipelines, text indexes, and geospatial indexes. You can run complex analytical queries by combining aggregation stages such as $match, $group, $sort, and $lookup (joins between collections). With Change Streams, you can detect collection changes in real time and build event-driven processing by triggering Lambda functions. With Performance Insights, you analyze query execution plans and wait events to identify the causes of slow queries. Automated backups have a retention period of up to 35 days, and point-in-time recovery (PITR) is possible.
DocumentDB Pricing
DocumentDB pricing consists of three components: instances, storage, and I/O. A db.r6g.large instance (2 vCPU, 16 GiB) costs approximately $0.277/hour (Tokyo Region) (as of August 2026). Storage costs approximately $0.11 per GB per month, and I/O costs approximately $0.22 per 1 million requests. If you choose I/O-Optimized storage, I/O charges no longer apply, and the total cost is reduced for workloads with heavy I/O. Elastic Clusters are billed per vCPU and scale with the number of shards. Read replicas incur the same instance charges as the primary, so you set an appropriate number of replicas according to the read load.
DR with Global Clusters
DocumentDB global clusters are a feature that replicates data across multiple Regions. Because writes to the primary Region are replicated to other Regions with low latency, you can build disaster recovery that prepares for the failure of an entire Region. Because reads are possible in the replica Regions, you can let users in each area reference data from a location close to them and improve global read performance. If the primary Region ever becomes unavailable, you can promote a replica Region to continue operations and keep data loss to a minimum. It is a configuration suited to systems that require geographically distributed availability.
Sharding with Elastic Clusters
There are limits to the capacity and throughput that a single instance can handle. DocumentDB Elastic Clusters is a mechanism that scales horizontally beyond these limits by distributing data across multiple shards. Even if the write load or data volume increases greatly, you can handle it by adding shards. It splits collections based on a distribution key and spreads the load across multiple shards. It is important to choose the distribution key so that data is distributed evenly without skew. It provides an option that lets you flexibly expand capacity and throughput for large workloads that keep growing.
High Availability and Failover
To increase availability, DocumentDB replicates data across multiple Availability Zones. If the primary instance fails, one of the replicas is automatically promoted and takes over processing, so you can keep downtime short. If you place multiple replicas that handle reads, you can improve both availability and read performance. By handling the connection endpoint appropriately, the application can reconnect and keep running even when a failover occurs. With redundancy across multiple zones and automatic failover, you can achieve a database foundation that has no single point of failure and is hard to bring down.
Performance Monitoring and Optimization
To run DocumentDB stably, it is important to monitor performance continuously, find bottlenecks, and improve them. If you use a mechanism that visualizes the load on the database, you can understand which queries are heavy and which resources are under strain. Once you identify slow queries, you speed them up by adding appropriate indexes. When you handle many connections, you pool and reuse connections to reduce connection overhead. Checking query execution plans and revisiting inefficient processing is also effective. By continuing to monitor and optimize, you can maintain performance that withstands growth in data volume.
Summary
Amazon DocumentDB is a fully managed, MongoDB-compatible document database that provides storage of schemaless JSON data and rich queries. With up to 15 read replicas, sharding with Elastic Clusters, and DR with global clusters, it supports a wide range of workloads from small to large scale.
References (Official AWS Resources)
The primary sources for this page are the official AWS website and documentation. Check the official pages below for the latest specifications and pricing.
- Amazon DocumentDB official page
- AWS KMS official page
- Amazon CloudWatch official page
- AWS Documentation (official)
If this page and the official documentation disagree, treat the official documentation as authoritative.