I know this question has probably been asked several times before, but my question is specific to my situation.
I am implementing a notification micro service. It has an email
table and a queue
table. The service is exposed using a REST API. Each email can have multiple to
addresses and cc
addresses. The queue has an email ID. Once the email is sent, the row is removed from the queue.
At this time, there is no requirement to query on who sent what emails or whether a email for a particular user with a given email address has been sent. There are multiple ideas on how to/cc email addresses can be stored.
- Store them in JSON format in a address field of the email table:
{
toList: ['h@h','g@g'],
ccList: ['a@b','c@d']
}
I considered using the JSON data type of MySQL 5.7, but it's not supported in h2db which we use for integration tests.
Store them as comma separated values in
toList
,ccList
columns in theemail
table.Store them in a relational table such as
email
,emailaddress
,emailaddresstype
where theemailaddress
table would contain theemailid
, email address and theemailaddressstypeid
. This results in several records inemailaddress
table and also multiple joins.
What would be the best solution to implement in this case? I am generally against violating FNF and I'm not sure what it means to have so many records in an emailaddress
table such as a record for every email sent to, for example, 2 to 3 people. There is no user
table in this system, if that matters.