The Namespaces API in Google App Engine makes it easy to compartmentalize your Google App Engine data. This API is implemented via a new package called the namespace manager, and is incorporated in certain namespace-enabled APIs. When you set a namespace in the namespace manager, these APIs get the current namespace and use it globally. You can explicitly declare a namespace locally, but you need to exercise caution when explicitly declaring namespaces, because you could inadvertently create data leaks and other bugs. Any App Engine request can access any namespace, leaving the application to enforce an access control policy across namespaces.
You can use the Namespaces API to build a wide range of applications. One of the most compelling uses of this API is for multitenant applications, as described below.
Multitenancy is the name given to a software architecture in which one instance of an application, running on a remote server, serves many client organizations (also known as tenants).
Using a multitenant architecture simplifies administration and provisioning of tenants. You can provide a more streamlined, customized user experience, and also aggregate different silos of data under a single database schema. As a result, your applications become more scalable as well as more cost-effective as you scale. Data becomes easier to segregate and analyze across tenants because all tenants share the same database schema. Different user groups see custom content wrapped within a more efficient application.
Building a multitenant application with the Namespaces APIUsing the Namespaces API, you can easily partition data across tenants simply by specifying a unique namespace string for each tenant. You simply set the namespace for each tenant globally using the namespace manager (as opposed to setting it explicitly for a specific request). The namespace-enabled APIs always use this current namespace by default.
The Namespaces API is integrated with G Suite, allowing you to use your G Suite domain as the current namespace. Because G Suite lets you deploy your app to any domain that you own, you can easily set unique namespaces for all domains linked to your G Suite account.
When designing multitenant applications, you need to prevent data from leaking across namespaces. For more information, please see Avoiding Data Leaks.
App Engine APIs that use namespaces
App Engine currently supports namespaces in the following APIs:
Sample projects using namespaces
Two sample guestbook applications using namespaces are provided:
- Python App Engine: appengine-multitenancy – A namespace-aware sample guestbook application.
- Java App Engine: appengine-gwtguestbook-namespaces-java – A namespace-aware sample guestbook application using GWT.
Other uses for the Namespace API
While the Namespaces API enables multitenancy on App Engine, it has a number of other uses, including:
- Compartmentalizing user information
- Separating admin data from application data
- Creating separate datastore instances for testing and production
- Running multiple apps on a single App Engine instance