Database
    🗄️Database

    Amazon DocumentDB

    MongoDB-compatible document database service

    DocumentDB is like a filing cabinet where each file (document) can have a completely different structure. Unlike traditional databases with rigid tables and columns, DocumentDB stores JSON documents, which are flexible, nested data structures. It's MongoDB-compatible, meaning if you're using MongoDB, you can switch to DocumentDB with minimal code changes. AWS handles all the infrastructure: replication, backups, scaling, patching, while you focus on your application. Think of it as managed MongoDB that's deeply integrated with AWS services, more reliable, and easier to scale.

    DocumentDB is a fully managed document database that implements the MongoDB API (version 3.6, 4.0, 5.0 compatibility). It stores data as JSON-like documents in collections. Storage is separated from compute; data is replicated 6 ways across 3 AZs automatically. You can add up to 15 read replicas for read scaling.

    Key Capabilities

    Key features: ACID transactions, change streams (capture document changes for event-driven architectures), and point-in-time recovery.

    Gotchas & Constraints

    Gotcha #1: DocumentDB is MongoDB-compatible, not MongoDB; some features and APIs differ. Test your application thoroughly before migrating. Gotcha #2: DocumentDB uses a shared storage architecture; all replicas read from the same storage layer, so write-heavy workloads can bottleneck on the primary instance. Constraints: Maximum cluster storage is 64TB, single-region deployment (use backup/restore for DR), and limited MongoDB feature support (no map-reduce, some aggregation pipeline limitations).

    A content management system stores articles, user profiles, and comments in MongoDB. Each document has a different structure: articles have title, body, tags; user profiles have name, email, preferences; comments have text, author, timestamp. Managing MongoDB on EC2 is painful: manual replication setup, backup scripts, and scaling challenges. They migrate to DocumentDB, which handles replication, backups, and scaling automatically. They create 5 read replicas to distribute read traffic from the web application. For real-time features, they use DocumentDB change streams to trigger Lambda functions when new comments are posted; Lambda sends notifications via SNS. During traffic spikes, they scale the primary instance from r5.large to r5.4xlarge in minutes without downtime. DocumentDB's automatic backups and point-in-time recovery protect against accidental data deletion.

    The Result

    70% reduction in database management overhead, 99.99% availability, and smooth scaling.

    Official AWS Documentation