educative.io

Educative

Query about data model in Instagram design problem

" We need to store relationships between users and photos, to know who owns which photo. We also need to store the list of people a user follows. For both of these tables, we can use a wide-column datastore like Cassandra. For the ‘UserPhoto’ table, the ‘key’ would be ‘UserID’ and the ‘value’ would be the list of ‘PhotoIDs’ the user owns, stored in different columns."

I have below questions and any help will be greatly appreciated.

  1. Model diagram says UserId is already in the Photo table, so why do we need a separate table to store the relationship ? Can’t we create a secondary index on UserId and use the same table ?
  2. How does Cassandra helps and what is the meaning of “stored in different columns” ? Does it mean that each PhotoID is a separate column ? If so, why is it preferred over storing the PhotoIDs in a list ?
1 Like