Migrating 1.1 billion MongoDB documents to Amazon DocumentDB
A production migration with AWS DMS that was first estimated to take about 21 days. This is what went wrong and how I brought the estimate under 24 hours.
At a glance
- Client
- a B2B platform that collects telemetry from field devices (name withheld)
- My role
- planning and carrying out the migration
- Source
- MongoDB 6.0.5 on EC2
- Target
- Amazon DocumentDB 8.0
- Data
- about 300 GB, over 1.1 billion documents, one collection with 13 indexes
- Method
- AWS DMS, Full Load + CDC (continuous replication until cutover)
- Key result
- Full Load estimate cut from about 21 days to under 24 hours
The challenge
Move a production database from MongoDB on EC2 to Amazon DocumentDB, keeping data in sync until cutover and stopping the application for as little time as possible.
13 active indexes on the target
≈ 600 rows per second
≈ 21 days
Indexes removed before the Full Load
≈ 20 times faster
under 24 hours
These are estimates, not measurements: the Full Load with active indexes was never run to completion.
What went wrong
- The initial load slowed down every hour. With 13 indexes active on the target, throughput fell to about 600 rows per second, which would have meant about 21 days of Full Load.
- CDC looked healthy but applied nothing. DocumentDB limits index key values to 1,024 bytes; MongoDB 6.0 did not enforce this in the same way. A few documents with an abnormal field made whole batches of changes fail, with no obvious task error.
- A replica set and a larger oplog were required. Converting from standalone to replica set needs a precise order of operations, and the oplog has to be sized for the Full Load duration, not for normal traffic.
- The DocumentDB instance was too small for the indexes. On an r6g.large the temporary storage ran out during index creation.
What I did
- I removed all indexes from the target before the Full Load and rebuilt them afterwards, during CDC.
- I found the abnormal documents with
mongoexportand moved them into a quarantine collection instead of deleting them, adding data validation in the application. The collection became a permanent part of the architecture and shows where malformed data comes from. - I used a constant-performance DMS replication instance (r6g.large) and, only for index creation, a DocumentDB r6g.2xlarge, later reduced to a t4g.medium for production.
- I sized the oplog and the change stream retention for the expected Full Load duration.
- Replica set from standalone to replica set, in the right order
- Oplog sized for the Full Load duration
- Full Load with no indexes on the target
- Indexes rebuilt during CDC
- Cutover and a rollback plan ready
The result
- Full Load estimate: from about 21 days to under 24 hours (roughly 20 times faster).
- Working CDC, with malformed data isolated and available for analysis.
- Production instance sized down to keep costs under control.
What I bring to your project
- A data check before starting, to find the target database’s limits.
- A one-hour trial run to measure real speed and size everything accordingly.
- Monitoring and alarms in place before problems appear.
- A cutover and rollback plan written in advance.
Do you need to migrate a database? Tell me about your situation.
Tell me about your situation