I have a dynamodb table with the following structure
userId -> hashkey
timestamp -> sortkey
//other fields
I have two primary queries I want to execute on this table.
- Get all entries for a user -> This is straight forward, as I can do query on the hashkey
- Get recent N entries -> Not sure what is the best way to do this. I will be displaying these in UI so I need to do paging. Should I use SCAN? or Create a GSI on timestamp and use Query?
Any other suggestions? Thank you.
Update 05/14 There are great suggestions posted here. I am still trying to figure how best to implement this and wanted to check the pros/cons of the following approach.
Trips:
Id -> this is a GUID generated by the API that is inserting data to dynamo
timestamp -> sortkey
//other details
UserTrips:
userId -> hashkey
tripId -> id from trips table
RecentTrips:
timeKey -> YYYYMM format hash key
tripId -> id from trips table
I am afraid that this might create lot of inconsistencies as if insertion to usertrips or recenttrips fail etc.