How to make custom event properties queryable?

Viewed 24

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:

  1. Query all users which have been referred (or even referred from a particular account).
  2. List all properties for a User Registered event (in the above case expected result is [plan, referred, referred_for]).
  3. List all seen values for a property (for plan expected result is ["Pro Annual"]).

I was thinking of a PSQL database :

  • event table stores event types.
  • property table stores properties per type.
  • property_value table 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?

0 Answers
Related