AWS Database Blog

Optimizing for cost with Amazon DocumentDB (with MongoDB compatibility)

Amazon DocumentDB (with MongoDB compatibility) is a fast, scalable, highly available, and fully managed document database service that supports MongoDB workloads. You can use the same MongoDB 3.6 application code, drivers, and tools to run, manage, and scale workloads on Amazon DocumentDB without worrying about managing the underlying infrastructure. As a document database, Amazon DocumentDB makes it easy to store, query, and index JSON data.

AWS built Amazon DocumentDB to uniquely solve your challenges around availability, reliability, durability, scalability, backup, and more. In doing so, we built several novel and unique capabilities to remove undifferentiated heavy lifting and help reduce costs. This post introduces you to Amazon DocumentDB capabilities that enable you estimate, optimize, and monitor your costs.

T3 medium instances

With the launch of T3 medium instances (4 GiB RAM, 2 vCPUs), you now have a lower-cost instance type ($0.078 per hour) that is 72% cheaper than the previous entry point of r5.large instances (16 GiB RAM, 2 vCPUs) (prices vary per Region, see Amazon DocumentDB pricing).

T3 instances are great for getting started, development and testing, and small production workloads. You can provision a new cluster with T3 medium instances or scale the instances in your existing cluster to T3 medium instances. To learn more, see Modifying an Amazon DocumentDB Instance.

Highly durable, single-instance clusters

Amazon DocumentDB’s architecture separates storage and compute, so even a single-instance cluster is highly durable. The cluster storage volume replicates data six ways across three Availability Zones, which provides extremely high durability regardless of the number of instances in the cluster. A typical production cluster has two or more instances to provide high availability. However, you can optimize costs by using a single-instance development cluster when high availability isn’t required. For a single-instance cluster with 4 GB of RAM, which is still highly durable with six-way replicated data, you pay $0.078/hour in us-east-1. For pricing for all Regions, see Amazon DocumentDB pricing.

Additionally, in addition to benefiting from six-way replication of your data, you only pay for a single copy of your data.

Billing alerts

One way to optimize costs is to proactively address unexpected costs during the month (for example, scaling up a cluster to import 10 TB of data but forgetting to scale back down). Creating billing alerts at thresholds of 50% and 75% of your expected bill for the month helps you get an early warning if you are spending more than you expected. For more information about creating billing alerts, see Creating a Billing Alarm.

Cost allocation tags

In AWS, a tag is a label that you assign to an AWS resource, such as an Amazon DocumentDB cluster or instance. Tags enable you to categorize your AWS resources in different ways, for example, by purpose, owner, or environment, and you can use tags for many purposes, including cost allocation. Instead of getting a bill every month that summarizes your Amazon DocumentDB usage in your account, you can tag specific clusters and instances and track your costs at a more granular level, such as your production cluster or development environment, on an ongoing basis. Doing so gives you more visibility into how your costs are being allocated across your resources and areas that you could further optimize for cost. For more information, see Using cost allocation tags with Amazon DocumentDB (with MongoDB compatibility) and Using Cost Allocation Tags.

Compute is independent of storage

Because compute and storage scale independently, you don’t have to provision more compute just to get more storage. For example, you can have a 1 TB storage volume that you only access once in a while, and you can have a one or two T3 medium instances in your cluster. There is no need to provision large instance types just because you have a large storage volume. Separating storage and compute helps you optimize your cluster’s cost based on your specific use case.

Starting and stopping clusters

For development and test scenarios, you can stop a cluster when it’s no longer needed and start it when development resumes. When the compute instances are stopped, you aren’t charged for instances or I/O.

You can temporarily stop compute instances for up to 7 days when you don’t need to access your cluster (which is ideal for pausing test clusters over the weekend), and restart the instances when needed. Starting and stopping clusters when you’re not using the resources can help you optimize for cost, and you can even automate the starting and stopping of clusters using AWS Lambda and the AWS Command Line Interface (AWS CLI). For more information, see Stopping and Starting an Amazon DocumentDB Cluster.

Automatically scaling storage and I/O

When you provision an Amazon DocumentDB cluster, you don’t have to specify how much storage and I//O you need for your cluster. Amazon DocumentDB storage and I/O automatically scale as your workload scales, so you only pay for the resources you use, without needing to pre-provision. Autoscaling storage and I/O helps you optimize for costs because you don’t have to model or guess how much storage and I/O you need each month and provision for peak load, only to pay for underutilized resources.

Per-second billing

Amazon DocumentDB provides per-second billing for instances. Partial instance hours are billed in one-second increments, with a 10-minute minimum charge following a billable status change such as creating, modifying, or deleting an instance. If your temporary workloads require you to provision and delete new instances often, per-second billing can help you save costs by not having to round up partial hours to full hours. Per-second billing is particularly impactful if you’re scaling up large instance types for fast bulks loads and scaling them back down after the load is complete.

Backups

You get backup storage equivalent to 100% of your cluster’s data storage for free each month (for example, if your cluster has 10 TB of stored data, you get 10 TB of backup for free). Additional backup storage beyond the free allotment is priced as low as $0.02 per GB/month (prices may vary across Regions). If you take daily manual snapshots over 30 days, you can optimize for costs by increasing your retention period to 30 days.

The maximum you’re charged for backup storage within your backup window is the size of your storage volume. Any manual snapshots taken outside of your backup window are full backups and count towards your SnapshotStorageUsed. For example, if you have a 100 GiB cluster, your backup window is set to 1 day (by default), and you take a manual snapshot each day for 31 days, your total cost backup cost is 100 GiB – 100 GiB + 30 * 100 GiB) = 30 GiB. A manual snapshot taken within your backup window doesn’t incur additional costs.

To optimize for cost, using the same scenario, if you extend your backup window to 30 days and use the automatic snapshots created each day, your maximum backup is at most 100 GiB. You get one free snapshot and only pay for the incremental during the Retention Period. If data hasn’t changed for 30 days, you don’t pay anything for the backup. Furthermore, instead of daily manual snapshots, which are 30 times more expensive, you can now perform a point-in-time restore at any second with your 31-day backup window.

To control your costs, you can monitor the amount of storage consumed by continuous backups and manual snapshots that persist beyond the retention period. You can reduce the backup retention interval and remove manual snapshots when they’re no longer needed. For more information, see Understanding Backup Storage Usage.

No cost data replication

Amazon DocumentDB doesn’t charge you for data transfer to replicate data between the Amazon DocumentDB instances or the data transfer between your compute instances and the storage layer. For more information, see Amazon DocumentDB pricing.

AWS pricing calculator

You can use the AWS Pricing Calculator to quickly assess your monthly costs. For more information, see Amazon DocumentDB Pricing Calculator.

No upfront costs or long-term commitments

Amazon DocumentDB has transparent and pay-as-you-go pricing. You don’t have to pay any upfront costs or negotiate any long-term contracts, and there are no licenses. We seek to earn your trust every day; you have full control over your resources without being locked into yearly commitments.

Free usage of AWS Database Migration Service

You can use AWS Database Migration Service (AWS DMS) for free (for 6 months) to easily migrate your on-premises or Amazon Elastic Compute Cloud (Amazon EC2) databases to Amazon DocumentDB with virtually no downtime. To learn more, see AWS Database Migration Service: Free DMS.

Conclusion

Amazon DocumentDB provides you with several capabilities to help you estimate, optimize, and monitor your costs. For more information, see Best Practices for Amazon DocumentDB. If you’re new to Amazon DocumentDB, see Getting Started with Amazon DocumentDB. If you are planning to migrate to Amazon DocumentDB, see Migrating to Amazon DocumentDB.

 


About the Author

 

Joseph Idziorek is a Principal Product Manager at Amazon Web Services.