My segment destination listens for events from customers. Events contain custom properties (customer might specify random fields):
{
user_id: "some_id", // predefined key
event_name: "User Registered", // predefined key
event_properties: { // predefined key
// reserved properties
plan: "Pro Annual", // predefined key
...
// custom properties
referred: true, // custom key and value type
referred_from: { // custom key and value type
account: "some_account",
},
...
}
};
In this case event User Registered has two custom properties: referred: bool and referred_from: object (note the value can be another object).
How do I save this data in a database so I can query it per any property? I have these use cases:
- Query all users which have been referred (or even referred from a particular account).
- List all properties for a
User Registeredevent (in the above case expected result is[plan, referred, referred_for]). - List all seen values for a property (for
planexpected result is["Pro Annual"]).
I was thinking of a PSQL database :
eventtable stores event types.propertytable stores properties per type.property_valuetable stores values per type.
This will work, although I am not sure how to handle nested objects like referred_from. Further, I'm uncertain if this approach will scale well as we expect hundreds of customers => millions of users => hundreds of millions of events.
Is this a better-suited job for a NoSQL database? If so which one and why?