12 Programming for the NoSQL database service: DynamoDB

 

This chapter covers

  • Advantages and disadvantages of the NoSQL service, DynamoDB
  • Creating tables and storing data
  • Adding secondary indexes to optimize data retrieval
  • Designing a data model optimized for a key-value database
  • Optimizing costs by choosing the best fitting capacity mode and storage type

Most applications depend on a database to store data. Imagine an application that keeps track of a warehouse’s inventory. The more inventory moves through the warehouse, the more requests the application serves and the more queries the database has to process. Sooner or later, the database becomes too busy and latency increases to a level that limits the warehouse’s productivity. At this point, you have to scale the database to help the business. You can do this in two ways:

  • Vertically—You can use faster hardware for your database machine; for example, you can add memory or replace the CPU with a more powerful model.
  • Horizontally—You can add a second database machine. Both machines then form a database cluster.

Scaling a database vertically is the easier option, but it gets expensive. High-end hardware is more expensive than commodity hardware. Besides that, at some point, you will not find more powerful machines on the market anymore.

12.1 Programming a to-do application

12.2 Creating tables

12.2.1 Users are identified by a partition key

12.2.2 Tasks are identified by a partition key and sort key

12.3 Adding data

12.3.1 Adding a user

12.3.2 Adding a task

12.4 Retrieving data

12.4.1 Getting an item by key

12.4.2 Querying items by key and filter

12.4.3 Using global secondary indexes for more flexible queries