Book Image

DynamoDB Applied Design Patterns

By : Uchit Hamendra Vyas
Book Image

DynamoDB Applied Design Patterns

By: Uchit Hamendra Vyas

Overview of this book

Table of Contents (17 chapters)
DynamoDB Applied Design Patterns
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

DynamoDB versus Redis


Both DynamoDB and Redis are NoSQL databases that store the data in key-value format. But Redis is an open source database provided by BSD. Redis means Remote Dictionary Server. It is often called a data structure server as its key contains many data types, such as string hashes, in which the key and values are string, sorted sets of strings, stored sets, and lists of strings. We can perform atomic operations in Redis. Redis stores the whole dataset in memory, so we can persist it by dumping the data to disk, because Redis synchronizes data to the disk every 2 seconds. So if the system fails, we lose the data for only a few seconds. Another way to persist it is by appending each command to the log.

Redis supports master-slave replication, which allows the slave Redis server to be the same copy of the master Redis server with non-blocking replication. On the master-side server, it will handle queries when one or more slaves perform initial synchronization. On the other side, while the slave server performs initial synchronization, it will still handle queries using the old dataset. But in DynamoDB, replication is done at a scheduled time; a continuous data replication is not performed. So in this case, if a primary DynamoDB table loses its data, there can be data loss while restoring from the backups. In Redis, slaves, are able to accept connections from several slaves apart from slaves from the same master server. But in DynamoDB, the tables should be on the same AWS account.

Other features of Redis include transactions, pub/sub, Lua scripting capabilities, keys with a restricted time to live, and other configuration settings, which will allow Redis to work like a cache. Redis is written in ANSI C and works in almost all operating systems, such as Linux, BSD, and OS X without any external dependencies.

While data durability is not the major concern, the in-memory environment of Redis allows it to perform extremely well compared to database systems that write every update or change to disk before allowing a committed transaction. There is no prominent speed difference between read and write IOs. Redis works as a single process and is single-threaded. Hence a single Redis instance cannot apply parallel execution of tasks such as stored procedures. Redis is mainly used for rapidly changing data with a predictable database size that should mostly fit in-memory. So Redis is used in real-time applications such as storing real-time stock prices, real-time communication, real-time analytics, and leaderboards. We can use it as an option for memory cache too. Let's move on to the tabular comparison between these databases, as follows:

Specification

DynamoDB

Redis

Data model

Key-value store

Key-value store

Operating system

Cross platform (hosted)

BSD

Linux

OS X

Solaris

Programming language

Ruby

C

License

Commercial (Amazon)

Open source with BSD-license

Data storage

Solid-state drive (SSD)

In-memory dataset (RAM)

Secondary indexes

Yes

No

Accessing method

RESTful HTTP API call

API call

Lua

Server-side script

No

Lua

Triggers

No

No

Partitioning

Sharding

None

MapReduce

No (can be done with other services of AWS)

No

Composite key support

Yes

No

Atomicity

Yes

Yes

Data consistency

Yes

Yes

Isolation

Yes

Yes

Durability

Yes

Yes

Transactions

No

Optimistic locking

Concurrency control

ACID

Locks

Partition tolerance

No

Yes

Persistence

No

Yes

High availability

Yes

No

Referential integrity

No

No

Revision control

Yes

No

Function-based index

Yes

No

Full text search

No

No

Geospatial indexes

No

No

Horizontal scalability

Yes

Yes

Replication method

Master-slave replica

(asynchronized)

Master-slave replica

(synchronized)

Largest value supported

64 KB

512 MB

Object-relational mapping

No

Yes

Log support

No

Yes

Operations per second

1000

140000

Free for commercial use

No

Yes (Up to some memory usage)

Deployment policy

Only with AWS

On premises

Easy to use

No

Yes

Backup

Scheduled (to configure)

Autosync frequently

User concepts

Access rights for users and roles can be defined via the AWS Identity and Access Management (IAM)

A very simple password-based access control

Best use

Rapidly varying data, frequently written, rarely read statistical data

Large to small database solution

So as per the previous comparisons, you can easily identify the most suitable NoSQL data service to work with your dynamic applications. In short, it provides the following features on the Amazon-distributed infrastructure and robust platform:

  • Seamless scaling

  • Secondary indexes

  • Schema-less

  • Strong consistency, atomic counters

  • Integrated monitoring

  • Secure

  • Elastic MapReduce and Redshift, and data-pipeline integration

  • Management console and APIs