It sounds like you have unique Items (users, devices, etc) that have a sortable time component (last modified, last login, etc). Your access patterns include fetching the oldest entry across all the items.
It sounds like you have a table that may look something like this:

Users Items are defined with a Partition Key of USER#<user_id> and the Sort Key is a date (could also include time of day, but I've simplified for this example).
If you are trying to search across multiple partitions, you only have access to the scan
operation, which can make access patterns like you describe tricky (and expensive). Let's try a different approach.
Let's define a secondary index (GSI1) with a Partition Key (GSI1PK) of USERS
and Sort Key (GSI1SK) as the time based attribute (updated_at, created_at, etc). That index would look like this:

Lets look at the same table and data from the perspective of GSI1:

Now I've got an Item Collections with a Partition Key of USERS
and a date Sort Key. Since all the User data you want to search is now in a single partition, you can use the query
operation to search across the entire USERS
partition. You could further use the Sort Key to order the results (ScanIndexForward=False
for descending order, ScanIndexForward=True
for ascending order). You can set Limit=1
on your query to fetch the oldest (or latest) Item in that collection.
There are often many ways to implement a given access pattern in DynamoDB. I've seen this specific pattern used to implement the "fetch oldest/latest" access pattern.