Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB most efficient date type

I see that DynamoDB is essentially limited to three data types: String, Number, and Binary. That seems to leave two options for storing a date or timestamp:

  • String of an 8601 date/time format or Unix timestamp
  • Number of a Unix timestamp

I will need to 'sort' results by using this date/timestamp as a range key and using scanIndexForward. Is it possible to say which approach would be more efficient?

like image 883
Eric Di Bari Avatar asked Apr 09 '14 12:04

Eric Di Bari


People also ask

Is DynamoDB good for time series data?

This takes out the guesswork of provisioning read and write units and you simply pay for what you use. All that to say, DynamoDb can work well for time series data, and can be much faster at querying the data, but you need to carefully consider how you need to access it.

How does DynamoDB store dates?

There are multiple ways to represent a timestamp in DynamoDB. Probably the most common is to use a Number type to represent the timestamp with the value as a Unix timestamp (seconds or milliseconds). Additionally, you can store the timestamp as a String type with the value as an ISO 8601 formatted string.

Does DynamoDB support strong consistency?

DynamoDB supports eventually consistent and strongly consistent reads. When you read data from a DynamoDB table, the response might not reflect the results of a recently completed write operation.

Is DynamoDB TTL real time?

Amazon DynamoDB Time to Live (TTL) allows you to define a per-item timestamp to determine when an item is no longer needed. Shortly after the date and time of the specified timestamp, DynamoDB deletes the item from your table without consuming any write throughput.


1 Answers

I don't know that it's necessarily more efficient, but we have had good success using a Unix timestamp as range keys. It's been fast (under 20ms latency, sometimes under 10ms) for queries and lets us sort "earliest to latest" or "latest to earliest" using the scanIndexForward flag.

The downside is that when looking at the raw tables it can be tough to compare two timestamps at a glance, but it's easy enough to convert a timestamp into a date-type in your language of choice.

like image 154
rpmartz Avatar answered Sep 28 '22 06:09

rpmartz