1

I am working in a database that has a hierarchy of Companies (From location-level all the way up to Top-level parent company). I am designing a system within that to provide a "subscription" mechanism that has implied inheritance. So for instance, Let's say you have Parent company A that has a subscription to service S. That means that all organizations from the parent company down to the location level will inherit that same subscription.

However, there is a requirement to be able to turn that subscription off. So given the above inheritance rules, you now have to be able to create an exception within the system for child companies below the parent. So you could have location company B that has a subscription to service S (inherited from company A) and location C from Parent Company A that has decided to explicitly not subscribe to service S.

My question is this: What is the best way to store this data? My first thought is this: You have 1 SQL table that stores columns for:

  • The "owning" company for the subscription
  • Subscription Metadata
  • "Parent" subscription
  • Subscription Exception (a "negative" subscription)

So a table to represent the above scenario would have 2 entries:

id| Company | Subscription | Parent Subscription | Subscription Exception
--------------------------------------------------------------------------
1 |  A      | {metadata X} | NULL                | False
2 |  C      | {metadata X} | 1                   | True

As an alternative, rather than having a Subscription Exception column, I could create a separate "exception" table that had the following Entry instead of the second row above:

id| Company | Subscription
---------------------------
1 | C       | 1

So my question is this: What is the best way to go? Which of these options would scale better? Is there another option to scale this up when you have thousands of companies with hundreds of subscriptions each?

The way I see it - The first idea seems to be the easiest to implement with ORM. The second idea stores less redundant data. But I don't know how well either of them would scale.

5
  • 1
    Company A's subscription changes. What happens now? Commented Oct 3, 2022 at 21:23
  • Why use the term "inheritance" for parent-child relationships?
    – Erik Eidt
    Commented Oct 3, 2022 at 21:58
  • "efficient" regarding what metric? Schema complexity? Storage space? Query execution time? (what queries are critical?). It seems to me you're looking for schema complexity but it'd be helpful to be explicit about it.
    – Rad80
    Commented Oct 4, 2022 at 11:40
  • @candied_orange What do you mean by changes? If that is the case, any changes to the program itself get applied to child companies as well, unless the child company does not "inherit" the subscription from the parent. Commented Oct 4, 2022 at 13:40
  • @Rad80 I'll clarify. Top 2 are: 1. Schema complexity (since we'll need to deal with tree manipulations at times). 2. Query execution time. The queries that we need to build are are: a. Given a service, get a list of customers with active subscriptions to the service. b. Given a service and customer, tell me if the customer or any of it's children have an active subscription to the service. Commented Oct 4, 2022 at 13:47

0