# Overview of Multitenancy and the Namespaces Java API - Google App Engine - Google Code

English ▼
Skip to page content Skip to main navigation
e.g. "templates" or "datastore"

# Overview of Multitenancy and the Namespaces Java API

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.

- About Multitenancy
- Building a Multitenant Application with the Namespaces API
- App Engine APIs that Use Namespaces
- Sample Projects Using Namespaces

## About Multitenancy

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 API

Using 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 Google Apps, allowing you to use your Google Apps domain as the current namespace. Because Google Apps lets you deploy your app to any domain that you own, you can easily set unique namespaces for all domains linked to your Google Apps 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:

- Datastore
- Memcache
- Task queue

## Sample Projects Using Namespaces

The Sample Applications page provides the following sample guestbook applications using namespaces:

- trunk/guestbook_namespaces – A namespace-aware sample guestbook application for Python App Engine.
- trunk/gwtguestbook-namespaces – A namespace aware sample guestbook application for GWT/Java App Engine.