Database
    🗄️Database

    Amazon DynamoDB

    Fast, flexible NoSQL database with single-digit millisecond latency

    Imagine a massive spreadsheet that can handle millions of rows and thousands of people reading and writing to it simultaneously, and every lookup takes less than 10 milliseconds, faster than you can blink. That's DynamoDB. Unlike traditional databases where you design tables with rigid columns, DynamoDB is flexible; each row (item) can have different attributes. You organize data by a partition key (like a filing cabinet drawer) and optionally a sort key (like tabs within that drawer). Need to find something? Give DynamoDB the key, and it retrieves it in milliseconds, no matter if you have 10 rows or 10 billion. It's like having a librarian who's memorized the location of every book and can fetch any one in the blink of an eye, even if the library is the size of a city.

    DynamoDB is a fully managed NoSQL database that stores data as items (rows) in tables, with each item containing attributes (key-value pairs). You define a partition key (required) and optionally a sort key (together forming the primary key). DynamoDB distributes data across partitions based on the partition key hash; this enables horizontal scaling. You choose between on-demand (pay per request) or provisioned capacity (specify read/write units).

    Key Capabilities

    Key features: Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI) enable querying on non-key attributes. DynamoDB Streams capture item-level changes for event-driven architectures. Point-in-time recovery and on-demand backups protect data.

    Gotchas & Constraints

    Gotcha #1: Hot partitions; if your partition key has low cardinality (e.g., status='active' for 90% of items), you'll overload specific partitions, causing throttling. Use high-cardinality keys like user_id or order_id. Gotcha #2: GSIs are eventually consistent by default and consume separate read/write capacity; under-provisioning GSIs causes throttling even if the base table has capacity. Constraints: Item size limited to 400KB; queries return max 1MB per request (use pagination for more). Strongly consistent reads cost 2x eventually consistent reads.

    A mobile gaming company stores player profiles, game sessions, and leaderboards for 10 million active users. They use DynamoDB with partition key user_id and sort key timestamp for game sessions, enabling fast queries like 'get all sessions for user X' or 'get user X's last 10 sessions.' For leaderboards, they create a GSI with partition key game_level and sort key score, allowing queries like 'top 100 players for level 5.' During a new game launch, traffic spikes 10x; DynamoDB auto-scales from 1,000 WCU to 10,000 WCU in minutes without downtime. They enable DynamoDB Streams to trigger Lambda functions that update real-time analytics in ElastiCache and send push notifications via SNS when players achieve milestones. Point-in-time recovery protects against accidental deletes.

    The Result

    sub-10ms latency at any scale, zero database administration, and 60% cost savings vs. managing RDS with read replicas.

    Official AWS Documentation