top of page

​​​Harshal Bulsara: AWS solution Architect - Assocaite 

How to use DynamoDB effectively

Hi everyone today we are going to discuss DynamoDB which is a Database as a service offered by AWS, it’s a NoSQL database capable for managing a large amount of data effectively. Most of the new Programmer/Database designers had trouble understanding the capabilities of the NoSQL databases because from day 1 we had studied about SQL database and their advantages. I have been working with DynamoDB since 2013, I had developed few applications which were backed by DynamoDB, with DynamoDB if a database is not designed properly then it becomes a nightmare for the programmer to query the database. DynamoDB is a database as a service thus most of the problem needs to be handled at application level. Let us look at all the points that will be helpful while developing the application using DynamoDB.

1) Understand the queries of your application: This is by far the most important analysis that needs to be carried out before building the database, usually in SQL what we do is that we create a database first and then think about how we will query the database. In NoSQL database, it is important that we should understand at least the major queries of the application as there is no joins/relationship between the tables in DynamoDB.

2) Choose proper Data type: It is very important to choose proper data type; if chosen wrongly you might end up keeping very high throughput to your tables and indexes. You can choose between variety of data types such as String, Number, Set, Boolean, List, Map Etc.

3) Choosing key-DynamoDB has 2 types of keys: a. Partition keys: Previously it was called as a hash key, it is same like a primary key, needs to be unique. b. Partition key and Sort key: Previously known as hash and range keys, sometimes single attribute is not capable enough to uniquely identify the row, combination of two attributes will make the row/Item unique We got to choose the Partition key or Partition key and Sort key in such a way that majority of our query should be on these keys and not on the non-key attributes.

4) Indexes: DynamoDB supports 2 types of index a. Local secondary index – A local secondary index would share same partition key as the main table, but it would have different sort key, this would be a light weight index basically used while sorting data. This index will share same throughput capacity from the main table. b. Global secondary index – A Global secondary index will act as a separate table where you can change the partition key and sort key. Global secondary index will have its own throughput and would be separate from the main table.

5) Read Throttle: When using DynamoDB at some point in time your application will suffer from a very high read consumption, by far the most important thing is to design a schema that will be effective. If still your application is consuming more capacity then adding a good caching mechanism would be a big advantage. By implementing caching mechanism we have reduced the bill by 30%-40%.

6) Write Throttle:

If your tables are very write heavy then adding a queuing mechanism would a very effective solution, a queue will add the data to DynamoDB gracefully rather than adding direclty to the database.

Let me know if you have any question in comment section below.

bottom of page