0

I'm new to DynamoDB, in our application the access pattern would be something like, display all Orders recently been created. Hence I decided to keep the createdDateTime attribute as range key, while doing data modeling in DynamoDB. Also I've seen many posts recommending to save the dateTime as String in ISO_8601 format. How the sorting will happen in DynamoDB. I want recent first while fetching the list of Orders.

Harish
  • 112
  • 2
  • 14

1 Answers1

1

Wanting to display recently created anything is a relatively common requirement for a lot of different business reasons.

Most often, a couple of things are true:

  1. that the list of ‘most recently created’ tends to be a fixed sized ordered list
  2. that this is a point in time snapshot, and depending on the velocity with which stuff is created, the list may not be accurate even as it is being returned

Saying this, you may consider a secondary system to store the most recently created items, that is not necessarily the same as the place where you store the items themselves.

The approach depends a lot on the velocity with which new items get created. For example, in a system where many new orders get created every second, getting the N most recently created orders could be achieved with a cache, or perhaps some stream processor.

However, if the velocity is closer to an order per hour, get the top N most recent order may be better implemented with something like a single record in Dynamo where you keep the list updated as each new order gets created.

The latter approach works up to the point where you reach about ~300 orders/second. Beyond that, you need something different.

Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151