DynamoDB should I use it?

Coder Singh
Towards AWS
Published in
4 min readApr 29, 2021

--

There are a lot of No-SQL Databases out there Dynamo DB is one of them. If you just want to learn about DynamoDB just jump to the DyanmoDB section.

No-SQL Database

No-SQL Databases are that database which is not tabular. Unlike SQL these databases can be a Key-Value Database, Document Database, or Graph Database.

Graph Database

These databases are relation first databases. Unlike SQL Graph Databases treat relationships between data as important as data itself. It can be very useful for scenarios where we have a lot of connected data. So, let's suppose we have a social networking site and there are a lot of users connected to a lot of other users, groups, chats, fan pages, etc. How will you draw a relation between all these in the relation database? Use JOINS? Joins are slow when we will be joining 10 tables together and will pull a lot of redundant and duplicate data but graph databases are opposite they are fast and they will pull out the accurate data which we need to see. Neo4j and ArangoDb are the top databases when we search for the graph databases online.

Document Database

Best used for storing semi-structured documents. The document is nonetheless same as table but with much more flexibility. Document dbs are very hot in the market especially MongoDB. MongoDB is a go to database for lot of young developers and startups. Its easy integration with JavaScript libraries, Monggose.js, gives us an advantage over any other database. A lot of time full-stack developers are called MERN or MEAN stack developers too, where ‘M’ stands for MongoDB. One other example of document database would Firebase database. Firebase too uses document based database. I would only recommend firebase only you are building a very small app with very less functionalities.

Key-Value Database

Key-Value Databases are databases which store data for long or short time usally in memory and we can access a record in o(n) time complexity. We have to make sure the keys stored in the database are unique. By unique I mean we can have 2 users with keys — USER1, USER2 and so on but we cannot have multiple users stores in USER key as we do in SQL we store all uses in one user table. Example of Key-Value database is Dynamo DB, Redis etc.

DynamoDB

We will talk a lot of Dynamo DB I guess. So, let me break if for you:

  1. Why it was built?
  2. How it scales?
  3. Who all are using it?
  4. Pricing?
  5. Should I use it or not?

Why DynamoDB Was Built?

DyanmoDB is an AWS product. And AWS is owned by Amazon.com. In 2004 summer due to high traffic Amazon’s server crashed and they were using Relational Databases. And there was no database in the market that would be able to handle Amazon level load. Werner Vogels, proposed an idea of Dynamo a key-value database which was built for internal tools at Amazon. But it was passed by engineers because it failed the requirement of scalling so they went with some other technology at that time. Later Amazon came up with a better iteration of Dynamo today know as DynamoDB. They automated most of the database management issues.

How DynamoDB Scales?

DyanamoDB uses sharding to scale up. What is sharding? Sharding is dividing mutiple tables/collections of data on multiple servers. Hence, dividing the load and scalling up. In short when ever there is more data we can add servers and it will automatically add more compute and storage to our database. So, in DynamoDB we implement sharding by adding shards to DynamoDB. The more shards we have the load we can handle. Depending upon your requirement you can increase the shards. You would be asking now how data is divided into shards DynamoDB? DynamoDB use B-Tree data structure to store the data in database. B-Tree is a self balanced tree data structure which gives it the power to do almost all database operations in logarithmic time complexity. And use hashed partition key to sort the data for B-tree.

Who all are using DynamoDB?

A lot of Amazon products, AirBnb, BMW, Capital One, Comcast etc. These are the few names but there are thousands of developers and hundreds of customers using it in production.

Pricing

DynamoDB pricing can be very tricky because they do not charge on the basis of memory or compute but read and writes. So, you have to pay for every read and write to the database. If you got millions of users you can imagine the cost it will come with if you use DynamoDB. Is there any way we can solve it? Yes. Use cache service, it will reduce the request to database hence saving us a lot of money. DynamoDB gives us discount too we can write 25 records and it will charge us for one request making a cost divided by 25. So, if you are paying $100 but due to this you will only have to pay $4. Isn’t that crazy? Yes, it is yet pretty difficult to maintain such kind of architecture. Store the write request in cache and once the count is 25 add them all at once in DynamoDB.

Should I use it or not?

It really depends on your situation. I started researching about it in January 2021 for my trading bot. Since it had single digit latency promise. But I realised DynamoDB can be super expensive with the amount of writes we have in trading industry and I need a time-series database not a key-value database. So, I picked timescaledb which is open source, has high write through put and has amazing time series based operations unlike DynamoDB. But does it mean I should not use DynamoDB? No, see what is your use case? If it is building a simple dating app I would built it on DynamoDB or maybe a a game because I need super low latency and ease of scaling. So, look into your product and needs and then decide.

--

--