I’m building a system that needs to track what users do so I can customize their interface based on their activity. The main goal is to make the UI adapt to user behavior patterns.
My scenario:
I have a many-to-many relationship between Users and Projects. When a user views their project list, I want to show the most recently accessed projects first.
Current approach I’m considering:
Create an activity tracking table with this structure:
{
userId: 42,
entityId: 15,
actionType: 'click',
entityType: 'project',
timestamp: '2022-07-15 14:30',
// other fields
}
When users request their project list, I would:
- Query the activity table for recent project interactions
- Sort projects based on this data
- Return the customized list
Alternative option:
Add tracking fields directly to the projects table (like lastViewedAt, viewCount, etc.)
My question:
What’s the recommended architecture pattern for this kind of user activity logging? Should I use a separate activity table, modify existing tables, or is there a better approach I’m missing?
Looking for advice on scalability and maintainability. Thanks for any suggestions!