Skip to Main Content

Why Choose Amazon DynamoDB? Benefits and Trade-offs

Have you ever experienced your website being down at the most crucial moment? That’s how Amazon DynamoDB was born. In this article, we’ll explore the problems that DynamoDB was developed to solve and the benefits that the service can offer to clients who are ‘cloud-native curious’, as well as some potential trade-offs to consider when making the choice to use DynamoDB over traditional relational database technology.

What is Amazon DynamoDB?

Amazon DynamoDB is a fully managed NoSQL database service provided by AWS.

In 2004, at the peak of their Christmas shopping period, a bug in Amazon’s customer database took their entire retail site down for 12 hours. In the aftermath of this catastrophe, the company decided it was time to re-evaluate their traditional relational database model and search for a more performant, scalable and fault-tolerant alternative.

Having found that 90% of all queries to their databases were in search of a single entity, or a group of related entities, from a single table, it became apparent that complex queries via the joins and aggregations facilitated by relational databases and Structured Query Language (SQL) were no longer a priority.

What ultimately emerged was Amazon DynamoDB. Primarily reliant on indexes for querying, DynamoDB was designed to circumvent many of the challenges posed by relational databases, which were devised at a time when the cost of persistent data storage was astronomically high.

To optimise for storage cost, relational databases minimise duplication of data through normalisation – breaking down entities into their own separate tables. SQL provides a flexible way to access this data, but at the cost of computationally expensive joins across multiple tables, which requires the central processing unit (CPU) to reunify tables in a way that is actually useful within an application.

But with computers having since overtaken storage as the most expensive resource, AWS saw the need for a more modern and efficient alternative. Amazon DynamoDB achieves lower compute overhead by permitting a greater degree of duplication, and restricting queries to simple key/value lookups.

Focusing on compute optimisation also enables DynamoDB to scale horizontally with ease, and remain performant no matter how much load it is placed under. This is in stark contrast to traditional relational databases, which have proved notoriously challenging to deploy in a distributed, horizontally scalable fashion in order to cope well with the increased traffic of internet scale applications.

What is a single table design?

Central to DynamoDB’s efficiency is its employment of a single table design, which consolidates multiple types of entities and relationships within a single table, utilising a flexible schema to efficiently manage various data models. Rather than creating separate tables for individual data entities, by consolidating all data into one table, Amazon DynamoDB reduces the need for joins, which can be computationally expensive and slow.

With high volumes of data spanning multiple entities populating a single table, efficient querying might appear problematic. However, DynamoDB facilitates the execution of complex queries and access patterns effectively by encouraging developers to leverage composite primary keys – made up of partition keys and sort keys – and secondary indexes.

Whereas querying against primary keys ensures only the required subset of data is evaluated following each query, secondary indexes provide additional query flexibility without the overhead of maintaining multiple tables by enabling you to rotate the primary key fields used for certain queries.

How does DynamoDB work?

A DynamoDB primary key will typically consist of a partition key and a sort key. The partition key is passed through a hash function to compute a partition identifier, which physically locates the data within one of AWS’s data centres. Amazon DynamoDB partitions data across multiple servers, ensuring an even distribution.

The advantages with regards to scalability are evident. As your database is scaled up, the ‘key space’ of partition keys across your table is simply chopped up into smaller sections, and each of these sections is assigned to a unique partition, ensuring consistent performance no matter the size of your table, or the amount of demand placed on it.

An example of a simple single table design is provided below via our representation of an ‘Orders’ table consisting of two entities – Users and Orders. Both entities share multiple mutual fields, including, crucially, ‘PK’ and ‘SK’ (i.e. the partition key and sort key).

PK SK Name UserId OrderDate OrderTotal OrderNo
USER#123 PROFILE John Doe 123
USER#123 ORDER#001 123 2024-07-13 39.99 001
USER#123 ORDER#002 123 2024-07-16 54.99 002
USER#456 PROFILE Jane Doe 456
USER#456 ORDER#003 456 2024-07-21 79.99 003

Note that both entities share the same partition key structure (‘USER#<UserId>’) but differing sort keys. This design enables the easy retrieval of various subsets of data via the following queries:

Subset Query (pseudocode)
Profile and order history of a specified user PK = USER#<UserId>
Profile of a specified user PK = USER#<UserId> AND SK = PROFILE
Order history of a specified user PK = USER#<UserId> AND SK BEGINS WITH ORDER
Order entry as specified by user and order number PK = USER#<UserId> AND SK BEGINS WITH ORDER#<OrderNo>

This design is particularly beneficial for use cases where data access patterns are well understood and can be planned upfront. Examples include web and mobile applications with predictable query patterns, real-time analytics, and IoT applications where rapid ingestion and retrieval of large volumes of data are critical. 

The single table design also excels in scenarios requiring high scalability and performance, such as online gaming leaderboards, session management, and recommendation engines. 

Is DynamoDB an ACID database?

The term ‘ACID’ in the context of databases refers to a set of properties that ensure reliable processing of database transactions. An acronym which stands for Atomicity, Consistency, Isolation, and Durability, these properties are crucial for maintaining data integrity, consistency, and reliability:

  • Atomicity: Ensures all database operations within a transaction are treated as a single unit, meaning if any part of the transaction fails, the entire transaction is rolled back, and the database is left unchanged
  • Consistency: Maintains the database’s predefined rules – such as constraints, cascades, and triggers – meaning only valid, compliant data can be written into the database, thus preventing data corruption
  • Isolation: Each transaction is executed as if it is the only transaction in the system, preventing data anomalies by ensuring concurrent transactions do not interfere with one another
  • Durability: Once a transaction has been committed, it remains so, even in the event of a system failure, with changes made by a transaction permanently recorded in the database, typically through logging and backup mechanisms

ACID properties are foundational to relational databases. However, for many NoSQL databases, they are often partially relaxed in favour of achieving the high scalability and availability with which these designs are synonymous. This is not the case with Amazon DynamoDB, which provides robust support for ACID properties through its transactional capabilities and consistency mechanisms.

DynamoDB operations such as ‘PutItem’, ‘UpdateItem’, and ‘DeleteItem’ are atomic, whereas its ‘TransactWriteItems’ operation enables you to group multiple write operations into a single transaction, providing atomicity across multiple items and tables. Conditional operations are also available to ensure that updates are performed only if certain conditions are met, helping to prevent conflicts and ensure validity of data changes while satisfying the consistency property.

Transactions are isolated from one another when they are executed, meaning that intermediate states of the transaction are not visible to other operations. Finally, Amazon DynamoDB ensures high durability by storing write operations data across multiple availability zones within an AWS region, guaranteeing the safety of data even in the event of hardware failures.

Is Amazon DynamoDB a suitable database for my organisation?

To guarantee consistent performance at any scale, DynamoDB sacrifices some flexibility in how you are able to query your data in contrast to traditional relational databases. But with careful table design, DynamoDB is still capable of supporting an extensive range of different access patterns. All is not lost on the flexibility front either, as Amazon DynamoDB offers the ability to add secondary indexes in situations where you need to accommodate a requirement for new, unforeseen queries against your data as business needs evolve.

Ultimately though, it is best suited to situations where you are able to predict your data access patterns fairly well in advance, and is particularly advantageous for industries that prioritise high-performance and low-latency. Conversely, DynamoDB is probably best avoided in scenarios where the ability to flexibly query huge amounts of data takes precedence over the need to ensure fast performance under internet-scale traffic, such as in a business intelligence or analytics context.

For most technologists who are comfortable and familiar with the traditional, normalised data modeling of relational databases, rethinking data modeling for DynamoDB can take some getting used to. At Chakray, our cloud development team has the expertise to guide you through the process of data modeling and leveraging DynamoDB’s secondary indexes for a single table design that is optimised for your organisation’s unique requirements.

Conclusion

Amazon DynamoDB offers a robust and scalable solution for organisations looking to optimise the performance and availability of their cloud applications. Its single table design and efficient use of composite primary keys allow it to handle large volumes of data with low latency, while its support for ACID properties ensures data integrity and consistency.

However, it is essential to consider trade-offs, such as limited query flexibility compared to traditional relational databases, and the need for careful table design to anticipate data access patterns.

At Chakray, as an official AWS partner, we have the experience and expertise to guide your organisation in implementing DynamoDB in an optimal way. Our cloud development team is ready to help you design and take full advantage of DynamoDB’s capabilities, ensuring your data infrastructure is ready to meet the challenges. Contact us today!

Contact our team and discover the cutting-edge technologies that will empower your business.

Talk to our experts!

contact us