I'm working at a SaaS, where any tenant can have several lists of contacts, each list can have any number of custom fields contacts of this list can store and any number of groups the contancts of the list can be includes (groups are used for segmenting contacts of the list). Each contact has one required fields: email_address and any number of userdefined fields that are defined for the list where it is as I mentioned about. We must be able to find contacts of the lists base on the groups they're in and the values of user defined values. We must provise up to 30 user defined fields. I see now three ways of solving this problem:
Using kind of EAV (we try to do it like this) but it looks rather complex. We have a table lists (lists of tenants), a related tables custom_fields, a related tables subscribers that stored email_addreses of subscribers of the list, table subscribers_custom_data which is related with subscribers and custom_fields tables (stored values of the custom fields of the subscribers).
Field tables pattern. The descriptions of it is here http://blog.springsource.com/arjen/archives/2008/01/24/storing-custom-fields-in-the-database/. In thise case we'd use a field related to custom fields, that would store in columns all custom fields for example have 30 columns to store values of each possible custom fields and a table that stored mapping of columns name and name of the user defined field. It looks complex too. We'd have to have at least 30 indexes at least to search by the values of custom fields, there other problems too,
To use some sort of NoSQL database at least for storing of user defined fields and maybe groups of the list. Do you think such databases can help here and if so how to design for storing custom fields and groups. I try to look at different types NoSQL, for example, document oriented like MongoDb, but right away I can't see how it can help solve this problem. We can store arbitrary attributes here but to search for the values of the custom fields we need to index them in advance so we have to know what custom fields we'll have.
Thank you for any information about it.