Apache Pulsar has revolutionized distributed messaging and streaming with its multi-tenant architecture and built-in geo-replication capabilities. At the heart of its resilience is asynchronous replication, which enables data to flow seamlessly across geographically dispersed clusters without blocking producers or consumers. This approach ensures low-latency local operations while maintaining eventual consistency across sites, making it perfect for global applications demanding high availability and disaster recovery.
Unlike synchronous replication that can introduce latency penalties, Pulsar’s async model persists messages locally first, then replicates them in the background. This decouples write performance from network distances, allowing applications to scale across data centers effortlessly. In this detailed guide, we’ll explore the foundational concepts, step-by-step implementation strategies, and advanced patterns to harness Pulsar’s replication power effectively.
Core Principles of Pulsar Replication
Pulsar’s replication operates at the namespace and topic levels within a tenant hierarchy. Tenants act as the gatekeepers, defining which clusters can exchange data. Once authorized, namespaces dictate replication scopes—either full-mesh broadcasting to all permitted clusters or selective routing for targeted syncing.
- Eventual Consistency: Messages are durably stored locally before async copying, ensuring no data loss even during partitions.
- Multi-Cluster Fabric: Producers and consumers operate independently per cluster, reading replicated data with minimal delay.
- Flexible Policies: Override defaults via message metadata for granular control over destinations.
The replication process leverages dedicated broker threads that consume from local topics and produce to remote counterparts. Network RTT typically bounds end-to-end latency, often under 100ms between proximate regions. Official Pulsar documentation confirms this mechanism scales linearly with cluster count, supporting dozens of sites without configuration tweaks.
Preparing Your Pulsar Environment
Before diving into configs, ensure your clusters are networked and brokers expose replication ports (default 6651). Clusters must share a common superuser for initial setup. Verify connectivity with pulsar-admin clusters list from any broker.
| Prerequisite | Action | Verification |
|---|---|---|
| Cluster Names | Define unique IDs like ‘dc1’, ‘dc2’ | pulsar-admin clusters list |
| Admin Tool | Install pulsar-admin CLI | pulsar-admin –help |
| Superuser Access | Configure shared credentials | Login from each cluster |
| Firewall Rules | Open broker ports bidirectionally | telnet <broker>:6651 |
With basics covered, proceed to tenant creation—the entry point for all replication.
Configuring Tenants for Cross-Cluster Access
Tenants encapsulate permissions, specifying allowed clusters via the --allowed-clusters flag. This granular control prevents unauthorized data flows. Execute on each participating cluster for symmetric access.
bin/pulsar-admin tenants create myorg \ --allowed-clusters dc-east,dc-west \ --admin-roles replication-adminHere, ‘myorg’ gains entry to ‘dc-east’ and ‘dc-west’, with ‘replication-admin’ handling namespace ops. Repeat per cluster to enable bidirectional flows. Pulsar’s official guide emphasizes creating tenants identically across sites to avoid permission mismatches that halt replication.
Namespace Policies: The Replication Control Center
Namespaces bundle topics and inherit tenant cluster permissions. Use set-clusters to activate replication, listing destinations separated by commas. This triggers full-mesh async copying by default.
bin/pulsar-admin namespaces create myorg/productionbin/pulsar-admin namespaces set-clusters myorg/production --clusters dc-east,dc-west,dc-centralPost-configuration, topics auto-replicate across listed clusters. Monitor progress via pulsar-admin namespaces get-clusters. For production, bundle with permissions:
- Produce/Consume roles for apps
- Retention policies matching workloads
- Bookkeeper ledger quotas
Active-Active Multi-Region Deployments
The hallmark of Pulsar is active-active setups, where every cluster handles reads and writes independently. Data converges asynchronously, resolving conflicts via cursor advancement and deduplication keys.
Benefits include:
- Zero-downtime regional scaling
- Local low-latency consumption
- Automatic partition healing
Implement by assigning namespaces to multiple clusters, as above. Clients connect via service URLs like pulsar://dc-east.example.com:6650, publishing locally while replication fans out. StreamNative docs highlight enabling this on both ends for true bidirectionality.
Active-Standby for Disaster Recovery
Not all scenarios need full active-active. For backup-focused active-standby, designate a primary cluster and route all traffic there via DNS or load balancers. Replication flows one-way to the standby.
Key steps:
- Namespace set-clusters includes both active and standby.
- Client configs pin to active endpoint.
- App-level message restrictions (below) enforce directionality.
Failover involves updating client endpoints transparently. Pulsar brokers detect peer unavailability, pausing replication until reconnection.
Message-Level Selective Routing
For precision, embed replication targets in message properties. Producers specify clusters per payload, overriding namespace defaults—ideal for hybrid active-standby.
import org.apache.pulsar.client.api.Producer;import org.apache.pulsar.client.api.schema.GenericRecord;List<String> targets = Arrays.asList("dc-standby");Producer<GenericRecord> prod = client.newProducer(...) .replicationClusters(targets) .create();prod.send(record);This routes exclusively to ‘dc-standby’, containing fan-out. Java, Python, and Go clients support this via builder patterns. Use cases span compliance (region-locking) to aggregation (funneling to analytics clusters).
Aggregation Patterns for Centralized Analytics
Picture three customer-facing clusters feeding a secure internal aggregator. Configure namespaces per source, replicating inbound only to the central hub.
# East clusterbin/pulsar-admin namespaces set-clusters analytics/east --clusters east,central# West clusterbin/pulsar-admin namespaces set-clusters analytics/west --clusters west,centralCentral consumes unified streams for ML training or reporting, isolated from public nets. Scale by partitioning topics, distributing replication load across brokers.
Monitoring and Troubleshooting Replication
Pulsar’s Prometheus exporter exposes metrics like pulsar_replication_backlog and replication_rate_in/out. Query via Grafana for lag alerts. Common issues:
- Backlog Growth: Check network, Bookkeeper health.
- Permission Denials: Sync tenant roles across clusters.
- Partition Skew: Balance via
topics partition.
CLI tools like pulsar-admin topics stats reveal per-topic replication state.
Best Practices for Production Deployments
- Start with 2-3 clusters; expand iteratively.
- Use dedup keys for idempotent producers.
- Size BookKeeper for 2x write amplification.
- Test failovers with Chaos Engineering.
- Secure with TLS and RBAC.
FAQ
- What latency can I expect?
- Bounded by RTT; typically 50-200ms inter-region.
- Does replication survive full cluster outages?
- Yes—resumes from last cursor on reconnection.
- Can I mix sync/async modes?
- No, Pulsar is async-only for geo-replication.
- How to disable replication temporarily?
- Remove clusters from namespace via set-clusters.
- Topic partitioning impact?
- Replicates independently per partition for parallelism.
Apache Pulsar’s async replication transforms distributed systems, blending simplicity with enterprise-grade resilience. By mastering tenants, namespaces, and selective routing, teams deploy global, fault-tolerant pipelines effortlessly.
References
- Geo Replication – Apache Pulsar — The Apache Software Foundation. 2024-01-15. https://pulsar.apache.org/docs/next/concepts-replication/
- Architecture Overview – Apache Pulsar — The Apache Software Foundation. 2024-03-22. https://pulsar.apache.org/docs/4.1.x/concepts-architecture-overview/
- Configure asynchronous geo-replication — StreamNative. 2023-11-10. https://docs.streamnative.io/private-cloud/v1/operating-streamnative-platform/advanced/configure-asyn-geo-replication
- Pulsar geo-replication — The Apache Software Foundation. 2022-06-01. https://pulsar.apache.org/docs/2.8.x/administration-geo/
- Async Geo-Replication and Cluster Down Scenarios — Apache Pulsar GitHub Discussions. 2024-05-05. https://github.com/apache/pulsar/discussions/25519

