0

I'm trying to model a simple address book schema that I will use for HBase/Cassandra.

The scenario:

  • A user can create his contacts.
  • A contact may have many phones, addresses or emails.
  • A user can create groups to organize his contacts (a group can contain many contacts and a contact can be placed in many groups).

The only select query that I'm planning to do is to grab all the contacts who live at address x and are in group y.

Would the following schema be appropriate for this?

|Table name: User     |
-----------------------
Key: user_id
email
password
-----------------------
Column family: Contacts
        Key: contact_id
        firstname
        lastname
        ---------------
        Column family: Address
                Key: address_id
                street
                housenumber
                zipcode
        ---------------
        Column family: Group
                groupname

Or is this better/possible?

|Table name: User     |
-----------------------
Key: user_id
email
password
-----------------------
Column family: Contacts
        Key: contact_id
        firstname
        lastname
        contact_id

|Table name: Address   |
-----------------------
Key: address_id
street
housenumber
zipcode
contact_id

|Table name: Group   |
-----------------------
Key: group_id
group_name
Moody
  • 851
  • 2
  • 9
  • 23

1 Answers1

1

Addresses tend to get more complicated and you could add addtional, denormalized column families/tables to support your queries.

EDIT: Since you're more concerned with querying on Address and Group, you should add two new, denormalized tables: one keyed by address_id and one by group_id.

I can't speak to HBase solutions for this problem, but in Cassandra 2.1+, there is support for User Defined Types. The documentation from that link has a good example of modeling the user-address entity relationship.

BeepBoop
  • 1,282
  • 10
  • 12
  • Thank you for your comment! I editted my post based on your comment. Do you think that this is more appropriate? – Moody Mar 22 '15 at 22:58