1. You are designing the row-key strategy for a Bigtable table that stores user activity logs. The table will be used for both real-time queries (looking up specific users' recent activities) and batch analytics (scanning activity by time range). User IDs are randomly distributed UUIDs, and timestamps are from a continuous stream. Which row-key design minimizes hotspotting and supports both query patterns?
- A. Use timestamp as the row-key prefix, followed by user ID (e.g., ts#userID). This ensures chronological ordering and prevents hotspot concentration on recent data.
- B. Reverse the timestamp bytes and prepend user ID (e.g., userID#reversed_ts). This distributes writes evenly across tablets while allowing efficient range scans by time.
- C. Use a hash of user ID as a prefix followed by timestamp (e.g., hash(userID)#ts). This distributes load across tablets and allows both user-specific and time-range queries.✓ Correct
- D. Use user ID as the sole row-key with timestamp stored as a column family qualifier. This optimizes real-time lookups but will cause hotspotting during batch time-range scans.
Explanation
The correct answer is option 3: hashing the user ID prefix ensures writes are distributed evenly across Bigtable tablets (avoiding hotspots), while the timestamp suffix still allows efficient range scans by time within each user's partition. This balances both query patterns. Option 1 fails because timestamps increase monotonically; recent activity will concentrate writes on a single tablet (hotspotting). Option 2 reverses the timestamp but doesn't solve hotspotting if writes cluster around current time. Option 4 optimizes only for user lookups and causes severe hotspotting on recent timestamps during batch scans.