Multitenancy and nested set trees

The application I work on utilizes nested sets1 to represent tree structures within our database.
We need to expand a particular area of access control to support multiple clients who should not be able to see other client’s information (aka multi-tenancy).
We have preferred the nested set approach over the more common, “naive” approach for a number of reasons as summarized in this presentation on slide 69.

At first glance, nothing within a nested set structure appears to be a problem that would prevent its use within a multi-tenant environment. However, one of the concerns with nested sets is the number of updates required leaf nodes are added or removed. For example, all entries to the right of the inserted leaf node end up needing their left and right values updated.

For the table in question, it will always remain relatively small (~5-10k rows, tops) even with multiple tenants.

We also have clients who will want additional access restrictions beyond those provided by ACLs expressed through a nested set tree.

In order to satisfy the client access restrictions and also to address potential database update concerns, we’re considering adding a ClientId field to our nested set table. The idea being that updates to one client’s tree won’t need to affect the trees of other clients. Likewise, we’ll have a hard block in place if Client A tries to inadvertently access Client B’s data because the Client field won’t match.

| RowId | ClientId | Left | Right | Foo... | Bar... |
|-------|----------|------|-------|--------|--------|
| 3     | 10       | 1    | 42    | ...    | ...    |
| 5     | 20       | 1    | 69    | ...    |        |

One complication that I have is that I have a set of users (call them “ClientId 0”) who will perform actions for the other clients (like “Client 10”, “Client 20”). And the actions that “Client 0” perform need to be visible / usable by the client they performed the action for. So “Client 0” has to create things that will receive a different ClientId.2


Does this approach appear to be sound, or what should I be examining to understand if it will hold up as I explained above?
Alternatively, is there a superior data structure in order to represent multi-tenant, hierarchical information?

1Also see this slidedeck starting at slide 53 for additional details of implementing a nested set tree structure.
2My working approach to resolve this is to pull the ClientId from the node that Client 0 is working on, and assign the node’s ClientId to the newly created node.

6

Adding a “tenant” column (ClientId in this case), and using that to filter by tenant, is logically identical to having a separate database for each tenant. The only difference is, you have to remember to use that everywhere. This is true for everything in the database, not simply your nested sets. You are safe, assuming you are careful in writing the stored procedures.

Whatever advantages or disadvantages you found in the chosen hierarchy representation, will still be present even after making it a multi-tenant database. The only difference is, now you have a bit more work to do on each query.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật