Amazon DynamoDB Interview Questions and Answers for 10 years experience
-
What are the core concepts of DynamoDB?
- Answer: DynamoDB's core concepts include tables (key-value stores), items (rows), attributes (columns), primary keys (partition key and optionally a sort key), secondary indexes (global and local), capacity units (read and write), and consistency models (strong and eventual).
-
Explain the difference between partition key and sort key.
- Answer: The partition key uniquely identifies an item within a table and distributes data across multiple partitions. The sort key further orders items within each partition, enabling efficient querying based on a secondary attribute. A partition key is mandatory; a sort key is optional.
-
What are Global Secondary Indexes (GSIs) and Local Secondary Indexes (LSIs)? When would you use each?
- Answer: GSIs are secondary indexes that allow querying on a non-key attribute. They have their own partition key and sort key, providing independent querying capabilities. LSIs are built on the primary key of the table and share the same partition key but have a different sort key. GSIs are better for complex queries on non-key attributes; LSIs are more efficient for queries on the primary key's sort key if you require different ordering.
-
Explain DynamoDB's capacity planning. Why is it crucial?
- Answer: DynamoDB uses a provisioned capacity model. You specify read and write capacity units (RCUs and WCUs) in advance. This controls how much data can be read or written per second. Accurate capacity planning is critical to ensure your application's performance and prevent throttling. Under-provisioning leads to slowdowns, while over-provisioning wastes resources.
-
How do you handle hotspots in DynamoDB?
- Answer: Hotspots occur when a single partition key receives a disproportionate amount of traffic. Solutions include: designing a composite partition key (incorporating additional attributes to distribute the load), using GSIs to offload queries, implementing sharding strategies, and adjusting capacity settings.
-
Describe DynamoDB's consistency models.
- Answer: DynamoDB offers strong and eventual consistency. Strong consistency guarantees that reads always return the most up-to-date data. Eventual consistency means reads may return stale data for a short period after a write. The choice depends on the application's tolerance for stale data; strong consistency is more robust but can be slower.
-
How do you optimize DynamoDB queries for performance?
- Answer: Optimization strategies include using appropriate indexes (GSIs or LSIs), filtering data server-side (using `FilterExpression`), using efficient query patterns (avoiding full table scans), batching operations, and carefully choosing data types and partition key strategies.
-
Explain DynamoDB transactions. What are their limitations?
- Answer: DynamoDB supports atomic transactions using the `TransactWriteItems` API. This allows multiple operations (Get, Put, Update, Delete) to be performed atomically. Limitations include a maximum of 25 operations per transaction and limitations on the types of operations.
-
How do you handle data backups and restores in DynamoDB?
- Answer: DynamoDB offers point-in-time recovery (PITR) and on-demand backups. PITR allows you to restore the table to a specific point in time. On-demand backups are manual snapshots you can create and restore.
Thank you for reading our blog post on 'Amazon DynamoDB Interview Questions and Answers for 10 years experience'.We hope you found it informative and useful.Stay tuned for more insightful content!