Gaelan
Gaelan

Reputation: 1149

DynamoDB architecture for getting recent articles

I'm working on an intranet app, where one of the requirements is to display recent news from inside the company. This thing doesn't need to be "webscale"--we have less than 20,000 users, and of course they won't all be logging in at the same time. We're going with DynamoDB not so much because we need its scalability, but more because it's fairly cheap and easy to use from Lambda (where our app code will run).

With all that being said, I need a way to display the most recent, say, 5 news articles. I can think of two ways to do this:

  1. Use timestamp as the partition key. Get most recent articles by doing a Scan then sorting on timestamp.
  2. Use the same partition key for all posts, and make timestamp the sort key. Use the sort key to get recent articles.

I know neither of these is ideal or playing to DynamoDB's strengths, but is one of them "less bad"? I'm also open to other solutions, of course.

Upvotes: 0

Views: 55

Answers (1)

Rafael Almeida
Rafael Almeida

Reputation: 10712

Option 2 (or a variant) looks better. Query on the timestamp sort index with ScanIndexForward = false to achieve descending order. Timestamp value can either be a numeric timestamp or ISO format string (YYYY-DD-MM HH:mm:ss) - either is sortable.

For the partition key, you can either use a dummy value for all records (but make it short to save space), or a subset of the timestamp (year or year-month).

Upvotes: 1

Related Questions