What are Best Practices for Using Amazon DynamoDB?

Upasana | July 26, 2018 | 2 min read | 64 views | Amazon DynamoDB

Best Practices

  1. Amazon DynamoDB is good fit for NoSql kind of data, if you have lot of relationships between different entities, then better off using MySql or RDBMS.

  2. Do not use transactions that span across tables in Amazon DynamoDB, if there is any such strong need, then better use a RDBMS. You can achieve some sort of eventual consistency can be achieved in DynamoDB using SQS.

  3. Correctly model your domain objects using Hash Key, Range Key, Local Secondary Index and Global Secondary Indexes.

  4. Use Auto Scaling option of Amazon DynamoDB to dynamically increase provisioned throughput as the need arises.

  5. Use atomic update operations to update shared records from multiple threads, this will save some cost and resources.

  6. For handling spike in write operations, user some kind of Queue (either Amazon SQS or Redis), this will not only bring resiliency to the system but also reduce the cost.

  7. Use Spring Retry to handle write failures. Spring retry gives flexibility of exponential backoff, which could be quite helpful under heavy load conditions.

How not to use DynamoDB

  1. Amazon DynamoDB is not a single fit for all your database needs. Use it only when you can afford the budget and requirements fit into NoSql world.

  2. If your application has strong transcational needs as well as NoSql needs, better to use RDBMS for transactional work and NoSql for everything else. In microservices architecture, for example, you can partition the application into multiple microservices and then each microservice can pick either NoSql or RDBMS as per its business requirement.

  3. Do not model data into dynamoDB from object relational mindset as we do it in RDBMS. Denormalizing data is the key concept in NoSql world. For example, if you want to store Tags with an Article, put them all into one object, one table rather than creating separate table for Article and Tags.

Top articles in this category:
  1. Scan all records of a Amazon DynamoDB table using a Java Code
  2. How to implement Atomic Counters in DynamoDB for high throughput
  3. How will you ensure that no two threads update the same db record in parallel in amazon DynamoDB
  4. How to automatically Retry DynamoDB Write on ProvisionedThroughputExceededException
  5. AWS DynamoDB Java interview questions
  6. What are Conditional Writes in AWS DynamoDB
  7. What is Eventual Consistency in DynamoDB?

Recommended books for interview preparation:

Find more on this topic:
Buy interview books

Java & Microservices interview refresher for experienced developers.