This is an interesting problem, I am not an expert on database design,
especially key-value based datastore,  but I will try to answer this
question.

For me, the design like
Class User{
Key id;
String name;
String email;
List<key> friends.
...etc
}
makes perfect sense, and as you said, you can do more query on
something like "UserActivity" or "TimeBecomeFriends", with
"user1Id=<userId> or user2Id=<userId>". approach. I am also fine with
it.

How big is your application? I think a good design is relevant to the
scalability, and we are always trading storage space with query time.

Another thing maybe useful is memcache, using it may lead to a gain in
performance, although it may bring a bit data inconsistency,  however
I think it's ok. For example, it should be fine if you see your
friends' latest post 1 minute later.

Maybe there is some paper talking about datastore design for scalable
applications? Not sure.

Thanks


On Tue, May 18, 2010 at 7:58 AM, Ravi <ping2r...@gmail.com> wrote:
> Hi,
> I am trying to design a website like Facebook, where user will have
> friends and will have wall where they can see there friend's updates
> etc. While designing it on GAE i got confused with what will be the
> best approach like data duplicate, data read time or data write time
> etc
>
> Friend's Design:
> I thought there will be User and User will be friend with another
> User.
>
> Class User{
> Key id;
> String name;
> String email;
> ...etc
> }
>
>
> Now i definitely can not have owened relatioship with Friends means I
> can not have List<User> friends in my User Class as it will not be
> same domain(User) data, so i thought ok i will have List<Key> or
> List<Long> User Ids as Friends
> Class User{
> Key id;
> String name;
> String email;
> List<key> friends.
> ...etc
> }
> And confusion/problem begins.
> First a Friendship is supposed to be from both side, so it should be
> defined only once but in this design both Friends will have each
> other's id in there friend list. Basically its not a typical
> relationship. What if i want to keep friendship info like when it
> started, who introduced etc. Then i may need to create a new Friend
> class with two fields as user1Id and user2Id and query this class with
> user1Id=<userId> or user2Id=<userId>. But not sure about this
> approach.
> Second i am doing data duplicate(but i am fine with it if it can be
> proved as best solution).
> Third: I am showing one user's profile and want to show his friends on
> one page, so first i need to get the User and its Friend List<Key>
> then i need to search User for each and every Id to get each user's
> data(like name.profile id and photo). For me it seemed bit longer
> process.Not sure how queries will perform.
>  Pseudo Code will be like this
>   > Get Logged In User
>   > Loop through friends field
>        >Begin
>          get User for each iterated Friend Id.
> //and if we want to show how many friends that user have, then i will
> be accessing friend list for each friend,so there will be lot of data
> read from database.
>        >End
> put all data in jsp to compile and show it to user.
>
>
> Other design problem related to wall like Facebook wall/profile,
> Lets say i have UserActivity class to keep track of User's Activity
> and that can be owned by User, so User class can look like
> Class User
> {
> Key id;
> String name;
> String email;
> List<Key> friends//assume we are going with this kind of design
> List<UserActivity> activities
> }
>
> Class UserActivity
> {
> Key id;
> String statusMessage;
> Date time;
> User user;
> }
>
> Now i want to show all activities of a user to him/her order by
> time(recent first/on the top).
> Now again i see one way of doing it as get all the Friend's id from
> List<Key> friends field, query all User data then go through
> UserActivity and get all data in memory and sort it out. This seems
> not a good option to me.
> How can i solve this problem efficiently and design a good solution.
>
> Thanks in advance
> Ravi.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine for Java" group.
> To post to this group, send email to google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-appengine-java+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>



-- 
Yiming
MS student of CS Department @UCSB

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to