Databases Reference
In-Depth Information
unknowingly, from the query patterns or from your prior understanding of the domain
(because entities and relationships are how we perceive the real world). It's important
to understand and start with entities and relationships, then continue modeling around
query patterns by de-normalizing and duplicating.
It also helps to identify the most frequent query patterns and isolate the less
frequent. Some queries might be executed only a few thousand times, while others will be
executed a billion times. Also consider which queries are sensitive to latency and which
are not. Make sure your model first satisfies the most frequent and critical queries.
De-normalize and Duplicate for Read Performance
In the relational world, the pros of normalization are well understood: less data
duplication, fewer data modification anomalies, conceptually cleaner, easier to maintain,
and so on. The cons are also understood: queries might perform slowly if many tables are
joined, etc. The same holds true in column family databases, but the cons are magnified
since it's a distributed database and of course there are no joins (since it's high-scale
distributed). So with a fully normalized schema, reads may perform much worse.
Example: “Like” relationship between user and item
This example concerns the functionality of an e-commerce application where users
can like one or more items. One user can like multiple items, and one item can be liked by
multiple users, leading to a many-to-many relationship as shown in the relational model
in Figure 6-13 .
UserID
Name
Email
ID
User ID
Item ID
Timestamp
123
ABC BC@123.com
1
123
111
1234567890
456
XYZ
XYZ@456.com
2
123
222
1234560987
3
456
111
4567098123
4
456
333
7890654321
Item ID
Title
Desc
111
iPhone
Apple iPhone
222
Tipping Point
Book - Malcom Gladwell
333
Kindle
eReader
Figure 6-13. Logical data model in RDBMS
For this example, let's say we would like to query data as follows:
Get user by user id
Get item by item id
Get all the items that a particular user likes
Get all the users who like a particular item
 
Search WWH ::




Custom Search