Databases Reference
In-Depth Information
UserID
Name
Email
Item ID
Title
Desc
123
ABC BC@123.com
111
iPhone
Apple iPhone
User by Item
User ID
User ID
Item by User
Item ID
Item ID
111
123
456
123
111
222
ABC
XYZ
iPhone
Tipping Point
Figure 6-16. Option 3: Logical NoSQL data model
Option 3: Normalized entities with de-normalization into
custom indexes
In this model, title, and username are de-normalized in “User byItem” and “Item byUser”
respectively. This allows us to efficiently query all the item titles liked by
a given user and all the user names who like a given item. This is a fair amount of
de-normalization for this use case.
What if you want to get all the information (title, description, price, etc.) about the items
liked by a given user? First you need to ask yourself whether you really need this query,
particularly for this use case. You can show all the item titles that a user likes and pull
additional information only when the user asks for it (by clicking on a title). So, it's better not to
do extreme de-normalization for this use case. Let's consider the following two query patterns:
For a given “Item Id”, get all of the item data (title, description, etc.)
along with the names of the users who liked that item.
For a given “User Id”, get all of the user data along with the item
titles liked by that user.
These are reasonable queries for item detail and user detail pages in an application.
Both will perform well with this model. Both will cause two lookups, one to query item
data (or user data) and another to query user names (or item titles). As the user becomes
more active (starts liking thousands of items, for example) or the item becomes hotter
(liked by a few million users, for example), the number of lookups will not grow; it will
remain constant at two. That's not bad, and de-normalization may not yield much benefit
like we had when moving from option 2 to option 3. However, you will learn how to
optimize further in option 4 (Figure 6-17 ).
User ID
User Info
Likes
123
Name
Email
111
222
ABC
ABC@123.comiPhone
Tipping Point
Item ID
Item Info
Liked By
111
Title
Desc
123
456
iPhone
Apple iPhone
ABC
XYZ
Figure 6-17. Option 4: Logical NoSQL data model
 
Search WWH ::




Custom Search