Search code examples
google-cloud-firestoremulti-tenant

Does Firestore support multitenancy?


Does Firestore have any support for a multi-tenant app? I am creating a service which will have multiple clients and need to be able to separate each client's data completely from every other client.


Solution

  • Firestore in Native mode has no (built-in) support for multitenancy.

    Firestore in Datastore mode has support for multitenancy via namespaces. However, Firestore in Datastore mode loses the real-time updates feature, which is a highly desirable feature for many developers/projects.

    One workaround for this limitation is to use a (collection/document) hierarchy in the Native-mode Firestore that looks something like this:

    • tenants (collection)
      • Tenant-01 (document representing a particular tenant; can contain basic details like name etc.)
        • users (sub-collection)
        • assets (sub-collection)
        • locations (sub-collection)
      • Tenant-02
        • users (sub-collection)
        • assets (sub-collection)
        • locations (sub-collection)

    However, there still remains the limitation that you cannot know the resource usage on a per-tenant basis. This matters particularly when there's a noisy neighbour: a single tenant that is using far more resources than the average. As the service provider your total bill is rising, but there's no easy way to know which client (tenant) is causing the higher costs.

    See also: