DynamoDB Table Design for Social Media Feeds
A social media application uses Amazon DynamoDB as its primary data store. The application stores user posts and allows users to retrieve the most recent 10 posts of users they follow. The access pattern is a followee-based query that needs to be highly scalable and low-latency. Which DynamoDB table design should the database specialist recommend?
Quick Answer
The correct choice is a composite primary key with a partition key of follower ID and a sort key of timestamp, storing the followee ID as an attribute. This design directly supports the DynamoDB design for social feed recent posts access pattern by co-locating all posts from followed users under a single partition key, while the sort key enables a highly efficient Query with a limit of 10 in descending order to retrieve the most recent posts without scans or secondary indexes. On the AWS Certified Database Specialty DBS-C01 exam, this scenario tests your ability to model access patterns using DynamoDB’s single-table design principles, with a common trap being the temptation to use a global secondary index on followee ID, which would introduce unnecessary overhead and latency. Remember the memory tip: “Follower partitions, timestamp sorts—no scans, just reports.”
⚠ Common exam trap
A common mix-up: candidates choose Option D because they think a GSI on followee ID solves the query pattern, but they overlook that the base table's partition key (user ID) does not match the follower-based access pattern, requiring multiple queries or a Scan, and the GSI still incurs additional latency and cost for index maintenance.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use a composite primary key with a partition key of follower ID and a sort key of timestamp, and store the followee ID as an attribute
It models the access pattern directly: the follower ID as the partition key ensures all posts from followed users are co-located, and the sort key of timestamp allows efficient retrieval of the most recent 10 posts via a Query with a limit of 10 and descending order. This design avoids expensive scans or secondary index lookups, meeting the low-latency and scalability requirements.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a partition key of post ID and a local secondary index on the followee ID
Why it's wrong here
Partition key as post ID does not support querying by follower or followee efficiently.
- ✗
Use a single table with a scan operation and filter on the followee attribute
Why it's wrong here
Scan operations are expensive and not recommended for low-latency access patterns.
- ✓
Use a composite primary key with a partition key of follower ID and a sort key of timestamp, and store the followee ID as an attribute
Why this is correct
This design allows efficient Query on the follower ID to retrieve recent posts in reverse order by timestamp.
- ✗
Design the table with a partition key of user ID and a sort key of timestamp, and create a global secondary index (GSI) on followee ID
Why it's wrong here
A GSI with followee ID as partition key might still lead to hot partitions if a popular user has many followers.
Go deeper
Related to this question
About these practice questions
This DBS-C01 question is part of Courseiva's 1,663-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on DBS-C01
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A social media application uses Amazon DynamoDB with a table that has a partition key of 'user_id' and a sort key of 'post_timestamp'. The application frequently queries for the 10 most recent posts by a specific user. The query pattern uses a 'begins_with' condition on the sort key with a timestamp prefix. Recently, the query latency has increased significantly for users with many posts. Which design change would improve query performance?
hard- ✓ A.Create a local secondary index (LSI) with 'user_id' as partition key and 'post_timestamp' as sort key, and query using reverse order with a limit of 10.
- B.Enable DynamoDB Accelerator (DAX) to cache the query results.
- C.Create a global secondary index (GSI) with 'post_timestamp' as partition key and 'user_id' as sort key.
- D.Change the table's partition key to 'post_id' to distribute data more evenly.
Why A: The optimal approach to retrieve the 10 most recent posts for a user is to query the table or an index with the partition key 'user_id' and use ScanIndexForward=false with a Limit of 10. Option A achieves this by creating a Local Secondary Index (LSI) with the same partition key and sort key as the base table. While the base table itself can be queried in reverse order, creating an LSI dedicated to this query pattern can improve performance by offloading reads from the base table index, reducing contention and ensuring fast consistent reads. The LSI can be provisioned with its own read capacity to handle the frequent queries for the most recent posts per user, thus improving overall query performance. Options B, C, and D do not effectively address the specific requirement of per-user recent posts. Option B (DAX) may reduce latency but does not fix the underlying inefficient query pattern (scanning many items per user). Option C (GSI with timestamp as partition key) would allow querying posts globally by time, not per user. Option D (changing partition key to post_id) would break the ability to query all posts by a user. Therefore, Option A is the correct design change.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DBS-C01 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DBS-C01 exam.