Basics of DynamoDB:
What is Amazon DynamoDB?
- Answer: Amazon DynamoDB is a fully managed NoSQL database service provided by AWS that offers fast and predictable performance with seamless scalability.
Explain the key features of DynamoDB.
- Answer: Key features include automatic scaling, high availability, durability, seamless backup and restore, and low-latency performance.
What are the primary key types in DynamoDB?
- Answer: DynamoDB supports two primary key types: Partition Key (also known as Hash Key) and Composite Key (Partition Key + Sort Key).
How does DynamoDB achieve scalability and high availability?
- Answer: DynamoDB achieves scalability and high availability by distributing data across multiple partitions and replicating data across multiple Availability Zones.
What is the consistency model in DynamoDB?
- Answer: DynamoDB provides eventual consistency by default, but it also allows users to choose strong consistency when reading data.
Data Modeling in DynamoDB:
Explain the concept of Item, Attribute, and Table in DynamoDB.
- Answer: Items are individual records in a table, attributes are the data elements within items, and tables are the collections of items.
What is a Partition Key?
- Answer: The Partition Key is a unique identifier for an item in DynamoDB, and it determines the partition (physical storage) where the item is stored.
When would you use a Composite Key in DynamoDB?
- Answer: Composite keys are used when the uniqueness of an item is determined by a combination of two attributes: Partition Key and Sort Key.
How do you perform a conditional write in DynamoDB?
- Answer: Conditional writes are performed using the
ConditionExpression
parameter, allowing you to write an item only if certain conditions are met.
- Answer: Conditional writes are performed using the
Explain the concept of Local Secondary Index (LSI) in DynamoDB.
- Answer: LSI is an index with the same partition key as the base table but a different sort key. It allows for querying data with a different sort order.
DynamoDB Queries and Scans:
What is the difference between a Query and a Scan in DynamoDB?
- Answer: A Query is used to retrieve items based on the key condition, while a Scan reads all items in a table and filters the result based on specified conditions.
How can you efficiently query data in DynamoDB?
- Answer: Efficient querying involves designing tables with appropriate partition keys and sort keys, and using Global Secondary Indexes (GSIs) when needed.
Explain the concept of FilterExpression in DynamoDB.
- Answer: FilterExpression is used to further filter the results of a Query or Scan after the initial conditions are met.
When should you use a Global Secondary Index (GSI) in DynamoDB?
- Answer: GSIs are used when you need to query data based on attributes other than the table's primary key.
What is the significance of the ProjectionExpression parameter?
- Answer: ProjectionExpression is used to specify the attributes that should be included in the result of a Query or Scan.
DynamoDB Capacity and Throughput:
How does DynamoDB handle scaling?
- Answer: DynamoDB automatically scales by partitioning data across multiple servers and adjusting the number of partitions based on demand.
Explain the concepts of Provisioned Throughput and On-Demand Capacity in DynamoDB.
- Answer: Provisioned Throughput requires users to specify the desired read and write capacity, while On-Demand Capacity automatically adjusts based on actual usage.
What is a Write Capacity Unit (WCU) and a Read Capacity Unit (RCU) in DynamoDB?
- Answer: WCU represents one write per second for an item up to 1 KB, and RCU represents one strongly consistent read per second for an item up to 4 KB.
How can you monitor and optimize DynamoDB throughput?
- Answer: Monitoring tools like CloudWatch can be used to track throughput metrics, and optimization involves adjusting provisioned capacity and improving data access patterns.
Explain the concept of Auto Scaling in DynamoDB.
- Answer: Auto Scaling automatically adjusts provisioned throughput capacity in response to changes in demand.
DynamoDB Indexing:
What is a Global Secondary Index (GSI) in DynamoDB?
- Answer: A GSI is an index with a partition key and optional sort key that is different from the table's primary key.
Can you add a Global Secondary Index to an existing DynamoDB table?
- Answer: Yes, you can add a GSI to an existing table using the
UpdateTable
operation.
- Answer: Yes, you can add a GSI to an existing table using the
Explain the concept of Local Secondary Index (LSI) in DynamoDB.
- Answer: An LSI is an index that has the same partition key as the base table but a different sort key.
When would you use a Local Secondary Index instead of a Global Secondary Index?
- Answer: LSIs are useful when you need to query data within the same partition key as the base table.
How do you choose between GSI and LSI in DynamoDB?
- Answer: Choose GSI when you need to query across partition keys, and LSI when you need to query within the same partition key.
DynamoDB Streams:
What is DynamoDB Streams?
- Answer: DynamoDB Streams capture changes to items in a table and allow for responding to these changes in real-time.
How can you enable DynamoDB Streams on a table?
- Answer: Streams can be enabled when creating a table or by modifying an existing table using the
UpdateTable
operation.
- Answer: Streams can be enabled when creating a table or by modifying an existing table using the
Explain the concept of the Shard in DynamoDB Streams.
- Answer: A Shard is a sequence of stream records in DynamoDB Streams, and it represents a unit of parallel processing.
What are the use cases for DynamoDB Streams?
- Answer: Use cases include data replication, change notification, and maintaining secondary indexes.
How do you consume and process records from DynamoDB Streams?
- Answer: Consumers can use AWS Lambda or other applications to process records from DynamoDB Streams.
DynamoDB Backup and Restore:
What is the importance of backup in DynamoDB?
- Answer: Backups in DynamoDB provide a way to recover data in case of accidental deletion or corruption.
How can you perform a backup in DynamoDB?
- Answer: Backups can be performed using on-demand backup, continuous backups, or point-in-time recovery.
Explain the difference between on-demand backup and continuous backup in DynamoDB.
- Answer: On-demand backup is manually triggered, while continuous backup is automatically performed and allows for point-in-time recovery.
What is Point-in-Time Recovery (PITR) in DynamoDB?
Answer:* PITR allows you to restore a table to any specific point in time within the last 35 days.
- How do you restore a DynamoDB table from a backup?
- Answer: You can restore a table using the
RestoreTableToPointInTime
operation.
- Answer: You can restore a table using the
Security in DynamoDB:
How is data encrypted in DynamoDB?
- Answer: Data at rest is encrypted by default, and you can enable server-side encryption for data in transit using HTTPS.
Explain the role of AWS Identity and Access Management (IAM) in DynamoDB.
- Answer: IAM is used to control access to DynamoDB resources, allowing you to specify who can access which resources and what actions they can perform.
What are fine-grained access controls in DynamoDB?
- Answer: Fine-grained access controls allow you to control access to individual items or attributes in a table.
How do you implement data validation and input validation in DynamoDB?
- Answer: You can use conditional expressions and input validation to ensure data integrity and validity.
What is the significance of the
ExpressionAttributeValues
parameter in DynamoDB?- Answer:
ExpressionAttributeValues
is used to substitute values in expression strings, providing a way to avoid hardcoding values in queries.
- Answer:
Advanced DynamoDB Concepts:
What is the significance of Consistent Reads in DynamoDB?
- Answer: Consistent Reads in DynamoDB provide a read-after-write consistency, ensuring that reads reflect the most recent write.
Explain the concept of Conditional Writes in DynamoDB.
- Answer: Conditional Writes allow you to write an item to the table only if certain conditions are met.
What are the best practices for designing efficient DynamoDB tables?
- Answer: Best practices include choosing appropriate partition keys, using GSIs wisely, and avoiding hot keys.
How does DynamoDB handle hot keys, and what are the implications?
- Answer: Hot keys can lead to uneven distribution of workload, and DynamoDB mitigates this by automatically splitting and merging partitions.
What is the purpose of the
BatchWriteItem
operation in DynamoDB?- Answer:
BatchWriteItem
allows you to write or delete multiple items across multiple tables in a single request.
- Answer:
DynamoDB and Serverless Architecture:
How can you integrate DynamoDB with AWS Lambda?
- Answer: AWS Lambda functions can be triggered by DynamoDB Streams, allowing for real-time processing of changes.
What is the role of Amazon API Gateway in DynamoDB applications?
- Answer: API Gateway can be used to create RESTful APIs for DynamoDB, allowing for external applications to interact with the database.
Explain the concept of DynamoDB Accelerator (DAX).
- Answer: DAX is an in-memory caching service that can be used to speed up read-intensive DynamoDB workloads.
What are the advantages of using DynamoDB with AWS AppSync?
- Answer: AppSync simplifies the process of developing GraphQL APIs for DynamoDB, providing features like real-time data synchronization.
How does DynamoDB fit into a serverless architecture?
- Answer: DynamoDB is a fully managed and serverless NoSQL database service, making it well-suited for serverless architectures where infrastructure management is abstracted.