Understanding Pulsar’s tenant, namespace, and topic hierarchy
Apache Pulsar is designed as a multi-tenant system from the ground up, providing strong isolation between different organizational units, applications, and teams.
# Create a new tenantpulsar-admin tenants create acme-corp \ --admin-roles admin-user,ops-team \ --allowed-clusters us-west,us-east# List all tenantspulsar-admin tenants list# Get tenant infopulsar-admin tenants get acme-corp
Namespaces are the administrative units within a tenant. From pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamespaceName.java:
public class NamespaceName implements ServiceUnitId { // Namespace format: tenant/namespace // Or legacy format: tenant/cluster/namespace public static final NamespaceName SYSTEM_NAMESPACE = NamespaceName.get("pulsar/system");}
Namespaces group related topics and provide a scope for policies:
# Create a namespacepulsar-admin namespaces create acme-corp/production# List namespaces in a tenantpulsar-admin namespaces list acme-corp
The public/default namespace is created automatically and provides a convenient starting point for development.
# Set retention - keep data for 7 days or 100GBpulsar-admin namespaces set-retention acme-corp/production \ --size 100G \ --time 7d# Get retention policypulsar-admin namespaces get-retention acme-corp/production
# Separate tenant per customercustomer-a/productioncustomer-b/productioncustomer-c/production# Each with isolated resources and quotaspulsar-admin resource-quotas set \ --namespace customer-a/production \ --msgRateIn 10000 \ --bandwidthIn 100000000
# Tenant per business unitretail/productionwholesale/productionmanufacturing/production# Shared infrastructure tenantplatform/shared-servicesplatform/monitoring
# Create new namespace with desired policiespulsar-admin namespaces create acme-corp/new-namespace# Set policies on new namespacepulsar-admin namespaces set-retention acme-corp/new-namespace --size 100G --time 7d# Update client configurations to use new topic names# persistent://acme-corp/new-namespace/my-topic
Pulsar doesn’t support moving topics between namespaces. Plan your namespace structure carefully, or implement dual-write during migrations.