This is a schema design question; implementation is going to be Mongo, but answers are platform agnostic.

  • Given an app, which has users, sessions, and items.
  • All visitors will have a session associated with them, but this is a transient row, while user id is associated with them after authentication;
  • I want to be able to assign an item to anonymous sessions/users, preferably in a single field, and retain the item association forever.
  • Use cases are eg usage data, and survey results; app is heavily interactive, so this schema will interact with most user data on some level

How would you design the item - user - session schema keying?

The design considerations here are: anon user registrates (should merge current anon items with user's items), logs out (should no longer hold the items), logs back again (should merge current anon items, with user's items)

Specifically considered so far:

  • keeping the sessions forever, associating items with sessions only, as per this SO answer. I feel this would blow up, as most of the info from a session isn't long-term relevant
  • creating a new user for each anonymous session, and keying item to the user (would create lots of empty users);
  • keying item to either/or session/user (requires 2 fields)

Any ideas for a clean design?

  • If you're going to go with Mongo, you had the advantage of being able to shift your schema on the fly - I'd just start building out the application and update it as you go in this case. Otherwise, this is a fairly broad question. If size is an issue for you, look at sharding the data. – LowlyDBA Aug 23 '19 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.