Skip to content

Data Model approaches

Vikhyat Bhatnagar edited this page Mar 25, 2023 · 3 revisions

Approach 1 (Selected)

Feature Flag

{
    "id": string,
    "flagName": string,
    "createdAt": number,
    "createdBy": string,
    "deactivatedAt": number,
    "description": string
}

Users (Existing)

{
  'id': string,
  'username': string,
  'first_name': string,
  'last_name': string,
  'email': string,
  'phone': number,
  'yoe': number,
  'company': string,
  'designation': string,
  'img': string,
  'github_id': string,
  'linkedin_id': string,
  'twitter_id': string,
  'instagram_id': string,
  'website': string,
  'github_display_name': string,
  'isMember': boolean,
  'userType': string,
  'tokens': {},
  'badges': []
}

FeatureFlagUserMapping

One drawback of having a separate table for user feature mapping, can be if we want to release feature X for 100 users, we need to make 100 entries in the FeatureFlagUserMapping table.

For fetching the flag of User X, need to scan all the entries with index on UserId

{
    'flagId': string,
    'userId': string,
    'enabled': boolean
    'enabledAt': timestamp
}

Approach 2: storing flags in Users

Feature Flag

{
    "id": string,
    "flagName": string,
    "createdAt": number,
    "createdBy": string,
    "deletedAt": number
}

Users (Existing)

{
  'id': string,
  'username': string,
  'first_name': string,
  'last_name': string,
  'email': string,
  'phone': number,
  'yoe': number,
  'company': string,
  'designation': string,
  'img': string,
  'github_id': string,
  'linkedin_id': string,
  'twitter_id': string,
  'instagram_id': string,
  'website': string,
  'github_display_name': string,
  'isMember': boolean,
  'userType': string,
  'tokens': {},
  'badges': [],
  **'flags': []**
}

One drawback of this approach is that if we have many feature flags for a User, the list of flags would become very large. We can fetch feature flags for Users, but the other way is not possible i.e: Fetching Users from the Feature flag.


Approach 3: Storing Users in Feature flags and Flags in Users

Feature Flag

{
    "id": string,
    "flagName": string,
    "createdAt": number,
    "createdBy": string,
    "deletedAt": number,
    "Users": []
}

Need to think more about faster querying for a user. Given a user check if the flag is enabled.

Users (Existing)

{
  'id': string,
  'username': string,
  'first_name': string,
  'last_name': string,
  'email': string,
  'phone': number,
  'yoe': number,
  'company': string,
  'designation': string,
  'img': string,
  'github_id': string,
  'linkedin_id': string,
  'twitter_id': string,
  'instagram_id': string,
  'website': string,
  'github_display_name': string,
  'isMember': boolean,
  'userType': string,
  'tokens': {},
  'badges': [],
  'flags': []
}

We have to update the data in 2 models, append the flag in flags of User model and append the User in Users of flag model.